From 2a1ef5d9e661827264c3011a3d898105c9f219a1 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 22 Feb 2024 07:18:17 +0100 Subject: [PATCH] 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 --- codex/contracts/clock.nim | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/codex/contracts/clock.nim b/codex/contracts/clock.nim index 9102e5c2..da85e4e4 100644 --- a/codex/contracts/clock.nim +++ b/codex/contracts/clock.nim @@ -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):