[market] Add Market.getTime()

This commit is contained in:
Mark Spanbroek 2022-03-30 13:01:44 +02:00 committed by markspanbroek
parent 061b32296a
commit dd89a55351
4 changed files with 11 additions and 1 deletions

View File

@ -40,7 +40,7 @@ method offerStorage(market: OnChainMarket, offer: StorageOffer) {.async.} =
method selectOffer(market: OnChainMarket, offerId: array[32, byte]) {.async.} =
await market.contract.selectOffer(offerId)
proc getTime(market: OnChainMarket): Future[UInt256] {.async.} =
method getTime(market: OnChainMarket): Future[UInt256] {.async.} =
let provider = market.contract.provider
let blck = !await provider.getBlock(BlockTag.latest)
return blck.timestamp

View File

@ -23,6 +23,9 @@ method offerStorage*(market: Market, offer: StorageOffer) {.base, async.} =
method selectOffer*(market: Market, id: array[32, byte]) {.base, async.} =
raiseAssert("not implemented")
method getTime*(market: Market): Future[UInt256] {.base, async.} =
raiseAssert("not implemented")
method waitUntil*(market: Market, expiry: UInt256) {.base, async.} =
raiseAssert("not implemented")

View File

@ -165,6 +165,10 @@ ethersuite "On-Chain Market":
await subscription.unsubscribe()
test "can retrieve current block time":
let latestBlock = !await provider.getBlock(BlockTag.latest)
check (await market.getTime()) == latestBlock.timestamp
test "supports waiting for expiry of a request or offer":
let pollInterval = 100.milliseconds
market.pollInterval = pollInterval

View File

@ -71,6 +71,9 @@ method unsubscribe*(subscription: OfferSubscription) {.async.} =
func `<`(a, b: Expiry): bool =
a.expiry < b.expiry
method getTime*(market: MockMarket): Future[UInt256] {.async.} =
return market.time
method waitUntil*(market: MockMarket, expiry: UInt256): Future[void] =
let future = Future[void]()
if expiry > market.time: