1

Ive seen people use examples of increasing the time of hardhat for time deoendent functions using evm_increaseTime in a test, but how can i manually do this? Im not even sure what file im supposed to put the increasetime function into so hardhat can run it as a task. Totally new to hardhat

1 Answer 1

1

In order to advance time when testing with Hardhat, you have to use the network provider's increase_time method. Here's a code of what it should look like

const { network } = require("hardhat")

describe("Best tests in the world", () => {
  let contract;
  beforeEach(async () => {
    contract = await someMethodToGetYourContract("Your contract name");
  })

  it("Should be able to interact with the contract once time a day", async () => {
    let DAY = 1000 * 60 * 60 * 24
    await contract.makeSomeEpicInteraction(); // Now we should wait a day to interact again!
    
    // Time travelling to the future!
    await network.provider.request({
      method: 'evm_increaseTime',
      params: [DAY],
    });

    await contract.makeSomeEpicInteraction(); // This will work

  })
})

I supposed that if you are new with Hardhat, you wouldn't be using Typescript.

There are other functions that let you play with the evm time and lots of other things, here is the Defi Wonderland's Solidity Boilerplate, where you'll be able to find some utils functions that might be of help for you my fren

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.