From dd89a553518654e4cd5b8026b5087db7017f481f Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 30 Mar 2022 13:01:44 +0200 Subject: [PATCH] [market] Add Market.getTime() --- dagger/contracts/market.nim | 2 +- dagger/market.nim | 3 +++ tests/contracts/testMarket.nim | 4 ++++ tests/dagger/helpers/mockmarket.nim | 3 +++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dagger/contracts/market.nim b/dagger/contracts/market.nim index 5d0078b1..4ad4e341 100644 --- a/dagger/contracts/market.nim +++ b/dagger/contracts/market.nim @@ -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 diff --git a/dagger/market.nim b/dagger/market.nim index 9e85ea2c..715a008b 100644 --- a/dagger/market.nim +++ b/dagger/market.nim @@ -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") diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index 48a875ff..025865bb 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -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 diff --git a/tests/dagger/helpers/mockmarket.nim b/tests/dagger/helpers/mockmarket.nim index 67985f72..a4d1c474 100644 --- a/tests/dagger/helpers/mockmarket.nim +++ b/tests/dagger/helpers/mockmarket.nim @@ -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: