7

Any tips on how to simulate real network conditions on the testrpc testing client using truffle? I have some functions that look at blocknumber and try to deal with passing time. Has anyone come up with a good way to test these kind of things?

I'm wondering if just calling some null transactions in a loop with increase the block number accordingly. Any info on the inner workings of these things would be appreciated.

11

By default, every transaction called in testrpc is immediately mined and the block height will increase. The time it takes to mine each block can be set as a command line option when starting testrpc using -b or --blocktime

In addition, testrpc provides a custom rpc method you can use to manipulate the block height:

evm_mine : Force a block to be mined. Takes no parameters. Mines a block independent of whether or not mining is started or stopped.

Testrpc's custom methods can be called from web3 using web3.currentProvider.sendAsync() like so:

web3.currentProvider.sendAsync({
  jsonrpc: "2.0",
  method: "evm_mine",
  id: 12345
}, function(err, result) {
  // this is your callback
});
  • 1
    I'd love some clarification in this answer! e.g. How can I make testrpc pass 180 days? – mesqueeb Feb 22 '18 at 5:41
  • 1
    @mesqueeb There's a method in ganache called evm_increaseTime – Paul Berg Nov 12 '18 at 18:40

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.