All Projects → ejwessel → GanacheTimeTraveler

ejwessel / GanacheTimeTraveler

Licence: other
Web3 ganache-cli commands that allow moving forward and backward in time

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to GanacheTimeTraveler

whatdevsneed
Discover new developer tools 🧰
Stars: ✭ 48 (+9.09%)
Mutual labels:  developer-tools
beneath
Beneath is a serverless real-time data platform ⚡️
Stars: ✭ 65 (+47.73%)
Mutual labels:  developer-tools
blimp
Blimp: Develop with Docker Compose in the cloud
Stars: ✭ 96 (+118.18%)
Mutual labels:  developer-tools
red
A fast, in-kernel, ad-hoc point-to-point vxlan network.
Stars: ✭ 31 (-29.55%)
Mutual labels:  developer-tools
ethdock
Ethereum development package in docker.
Stars: ✭ 25 (-43.18%)
Mutual labels:  truffle
myke
make with yaml: development tasks made simple with golang, yaml and many ingredients
Stars: ✭ 67 (+52.27%)
Mutual labels:  developer-tools
elm-book
Rich documentation builder for Elm applications and packages. Inspired by Storybook and HexDocs.
Stars: ✭ 52 (+18.18%)
Mutual labels:  developer-tools
AppIconSetGen
Tool to generate App Icon set for iOS, macOS, watchOS apps
Stars: ✭ 20 (-54.55%)
Mutual labels:  developer-tools
pganonymize
A commandline tool for anonymizing PostgreSQL databases
Stars: ✭ 20 (-54.55%)
Mutual labels:  developer-tools
truffle-privatekey-provider
Private Key Web3 provider
Stars: ✭ 44 (+0%)
Mutual labels:  truffle
komit
An interactive prompt for conventional commit messages that doesn't get in your way. Designed to run as a git hook.
Stars: ✭ 29 (-34.09%)
Mutual labels:  developer-tools
cita-truffle-box
Develop DApps on CITA
Stars: ✭ 12 (-72.73%)
Mutual labels:  truffle
tools-install
Setup scripts for various dev tools, utilities, SDKs and CLI stuff
Stars: ✭ 13 (-70.45%)
Mutual labels:  developer-tools
bodhi-core
Smart Contracts for the Bodhi Prediction Market
Stars: ✭ 32 (-27.27%)
Mutual labels:  truffle
Umbraco.GodMode
Diplo God Mode makes Umbraco developers invincible!
Stars: ✭ 16 (-63.64%)
Mutual labels:  developer-tools
localhostd
Run and serve your web apps in .test domains on your develop machine.
Stars: ✭ 27 (-38.64%)
Mutual labels:  developer-tools
narc
Small utility to watch log files and ship to syslog service.
Stars: ✭ 18 (-59.09%)
Mutual labels:  developer-tools
sp-live-reload
SharePoint pages live reload module for client side development
Stars: ✭ 23 (-47.73%)
Mutual labels:  developer-tools
email-concealer-cli
CLI tool for concealing e-mails in a file by replacing their domain
Stars: ✭ 30 (-31.82%)
Mutual labels:  developer-tools
hapi-dev-errors
A hapi plugin to return better error details and skip the look at command line to catch the issue.
Stars: ✭ 58 (+31.82%)
Mutual labels:  developer-tools

ganache-time-traveler

A ganache utility that simplifies writing time dependent or stateless tests on a local Ethereum blockchain.

NOTE:

  • this only works with ganache-cli
  • this only works locally

Tool Dependencies

Install

  • npm i ganache-time-traveler

Usage

The general outline is to add require at the top of your tests

const timeMachine = require('ganache-time-traveler');

add the beforeEach and afterEach hooks into your truffle test file

contract('Test', async (accounts) =>  {

   let exampleContract;

   beforeEach(async() => {
       let snapshot = await timeMachine.takeSnapshot();
       snapshotId = snapshot['result'];
   });

   afterEach(async() => {
       await timeMachine.revertToSnapshot(snapshotId);
   });

   before('Deploy Contracts', async() => {
       /* DEPLOY CONTRACTS HERE */
       exampleContract = await ExampleContract.new();
   });

   /* ADD TESTS HERE */

   it('Time Dependent Test', async () => {
       await timeMachine.advanceTimeAndBlock(/* SECONDS TO ADVANCE BY */);
   });
});

Methods

advanceTime(<seconds_to_advance_by>)

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 advanceBlock(). See advanceTimeAndBlock() to do both.

advanceBlock()

Mines a new block; advances the block forward by 1 block.

advanceBlockAndSetTime(<new_time>)

Advances the block forward by 1 and sets the time to a new time.

advanceTimeAndBlock(<seconds_to_advance_by>)

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.

takeSnapshot()

Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the integer id of the snapshot created.

revertToSnapshot(<id_to_revert_to>)

Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to.

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].