Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

evm_setTime fails when called through web3.currentProvider.send #600

Closed
Ivshti opened this issue Aug 1, 2020 · 0 comments · Fixed by #601
Closed

evm_setTime fails when called through web3.currentProvider.send #600

Ivshti opened this issue Aug 1, 2020 · 0 comments · Fixed by #601

Comments

@Ivshti
Copy link
Contributor

Ivshti commented Aug 1, 2020

calling evm_setTime fails when using web3.currentProvider.send

Expected Behavior

Calling evm_setTime with anything that can be cast into a JS date should set the blockchain time

Current Behavior

Calling evm_setTime with anything that can be cast into a JS date returns an exception through the JSONRPC response (eg { error: { message: 'e.getTime() is not a function' .... })

Possible Solution

It can be worked around by editing the mangled file (ganache-core.node.cli.js) to replace p.prototype.evm_setTime=function(e,t){t(null,this.state.blockchain.setTime(e))} with p.prototype.evm_setTime=function(e,t){t(null,this.state.blockchain.setTime(new Date(e)))}
Apparently the original code was added here: cec7362 but it's out of this repo now

Since the input is passed through JSONRPC, it can be either Number/String but not a Date. I tried passing a timestamp number too, same error.

Steps to Reproduce (for bugs)

Using this code to call into a ganache-cli over network:

async function setTime(web3, time) {
	// Doesn't work cause of a ganache bug: `e.getTime is not a function` cause it doesn't construct a date from the JSONRPC input
	return new Promise(function(resolve, reject) {
		web3.currentProvider.send(
			{
				jsonrpc: '2.0',
				method: 'evm_setTime',
				params: [new Date(time * 1000)],
				id: 0
			},
			(err, res) => (err ? reject(err) : (res.error ? reject(res.error) : resolve(res)))
		)
	})
}

The result is the following exception:

e.getTime() is not a function

This message comes through from JSONRPC (through the res.error that's returned from ganache)

Context

Trying to move the blockchain time backwards during testing.
evm_increaseTime does not help here since a specific time is hardcoded into the contract

Your Environment

Latest ganache from NPM, v6.9.1
Project: https://github.com/AdExNetwork/adex-protocol-eth/tree/new-token and namely https://github.com/AdExNetwork/adex-protocol-eth/blob/new-token/test/TestADXToken.js - notice the SupplyController test and also https://github.com/AdExNetwork/adex-protocol-eth/blob/new-token/test/index.js where setTime is implemented

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant