@@ -6,6 +6,7 @@ import ../contracts/deployment
66import ./ marketplacesuite
77import ./ twonodes
88import ./ nodeconfigs
9+ import ../ helpers
910
1011marketplacesuite " Marketplace" :
1112 let marketplaceConfig = NodeConfigs (
@@ -240,8 +241,8 @@ marketplacesuite "Marketplace payouts":
240241 # )
241242 .some,
242243 ):
243- let duration = 20 .periods
244- let expiry = 10 .periods
244+ let duration = 6 .periods
245+ let expiry = 4 .periods
245246 let data = await RandomChunker .example (blocks = blocks)
246247 let client = clients ()[0 ]
247248 let provider = providers ()[0 ]
@@ -251,15 +252,14 @@ marketplacesuite "Marketplace payouts":
251252 let startBalanceClient = await token.balanceOf (client.ethAccount)
252253
253254 # provider makes storage available
254- let datasetSize = datasetSize (blocks, ecNodes, ecTolerance)
255- let totalAvailabilitySize = (datasetSize div 2 ).truncate (uint64 )
255+ let slotSize = slotSize (blocks, ecNodes, ecTolerance)
256256 discard await providerApi.postAvailability (
257257 # make availability size small enough that we can't fill all the slots,
258258 # thus causing a cancellation
259- totalSize = totalAvailabilitySize ,
259+ totalSize = slotSize. truncate ( uint64 ) ,
260260 duration = duration.uint64 ,
261261 minPricePerBytePerSecond = minPricePerBytePerSecond,
262- totalCollateral = collateralPerByte * totalAvailabilitySize.u256 ,
262+ totalCollateral = collateralPerByte * slotSize ,
263263 )
264264
265265 let cid = (await clientApi.upload (data)).get
@@ -269,7 +269,14 @@ marketplacesuite "Marketplace payouts":
269269 assert not eventResult.isErr
270270 slotIdxFilled = some (! eventResult).slotIndex
271271
272- let subscription = await marketplace.subscribe (SlotFilled , onSlotFilled)
272+ var requestCancelledFut = Future [void ].Raising ([CancelledError ]).init ()
273+ proc onRequestCancelled (eventResult: ?! RequestCancelled ) {.raises : [].} =
274+ trace " cancelling request" , eventResult
275+ requestCancelledFut.complete ()
276+
277+ let cancelledSubscription = await marketplace.subscribe (RequestCancelled , onRequestCancelled)
278+ let filledSubscription = await marketplace.subscribe (SlotFilled , onSlotFilled)
279+
273280
274281 # client requests storage but requires multiple slots to host the content
275282 let id = await clientApi.requestStorage (
@@ -289,13 +296,10 @@ marketplacesuite "Marketplace payouts":
289296 # wait until sale is cancelled
290297 await ethProvider.advanceTime (expiry.u256)
291298
292- check eventually (
293- await providerApi.saleStateIs (slotId, " SaleCancelled" ), pollInterval = 100
294- )
299+ await requestCancelledFut.wait (timeout = (expiry.uint32 + 1 'u32 ).seconds)
295300
296301 await advanceToNextPeriod ()
297302
298- let slotSize = slotSize (blocks, ecNodes, ecTolerance)
299303 let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
300304
301305 check eventually (
@@ -313,7 +317,9 @@ marketplacesuite "Marketplace payouts":
313317 timeout = 10 * 1000 , # give client a bit of time to withdraw its funds
314318 )
315319
316- await subscription.unsubscribe ()
320+ await allFuturesThrowing (
321+ filledSubscription.unsubscribe (),
322+ cancelledSubscription.unsubscribe ())
317323
318324 test " the collateral is returned after a sale is ignored" ,
319325 NodeConfigs (
0 commit comments