diff --git a/dagger/sales.nim b/dagger/sales.nim index 4fdff93b..f5d5c34e 100644 --- a/dagger/sales.nim +++ b/dagger/sales.nim @@ -73,8 +73,11 @@ proc handleRequest(sales: Sales, request: StorageRequest) {.async.} = proc onSelect(offerId: array[32, byte]) {.gcsafe, upraises:[].} = if subscription =? subscription: asyncSpawn subscription.unsubscribe() - if onSale =? sales.onSale and offer.id == offerId: - onSale(offer) + if offer.id == offerId: + if onSale =? sales.onSale: + onSale(offer) + else: + sales.add(availability) subscription = some await sales.market.subscribeSelection(request.id, onSelect) proc start*(sales: Sales) = diff --git a/tests/dagger/testsales.nim b/tests/dagger/testsales.nim index aad99ca3..a6890a99 100644 --- a/tests/dagger/testsales.nim +++ b/tests/dagger/testsales.nim @@ -87,3 +87,11 @@ suite "Sales": otherOffer = await market.offerStorage(otherOffer) await market.selectOffer(otherOffer.id) 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)