0

I have this code for a Voting smart contract test:

it("Should return true if end time is less than the current timestamp", async function () {
  const { votingSmartContract } = await loadFixture(deployVotingSmartContract);
  const now = Math.floor(new Date().getTime()/1000.0);
  await votingSmartContract.initialise(
    [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], // candidates
    now + 1 // endTime
  );
  expect(await votingSmartContract.checkVotingIsOver()).to.be.true;

});

What this does is basically initialise the voting so it finishes in 1 sec, so I can then test that checkVotingIsOver returns true.

Problem is test is failing because I am getting false every time. I have console.log the block.timestamp that I am checking and it looks like I am always getting it to be 1 LESS than the now variable.

How can I wait until block.timestamp increases so I can pass this test?

Falcon Stakepool
  • 719
  • 2
  • 5
  • 26

1 Answers1

1

There are hardhat helpers for manipulating time and block.number.

Time-dependent tests with Hardhat?

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145