1

In Ganache, I use evm_mine to simulate the passage of time.

Assuming block times are accurate enough, what are the best practices to test some contracts on the mainnet or a testnet which depend on block numbers for various computations?

Should a truffle test process be started and, when a time-dependent test is hit, just run a while instruction and wait for the block number to be generated? Or should something like Oraclize be used?

1

There is no way to adjust the time on the main network. If you are trying to run time-depeendant tests, your best option is to use ganache.

Another option you have is to use Kovan, which is a PoA testnet with <5s block times. This is a good way to mimic the main network while still getting quicker block times.

Lastly, it sounds as though what you are doing is not time dependant, but rather block number dependant. Ganache does process transactions using block numbers, though it is not as clear. You can use these block numbers, if they fit your needs.

Update based on comment

In order to apply your current tests on gamache to a testnet, you would add a waitForBlock function that waits for a specific block number. As you mentioned in the question, you can simply write this into a while loop.

You can use a filter to wait for changes.

  • 1
    Thank you for your answer but, unfortunately, this is not what I was referring to. I am able to run tests on Ganache, the question is how to retrofit those tests to a testnet or mainnet (specifically referring to the JavaScript code in the test folder). – Paul Razvan Berg Nov 16 '18 at 15:32
  • I see. I have updated the answer. – shane Nov 16 '18 at 15:41

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.