Skip to content

Commit

Permalink
fix intermittent error in contract tests
Browse files Browse the repository at this point in the history
currentTime() doesn't always correctly reflect
the time of the next transaction
  • Loading branch information
markspanbroek committed Nov 12, 2024
1 parent 044ceea commit bf183f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/contracts/testContracts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down
5 changes: 4 additions & 1 deletion tests/contracts/time.nim
Original file line number Diff line number Diff line change
@@ -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)])
Expand Down

0 comments on commit bf183f9

Please sign in to comment.