clock: use wall clock in integration tests

reason: we'll need to wait for the next period in
integration tests, and we can't do that if the
time doesn't advance
This commit is contained in:
Mark Spanbroek 2024-02-22 07:18:17 +01:00
parent d442cc80d7
commit 2a1ef5d9e6
No known key found for this signature in database
GPG Key ID: FBE3E9548D427C00
1 changed files with 2 additions and 16 deletions

View File

@ -47,22 +47,8 @@ method stop*(clock: OnChainClock) {.async.} =
clock.started = false
method now*(clock: OnChainClock): SecondsSince1970 =
when codex_use_hardhat:
# hardhat's latest block.timestamp is usually 1s behind the block timestamp
# in the newHeads event. When testing, always return the latest block.
try:
if queriedBlock =? (waitFor clock.provider.getBlock(BlockTag.latest)):
trace "using last block timestamp for clock.now",
lastBlockTimestamp = queriedBlock.timestamp.truncate(int64),
cachedBlockTimestamp = clock.lastBlockTime.truncate(int64)
return queriedBlock.timestamp.truncate(int64)
except CatchableError as e:
warn "failed to get latest block timestamp", error = e.msg
return clock.lastBlockTime.truncate(int64)
else:
doAssert clock.started, "clock should be started before calling now()"
return toUnix(getTime() + clock.offset)
doAssert clock.started, "clock should be started before calling now()"
return toUnix(getTime() + clock.offset)
method waitUntil*(clock: OnChainClock, time: SecondsSince1970) {.async.} =
while (let difference = time - clock.now(); difference > 0):