Last active
July 20, 2016 06:01
-
-
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
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
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