Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ether-time-traveler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ether-time-traveler

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

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

ether-time-traveler

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

Forked from ejwessel's ganache-time-traveler to allow use in a testing environment using ethers.js.

Install

  • npm i ether-time-traveler

Usage

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

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

add the beforeEach and afterEach hooks into your test file

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

   const provider = new MockProvider();
   let exampleContract;

   beforeEach(async() => {
       let snapshotId = await timeMachine.takeSnapshot(provider);
   };

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

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

   /* ADD TESTS HERE */

   it('Time Dependent Test', async () => {
       await timeMachine.advanceTimeAndBlock(provider, SECONDS_TO_ADVANCE_BY)
   });
});

Methods

advanceTime(<ethers_provider>, <seconds_to_advance_by>)

Advances the time on the blockchain forward. Takes an extra 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(<ethers_provider>)

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

advanceBlockAndSetTime(<ethers_provider>, <new_time>)

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

advanceTimeAndBlock(<ethers_provider>, <seconds_to_advance_by>)

Advances the block by 1 in addition to advancing the time on the blockchain forward. Takes an extra parameter, which is the number of seconds to advance by.

takeSnapshot(<ethers_provider>)

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

revertToSnapshot(<ethers_provider>, <id_to_revert_to>)

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

Resources

Keywords

FAQs

Package last updated on 20 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc