[WIP sales] Handle request expiry
This commit is contained in:
parent
9438aba5d2
commit
f14eeb688b
|
@ -116,9 +116,9 @@ proc subscribeFulfill(negotiation: Negotiation) {.async.} =
|
||||||
negotiation.subscription = some subscription
|
negotiation.subscription = some subscription
|
||||||
|
|
||||||
proc waitForExpiry(negotiation: Negotiation) {.async.} =
|
proc waitForExpiry(negotiation: Negotiation) {.async.} =
|
||||||
without offer =? negotiation.offer:
|
without request =? negotiation.request:
|
||||||
return
|
return
|
||||||
await negotiation.sales.clock.waitUntil(offer.expiry.truncate(int64))
|
await negotiation.sales.clock.waitUntil(request.expiry.truncate(int64))
|
||||||
negotiation.finish(success = false)
|
negotiation.finish(success = false)
|
||||||
|
|
||||||
proc start(negotiation: Negotiation) {.async.} =
|
proc start(negotiation: Negotiation) {.async.} =
|
||||||
|
@ -142,11 +142,11 @@ proc start(negotiation: Negotiation) {.async.} =
|
||||||
negotiation.finish(success = false)
|
negotiation.finish(success = false)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
negotiation.waiting = some negotiation.waitForExpiry()
|
||||||
|
|
||||||
await retrieve(request.content.cid)
|
await retrieve(request.content.cid)
|
||||||
let proof = await prove(request.content.cid)
|
let proof = await prove(request.content.cid)
|
||||||
await market.fulfillRequest(request.id, proof)
|
await market.fulfillRequest(request.id, proof)
|
||||||
|
|
||||||
negotiation.waiting = some negotiation.waitForExpiry()
|
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
raise
|
raise
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
|
|
|
@ -12,7 +12,7 @@ suite "Sales":
|
||||||
duration=60.u256,
|
duration=60.u256,
|
||||||
minPrice=42.u256
|
minPrice=42.u256
|
||||||
)
|
)
|
||||||
let request = StorageRequest(
|
var request = StorageRequest(
|
||||||
ask: StorageAsk(
|
ask: StorageAsk(
|
||||||
duration: 60.u256,
|
duration: 60.u256,
|
||||||
size: 100.u256,
|
size: 100.u256,
|
||||||
|
@ -35,6 +35,7 @@ suite "Sales":
|
||||||
sales.retrieve = proc(_: string) {.async.} = discard
|
sales.retrieve = proc(_: string) {.async.} = discard
|
||||||
sales.prove = proc(_: string): Future[seq[byte]] {.async.} = return proof
|
sales.prove = proc(_: string): Future[seq[byte]] {.async.} = return proof
|
||||||
await sales.start()
|
await sales.start()
|
||||||
|
request.expiry = (clock.now() + 42).u256
|
||||||
|
|
||||||
teardown:
|
teardown:
|
||||||
await sales.stop()
|
await sales.stop()
|
||||||
|
@ -121,10 +122,10 @@ suite "Sales":
|
||||||
market.fulfillRequest(request.id, proof, otherHost)
|
market.fulfillRequest(request.id, proof, otherHost)
|
||||||
check sales.available == @[availability]
|
check sales.available == @[availability]
|
||||||
|
|
||||||
# test "makes storage available again when offer expires":
|
test "makes storage available again when request expires":
|
||||||
# sales.add(availability)
|
sales.retrieve = proc(_: string) {.async.} = await sleepAsync(1.hours)
|
||||||
# discard await market.requestStorage(request)
|
sales.add(availability)
|
||||||
# let offer = market.offered[0]
|
discard await market.requestStorage(request)
|
||||||
# clock.set(offer.expiry.truncate(int64))
|
clock.set(request.expiry.truncate(int64))
|
||||||
# await sleepAsync(chronos.seconds(2))
|
await sleepAsync(2.seconds)
|
||||||
# check sales.available.contains(availability)
|
check sales.available == @[availability]
|
||||||
|
|
Loading…
Reference in New Issue