Skip to content

Instantly share code, notes, and snippets.

@mds1
Created August 26, 2018 15:53
Show Gist options
  • Select an option

  • Save mds1/0a3a2fbaa08474bb1317d1f4b1f6d514 to your computer and use it in GitHub Desktop.

Select an option

Save mds1/0a3a2fbaa08474bb1317d1f4b1f6d514 to your computer and use it in GitHub Desktop.

Revisions

  1. mds1 created this gist Aug 26, 2018.
    32 changes: 32 additions & 0 deletions increase-EVM-time.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    /**
    * Increase EVM time in ganache-cli to simulate calls in the future
    * @param integer Number of seconds to increase time by
    */
    async function increaseTime(integer) {
    // First we increase the time
    await web3.currentProvider.send({
    jsonrpc: '2.0',
    method: 'evm_increaseTime',
    params: [integer],
    id: 0,
    }, () => {});

    // Then we mine a block to actually get the time change to occurs
    // See this issue: https://github.com/trufflesuite/ganache-cli/issues/394
    await web3.currentProvider.send({
    jsonrpc: '2.0',
    method: 'evm_mine',
    params: [],
    id: 0,
    }, () => { });

    // This does not seem to work properly. After using this function the
    // ganache-cli timestamp is updated properly, but the timestamp returned
    // from the contract itself is not updated. See this issue:
    // https://github.com/trufflesuite/ganache-cli/issues/336

    /* Note: witout the blank callbacks you get:
    Error: No callback provided to provider's send function. As of web3
    1.0, provider.send is no longer synchronous and must be passed a
    callback as its final argument. */
    } // end increaseTime