From bf183f9521f802b25accc9ad7bc1ab08ccab6676 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 12 Nov 2024 20:54:43 +0100 Subject: [PATCH] fix intermittent error in contract tests currentTime() doesn't always correctly reflect the time of the next transaction --- tests/contracts/testContracts.nim | 4 ++-- tests/contracts/time.nim | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/contracts/testContracts.nim b/tests/contracts/testContracts.nim index 8743ef85..3b95c5fc 100644 --- a/tests/contracts/testContracts.nim +++ b/tests/contracts/testContracts.nim @@ -50,8 +50,8 @@ ethersuite "Marketplace contracts": switchAccount(host) discard await token.approve(marketplace.address, request.ask.collateral).confirm(1) discard await marketplace.reserveSlot(request.id, 0.u256).confirm(1) - filledAt = await ethProvider.currentTime() - discard await marketplace.fillSlot(request.id, 0.u256, proof).confirm(1) + let receipt = await marketplace.fillSlot(request.id, 0.u256, proof).confirm(1) + filledAt = await ethProvider.blockTime(BlockTag.init(!receipt.blockNumber)) slotId = request.slotId(0.u256) proc waitUntilProofRequired(slotId: SlotId) {.async.} = diff --git a/tests/contracts/time.nim b/tests/contracts/time.nim index ae448789..c8e51b0c 100644 --- a/tests/contracts/time.nim +++ b/tests/contracts/time.nim @@ -1,8 +1,11 @@ import pkg/ethers import pkg/serde/json +proc blockTime*(provider: Provider, tag: BlockTag): Future[UInt256] {.async.} = + return (!await provider.getBlock(tag)).timestamp + proc currentTime*(provider: Provider): Future[UInt256] {.async.} = - return (!await provider.getBlock(BlockTag.pending)).timestamp + return await provider.blockTime(BlockTag.pending) proc advanceTime*(provider: JsonRpcProvider, seconds: UInt256) {.async.} = discard await provider.send("evm_increaseTime", @[%("0x" & seconds.toHex)])