mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-22 02:39:27 +00:00
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:
parent
d442cc80d7
commit
2a1ef5d9e6
@ -47,22 +47,8 @@ method stop*(clock: OnChainClock) {.async.} =
|
|||||||
clock.started = false
|
clock.started = false
|
||||||
|
|
||||||
method now*(clock: OnChainClock): SecondsSince1970 =
|
method now*(clock: OnChainClock): SecondsSince1970 =
|
||||||
when codex_use_hardhat:
|
doAssert clock.started, "clock should be started before calling now()"
|
||||||
# hardhat's latest block.timestamp is usually 1s behind the block timestamp
|
return toUnix(getTime() + clock.offset)
|
||||||
# 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)
|
|
||||||
|
|
||||||
method waitUntil*(clock: OnChainClock, time: SecondsSince1970) {.async.} =
|
method waitUntil*(clock: OnChainClock, time: SecondsSince1970) {.async.} =
|
||||||
while (let difference = time - clock.now(); difference > 0):
|
while (let difference = time - clock.now(); difference > 0):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user