sol-time-machine

Block manager library for Solidity tests

Usage no npm install needed!

<script type="module">
  import solTimeMachine from 'https://cdn.skypack.dev/sol-time-machine';
</script>

README

sol-time-machine

Block manager for Solidity tests

Install

npm install sol-time-machine

Usage

const TimeMachine = require('sol-time-machine')
const timeMachine = new TimeMachine(global.web3)

snapshot/revert

// test.js
contract('Example', (accounts) => {
  beforeEach(async () => {
    await timeMachine.snapshot()
  })
  
  afterEach(async () => {
    await timeMachine.revert()
  })

  // Your tests here...
})

mine

// advance 10 blocks
await timeMachine.mine(10)

mineTo

// advance to block number 10
await timeMachine.mineTo(10)