A ganache utility that simplifies writing time dependent or stateless tests on a local Ethereum blockchain.
- this only works with ganache-cli
- this only works locally
npm i ganache-time-traveler
The general outline is to add
require at the top of your tests
const timeMachine = ;
afterEach hooks into your truffle test file
Advances the time on the blockchain forward. Takes a single parameter, which is the number of seconds to advance by.
Note: for advancetime() to take effect, the block must also be mined using
advanceTimeAndBlock() to do both.
Mines a new block; advances the block forward by 1 block.
Advances the block forward by 1 and sets the time to a new time.
Advances the block by 1 in addition to advancing the time on the blockchain forward. Takes a single parameter, which is the number of seconds to advance by.
Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created.
Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to.