[sales] Make storage available again when offer declined
This commit is contained in:
parent
5d434f20d3
commit
e46c9816fa
|
@ -73,8 +73,11 @@ proc handleRequest(sales: Sales, request: StorageRequest) {.async.} =
|
||||||
proc onSelect(offerId: array[32, byte]) {.gcsafe, upraises:[].} =
|
proc onSelect(offerId: array[32, byte]) {.gcsafe, upraises:[].} =
|
||||||
if subscription =? subscription:
|
if subscription =? subscription:
|
||||||
asyncSpawn subscription.unsubscribe()
|
asyncSpawn subscription.unsubscribe()
|
||||||
if onSale =? sales.onSale and offer.id == offerId:
|
if offer.id == offerId:
|
||||||
onSale(offer)
|
if onSale =? sales.onSale:
|
||||||
|
onSale(offer)
|
||||||
|
else:
|
||||||
|
sales.add(availability)
|
||||||
subscription = some await sales.market.subscribeSelection(request.id, onSelect)
|
subscription = some await sales.market.subscribeSelection(request.id, onSelect)
|
||||||
|
|
||||||
proc start*(sales: Sales) =
|
proc start*(sales: Sales) =
|
||||||
|
|
|
@ -87,3 +87,11 @@ suite "Sales":
|
||||||
otherOffer = await market.offerStorage(otherOffer)
|
otherOffer = await market.offerStorage(otherOffer)
|
||||||
await market.selectOffer(otherOffer.id)
|
await market.selectOffer(otherOffer.id)
|
||||||
check not didSell
|
check not didSell
|
||||||
|
|
||||||
|
test "makes storage available again when different offer is selected":
|
||||||
|
sales.add(availability)
|
||||||
|
let request = await market.requestStorage(request)
|
||||||
|
var otherOffer = StorageOffer(requestId: request.id, price: 1.u256)
|
||||||
|
otherOffer = await market.offerStorage(otherOffer)
|
||||||
|
await market.selectOffer(otherOffer.id)
|
||||||
|
check sales.available.contains(availability)
|
||||||
|
|
Loading…
Reference in New Issue