5

How can one set the block height of testrpc so that a contract can react on the new height.

Concrete problem is that I want to write an automated test that shows that after a certain block number conditional can be executed.

  • Do you have to test against the exact block number, or can it be relative? Could you just check that block2.number - block1.number is sufficient? – Raine Revere Jul 11 '16 at 17:51
  • You could restart testrpc and run exactly enough transactions to get to a certain block number, but that seems unrealistic. In the real world you will only be able to control relative block numbers, not exact. – Raine Revere Jul 11 '16 at 17:52
  • yes, better to be testrpc agnostic, so that you can run em also on a real node once in a while – Roland Kofler Jul 12 '16 at 8:00
5

Since testrpc mines one block per transaction, you could just send transactions until the corrrect block height is reached.

If you're doing automated testing, you can use the evm_snapshot and evm_revert commands so that you don't need to send the transactions on every test, just once at the beginning.

  • 2
    Can you share more information on how to set the block height using evm_snapshot? – Yuanfei Zhu Jul 26 '17 at 10:02

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.