2

How can I fix this?

See:

$ truffle console
truffle(development)> web3.eth.getBlock("latest").timestamp
> 1506694386
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [500000], id: 123})
{ id: 123, jsonrpc: '2.0', result: 500000 }
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [500000], id: 123})
{ id: 123, jsonrpc: '2.0', result: 1000000 }

When using evm_increaseTime, the result returns a value that appends to 0, instead of adding onto the block time.

The expected result value should be 1506694386 + 500000, but instead, it returns 0 + 500000.

Your Environment

  • Version used: v4.1.3
  • Operating System and version: Mac OSX

EDIT: On the suggestion of force-mining:

If I mine a block before (or even after) performing evm_increaseTime, it does not make a difference:

$ truffle console
truffle(development)> web3.eth.getBlock("latest").timestamp
1506739091
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0})
{ id: 0, jsonrpc: '2.0', result: [] }
truffle(development)> web3.eth.getBlock("latest").timestamp
1506739124
truffle(development)> web3.eth.getBlock("latest").timestamp
1506739124
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [500000], id: 123})
{ id: 123, jsonrpc: '2.0', result: 500000 }
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0})
{ id: 0, jsonrpc: '2.0', result: [] }
truffle(development)> web3.currentProvider.send({jsonrpc: "2.0", method: "evm_increaseTime", params: [500000], id: 123})
{ id: 123, jsonrpc: '2.0', result: 1000000 }
3

Looking at the testrpc docs https://github.com/ethereumjs/testrpc :

evm_increaseTime : Jump forward in time. Takes one parameter, which is the amount of time to increase in seconds. Returns the total time adjustment, in seconds.

So it's normal that the first call you make returns 500000 and the second call returns the total time adjustment 500000 + 500000 = 1000000.

To make those adjustments effective you need to force a block to be mined after you've ran evm_increaseTime :

web3.currentProvider.send({jsonrpc: "2.0", method: "evm_mine", params: [], id: 0})

afterwards you can check the current timestamp with:

web3.eth.getBlock(web3.eth.blockNumber).timestamp

  • Not working, see my edit. – nubela Sep 30 '17 at 2:39
  • So the right order of things is : evm_increaseTime -> evm_mine -> check timestamp . In your edited example you're not checking the time stamp after running evm_increaseTime and evm_mine , you need to check the timestamp as the last step – Adil Sep 30 '17 at 6:52
  • you are right! working now. – nubela Sep 30 '17 at 15:13
0

result field in response to evm_increaseTime call contains timestamp adjustment, not timestamp of the next block.

Check the source code:

BlockchainDouble.prototype.increaseTime = function(seconds) {
  if (seconds < 0) seconds = 0;
  this.timeAdjustment += seconds;
  return this.timeAdjustment;
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.