I'm running some tests over my contract using TestRPC and Mocha.

I'm writing a debt manager. My data structure has a field called validity, which is semantically a date that determines until when this debt can be paid without a fine.

Some of my business rules are:

  1. I cannot insert a registry with validity in the past
  2. When I try to pay the debt and it is past its validity, I have to add a fine to the due value.

My contract has a rule that checks (simplified version):

function getValue() returns (uint) {
    if (now > validity) 
        return value + fine;
        return value;

I generate a registry with validity very near in the future in order to allow it to be inserted.

I tried to set a delay for the test case, in order to get the "out of validity" condition when I want to getValue() of the registry, but I'm not getting into that branch. It keeps returning only value instead of value + fine.

Then I discovered that now is just an alias to block.timestamp, which leads me to a problem:

How can I delay execution of the test until the next block is mined?


You can use the function evm_increaseTime to artificially increase the time during the tests with testrpc.


| improve this answer | |

couldn't you use something like this ?

modifier onlyAfter(uint _time) { if (now <= _time) throw; _ }

function getValue() onlyAfter(validity) returns (uint){
| improve this answer | |
  • Yes, I could, but this is not what my problem is. I'm running test cases and need to wait for the next block. – Henrique Barcelos May 12 '16 at 23:51

Your Answer

