From f14eeb688b30e1cb3be8db247bd7699ac3fb4d7c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 5 Jul 2022 15:04:25 +0200 Subject: [PATCH] [WIP sales] Handle request expiry --- codex/sales.nim | 8 ++++---- tests/codex/testsales.nim | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/codex/sales.nim b/codex/sales.nim index 74e763c8..703ff322 100644 --- a/codex/sales.nim +++ b/codex/sales.nim @@ -116,9 +116,9 @@ proc subscribeFulfill(negotiation: Negotiation) {.async.} = negotiation.subscription = some subscription proc waitForExpiry(negotiation: Negotiation) {.async.} = - without offer =? negotiation.offer: + without request =? negotiation.request: return - await negotiation.sales.clock.waitUntil(offer.expiry.truncate(int64)) + await negotiation.sales.clock.waitUntil(request.expiry.truncate(int64)) negotiation.finish(success = false) proc start(negotiation: Negotiation) {.async.} = @@ -142,11 +142,11 @@ proc start(negotiation: Negotiation) {.async.} = negotiation.finish(success = false) return + negotiation.waiting = some negotiation.waitForExpiry() + await retrieve(request.content.cid) let proof = await prove(request.content.cid) await market.fulfillRequest(request.id, proof) - - negotiation.waiting = some negotiation.waitForExpiry() except CancelledError: raise except CatchableError as e: diff --git a/tests/codex/testsales.nim b/tests/codex/testsales.nim index 997c7d97..f7d29557 100644 --- a/tests/codex/testsales.nim +++ b/tests/codex/testsales.nim @@ -12,7 +12,7 @@ suite "Sales": duration=60.u256, minPrice=42.u256 ) - let request = StorageRequest( + var request = StorageRequest( ask: StorageAsk( duration: 60.u256, size: 100.u256, @@ -35,6 +35,7 @@ suite "Sales": sales.retrieve = proc(_: string) {.async.} = discard sales.prove = proc(_: string): Future[seq[byte]] {.async.} = return proof await sales.start() + request.expiry = (clock.now() + 42).u256 teardown: await sales.stop() @@ -121,10 +122,10 @@ suite "Sales": market.fulfillRequest(request.id, proof, otherHost) check sales.available == @[availability] - # test "makes storage available again when offer expires": - # sales.add(availability) - # discard await market.requestStorage(request) - # let offer = market.offered[0] - # clock.set(offer.expiry.truncate(int64)) - # await sleepAsync(chronos.seconds(2)) - # check sales.available.contains(availability) + test "makes storage available again when request expires": + sales.retrieve = proc(_: string) {.async.} = await sleepAsync(1.hours) + sales.add(availability) + discard await market.requestStorage(request) + clock.set(request.expiry.truncate(int64)) + await sleepAsync(2.seconds) + check sales.available == @[availability]