Created
August 26, 2018 15:53
-
-
Save mds1/0a3a2fbaa08474bb1317d1f4b1f6d514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment