1

While using SimulateBackend I attempted to roll forward the time of the simulated blockchain using AdjustTime(604800 *time.Second) which should roll forward time by a week. Checking the returned error value shows that it is nil, however from all my testing it appears that time does not actually roll forward, and local system time is used. Attempting to call functions which should work after time is rolled forward, do not work.

go version: go1.10.11 linux/amd64

Using the lates go-ethereum version.

1

Are you doing a client.Commit() afterwards. I can't remember if it is necessary - but I have got into the habit of doing it so I assume it is.

The only way you will be able to test this function is to have a function that returns now or block.timestamp

I do this by having a small contract :

pragma solidity ^0.4.24;

contract Canary {

    function timeStamp() constant returns (uint256) {
        return now;
    }
}

This allows you to check the time before and after adjusting the time - or (for example) during a crowdsale - to adjust the time to a specific new time, e.g. sale start.

now, err := canary.TimeStamp(nil)
if err != nil {
    log.Fatal(err)
}

timeOffset := new(big.Int).Sub(targetTime, now).Int64()
c.AdjustTime(time.Duration(timeOffset) * time.Second)
c.Commit()

This only fails if you try to take the simulated chain ahead of your real current time.

  • So that's the issue! I had suspected that it was limited by your system time although I was never able to confirm this as the documentation on simulated time is sparse. The issue I was having is not being able to roll forward time in the future (1 week ahead of system time, etc..) – hextet Jun 14 '18 at 5:41
  • I handle that by putting all dates back in time by a year or some other suitable constant in a general purpose routine. This allowed me to test code over a 20 year period. – Dave Appleton Oct 23 '18 at 20:29

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.