I know about tools like ganache-time-traveler that let you advance the block number.
But is it possible to go back to a lower value?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
When you are at a state you know you want to return to, call
takeSnapshot in order to get a snapshot ID. When you want to revert to that state, simply run
revertToSnapshot with that specific ID.
As a note, the snapshotting function in Ganache was finicky the last time I used it (Feb 2019). There were certain limitations, such as not being able to take multiple snapshots before reverting to one. I do not know the current status of this.
The issues I was having with this feature are addressed in the "Custom Methods" section of the ganache-cli repo:
evm_snapshot : Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created. A snapshot can only be used once. After a successful evm_revert, the same snapshot id cannot be used again. Consider creating a new snapshot after each evm_revert if you need to revert to the same point multiple times.
evm_revert : Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to. This deletes the given snapshot, as well as any snapshots taken after (Ex: reverting to id 0x1 will delete snapshots with ids 0x1, 0x2, etc... If no snapshot id is passed it will revert to the latest snapshot. Returns true.