In my contract I have a function that is set to be active after a particular block.timestamp has elapsed.
so in my test, I used
describe("do something at time stated", ()=>{
it("revert after time", async()=>{
const stillValid = await contractInstance.showAtTime() // returns timestamp 7 days from now
console.log(stilValid)
await time.increase(stillValid);
await expectRevert(await contractInstance.doAtTime(), "time over")
}
})
this above function returned error Error: Cannot increase current time (6465161954) to a moment in the past (1614832558)
after several tries I discovered on every call of increaseTo(timestamp) moves the current block time ahead.
Can you share a cut down version of your contract with the showAtTime and doAtTime functions?
I assume that the time is passed in as a parameter to the constructor?
Are you using Truffle’s internal network or are you testing on ganache-cli?
Thank you @abcoathup I found a way to run the test. I believe it would be great to have helper functions to capture the timestamp before the test and reset the timestamp to the current timestamp after each “it” block. Thank you for this reference
Hi,
It seems that I cannot use any of the time.XXX functions as it keeps on throwing me with this error message.
Error: CONNECTION ERROR: Couldn't connect to node http://localhost:8545
I´ve installed npm install --save-dev @openzeppelin/test-helpers correctly.
Any ideas?