fix intermittent error in contract tests

currentTime() doesn't always correctly reflect
the time of the next transaction
This commit is contained in:
Mark Spanbroek 2024-11-12 20:54:43 +01:00
parent 044ceea946
commit bf183f9521
No known key found for this signature in database
GPG Key ID: FBE3E9548D427C00
2 changed files with 6 additions and 3 deletions

View File

@ -50,8 +50,8 @@ ethersuite "Marketplace contracts":
switchAccount(host) switchAccount(host)
discard await token.approve(marketplace.address, request.ask.collateral).confirm(1) discard await token.approve(marketplace.address, request.ask.collateral).confirm(1)
discard await marketplace.reserveSlot(request.id, 0.u256).confirm(1) discard await marketplace.reserveSlot(request.id, 0.u256).confirm(1)
filledAt = await ethProvider.currentTime() let receipt = await marketplace.fillSlot(request.id, 0.u256, proof).confirm(1)
discard await marketplace.fillSlot(request.id, 0.u256, proof).confirm(1) filledAt = await ethProvider.blockTime(BlockTag.init(!receipt.blockNumber))
slotId = request.slotId(0.u256) slotId = request.slotId(0.u256)
proc waitUntilProofRequired(slotId: SlotId) {.async.} = proc waitUntilProofRequired(slotId: SlotId) {.async.} =

View File

@ -1,8 +1,11 @@
import pkg/ethers import pkg/ethers
import pkg/serde/json 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.} = 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.} = proc advanceTime*(provider: JsonRpcProvider, seconds: UInt256) {.async.} =
discard await provider.send("evm_increaseTime", @[%("0x" & seconds.toHex)]) discard await provider.send("evm_increaseTime", @[%("0x" & seconds.toHex)])