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?