[sales] Make storage available again when offer declined

This commit is contained in:
Mark Spanbroek 2022-03-31 13:36:03 +02:00 committed by markspanbroek
parent 5d434f20d3
commit e46c9816fa
2 changed files with 13 additions and 2 deletions

View File

@ -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:
if onSale =? sales.onSale:
onSale(offer) 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) =

View File

@ -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)