Time manipulation in Truffle console with OpenZeppelin Test Helpers

Hi, in truffle console after inputting await time.increase(time.duration.minutes(2)); from "@openzeppelin/test-helpers": "^0.5.6" I got the error

Uncaught Error: Invalid JSON RPC response: ""
    at XMLHttpRequest._onHttpRequestError (/Users/anhdungle/learning/mooniswap/node_modules/xhr2-cookies/xml-http-request.ts:379:8)
    at XMLHttpRequest._setReadyState (/Users/anhdungle/learning/mooniswap/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/anhdungle/learning/mooniswap/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest.request.onreadystatechange (/Users/anhdungle/learning/mooniswap/node_modules/web3/node_modules/web3-providers-http/src/index.js:107:32)
    at Object.InvalidResponse (/Users/anhdungle/learning/mooniswap/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:45:16)
truffle(development)> await time.increase(time.duration.minutes(2));
evalmachine.<anonymous>:1
  await time.increase(time.duration.minutes(2));
                                               ^

Uncaught SyntaxError: Unexpected token ';'
truffle(development)> await time.increase(time.duration.minutes
(2))
Uncaught Error: Invalid JSON RPC response: ""
    at XMLHttpRequest._onHttpRequestError (/Users/anhdungle/learning/mooniswap/node_modules/xhr2-cookies/xml-http-request.ts:379:8)
    at XMLHttpRequest._setReadyState (/Users/anhdungle/learning/mooniswap/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/anhdungle/learning/mooniswap/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest.request.onreadystatechange (/Users/anhdungle/learning/mooniswap/node_modules/web3/node_modules/web3-providers-http/src/index.js:107:32)
    at Object.InvalidResponse (/Users/anhdungle/learning/mooniswap/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:45:16)

Can you help me with this? Thanks a lot.

1 Like

Hi @Anh_Dung_Le,

Welcome to the community :wave:

I was able to use OpenZeppelin Test Helpers in a Truffle console with ganache-cli running in another terminal.

$ npx truffle console
truffle(development)> const {time} = require('@openzeppelin/test-helpers');
undefined
truffle(development)> (await time.latest()).toString()
'1600151667'
truffle(development)> await time.increase(time.duration.minutes(2));
undefined
truffle(development)> await time.advanceBlock()
{ id: 1600151532744, jsonrpc: '2.0', result: '0x0' }
truffle(development)> (await time.latest()).toString()
'1600151892'

I just had Truffle installed and OpenZeppelin Test Helpers, along with ganache-cli.

My truffle-config.js was as follows:

...
  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 8545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },
...

Hi @Anh_Dung_Le,

I just wanted to check if the above solved your issue and if you needed any more information?

@abcoathup
thank you very much for your answer. I have just been busy with other stuff lately, so I haven’t had time to check it yet.

1 Like