https://github.com/bh2smith/ganache-snapshot
Simple package intended to make and revert snapshots of a ganache database.
https://github.com/bh2smith/ganache-snapshot
devtools ethereum ganache ganache-cli snapshot testing-tools
Last synced: about 1 year ago
JSON representation
Simple package intended to make and revert snapshots of a ganache database.
- Host: GitHub
- URL: https://github.com/bh2smith/ganache-snapshot
- Owner: bh2smith
- Created: 2019-07-03T14:49:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T21:21:59.000Z (over 3 years ago)
- Last Synced: 2025-04-24T03:13:34.618Z (about 1 year ago)
- Topics: devtools, ethereum, ganache, ganache-cli, snapshot, testing-tools
- Language: JavaScript
- Size: 385 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.com/bh2smith/ganache-snapshot)
[](https://badge.fury.io/js/ganache-snapshot)
# Ganache Snapshot
This plugin provides an easy and robut way to make and revert ganache snapshots for smart contract development.
Generally speaking, this is a development tool for testing long sequences of transactions.
## Installing the Plugin
To install the latest stable version from NPM:
```console
$ npm install -g ganache-snapshot
```
## Configuration & Usage
Currently, the plugin must be activated on a per-project basis. If `ganache-snapshot` was installed to the Truffle project root, it will attempty to automatically include itself into `truffle-config.js`. If installed globally, you will need to manually add the following to `truffle-config.js` in the root directory of your Truffle project to enable the plugin:
```javascript
module.exports = {
plugins: [ "ganache-snapshot" ]
};
```
Note also that, currently, the `development` network of the truffle configuration should be uncommented.
That is, development network is the hardcoded web3Provider and is expected to be declared.
### Usage Example - CLI
```bash
# Make sure that Ganache is running (in a separate terminal)
SNAP_ID=$(truffle run snapshot make)
# send some transaction...
truffle run snapshot revert $SNAP_ID
```
### Usage Example - truffle test
An example contract has been provided here and the use case is found in `test/example.js` with description.
Essentially, the recipe to follow is;
```js
const myContract = artifacts.require("SomeContract")
const { makeSnapshot, revertSnapshot } = require("ganache-snapshot")
const example = await myContract.new() // Deploy contract
const snapID = (await makeSnapshot(web3)).result // Take a snapshot and keep returned ID
await example.sendTranaction() // Send TX
await revertSnapshot(snapID, web3) // revert snapshot (by ID)
```