HOW TO WRITE TIME DEPENDENT TEST WITH HARDHAT?
To write time-dependent tests with hardhat, the “evm_increasetime” and “evm_mine” functions of the hardhat ethers plugin are used.
Steps:
1. Import Hardhat and Hardhat Ethers plugins
const { ethers } = require("hardhat")
const hre = require("hardhat")
2. Define the below mentioned functions
3. Call the functions in tests
1. Manipulating EVM via Increasing Block Timestamp
async function increaseTime(amount) {
await hre.network.provider.send("evm_increaseTime", [amount])
console.log("EVM time " + amount + " seconds increased!")
}
2. Manipulating EVM via Mining Blocks
async function mineBlocks(amount) {
for (let i = 0; i < amount; i++) {
await hre.network.provider.send("evm_mine")
}
console.log(amount + " Blocks Mined!")
}