Skip to content

Instantly share code, notes, and snippets.

@mpolci
Last active July 20, 2016 06:01
Show Gist options
  • Save mpolci/f2c4a80667b47acdfd016664a0c41999 to your computer and use it in GitHub Desktop.
Save mpolci/f2c4a80667b47acdfd016664a0c41999 to your computer and use it in GitHub Desktop.
Manage evm_setTimestamp RPC call provided by the modified testrpc from https://github.com/Georgi87/testrpc
function rpc(method, arg) {
var req = {
jsonrpc: "2.0",
method: method,
id: new Date().getTime()
};
if (arg) req.params = arg;
return new Promise((resolve, reject) => {
web3.currentProvider.sendAsync(req, (err, result) => {
if (err) return reject(err)
if (result && result.error) {
return reject(new Error("RPC Error: " + (result.error.message || result.error)))
}
resolve(result)
})
})
}
// Change block time using the rpc call "evm_setTimestamp" available in the testrpc fork https://github.com/Georgi87/testrpc
web3.evm = web3.evm || {}
web3.evm.setTimestamp = function (time) {
return rpc('evm_setTimestamp', [time])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment