Write tests for time based contracts

ethers.jshardhatsoliditytestingtimestamp

I have a function that requires 7 days to pass from the time of an event (lockTime) before the rest of it will execute:

function resetGame () public onlyOwner {
    require (block.timestamp >= lockTime + 7 days);
    _;
}

how could I write a test using JS and chai to test that when 7 days pass, the function works as intended?

(p.s. I am using Hardhart and ethers.js)

Best Answer

You can use evm_increaseTime rpc available in Hardhat Network (docs).

await hre.ethers.provider.send('evm_increaseTime', [7 * 24 * 60 * 60]);
Related Topic