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.

Roland Kofler
  • 11,638
  • 3
  • 44
  • 83
  • 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 08:00

1 Answers1

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.

Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118