Code Monkey home page Code Monkey logo

ganache-snapshot's Introduction

Build Status npm version

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:

$ 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:

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

# 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;

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)

ganache-snapshot's People

Contributors

bh2smith avatar fleupold avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.