Skip to main content
added 934 characters in body
Source Link
Shane Fontaine
  • 18.3k
  • 20
  • 56
  • 83

The only option to do this is to use the takeSnapshot and revertToSnapshot functions in that same repo.

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.


Edit

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.

The only option to do this is to use the takeSnapshot and revertToSnapshot functions in that same repo.

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 only option to do this is to use the takeSnapshot and revertToSnapshot functions in that same repo.

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.


Edit

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.

Source Link
Shane Fontaine
  • 18.3k
  • 20
  • 56
  • 83

The only option to do this is to use the takeSnapshot and revertToSnapshot functions in that same repo.

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.