From ca869f6dce4b6718863bb608053f7a8d659c8763 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 2 Jun 2025 18:47:12 +0200 Subject: [PATCH] fix(availabilities): use totalRemainingCollateral instead of totalCollateral for comparaison (#1229) * Use totalRemainingCollateral instead of totalCollateral to compare the availability changes * Update test to use totalRemainingCollateral instead of totalCollateral when testing OnAvailabilitySaved * Reduce poll interval * Fix flaky test * Fix format --- codex/sales/reservations.nim | 3 ++- tests/codex/sales/testreservations.nim | 10 ++++++---- tests/contracts/testMarket.nim | 2 +- tests/integration/testmarketplace.nim | 4 +--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/codex/sales/reservations.nim b/codex/sales/reservations.nim index b9facd2e..f27a66fe 100644 --- a/codex/sales/reservations.nim +++ b/codex/sales/reservations.nim @@ -351,7 +351,8 @@ proc updateAvailability( if oldAvailability.freeSize < obj.freeSize or oldAvailability.duration < obj.duration or oldAvailability.minPricePerBytePerSecond < obj.minPricePerBytePerSecond or - oldAvailability.totalCollateral < obj.totalCollateral: # availability updated + oldAvailability.totalRemainingCollateral < obj.totalRemainingCollateral: + # availability updated # inform subscribers that Availability has been modified (with increased # size) if OnAvailabilitySaved =? self.OnAvailabilitySaved: diff --git a/tests/codex/sales/testreservations.nim b/tests/codex/sales/testreservations.nim index ff5e153c..48bdee9c 100644 --- a/tests/codex/sales/testreservations.nim +++ b/tests/codex/sales/testreservations.nim @@ -427,22 +427,24 @@ asyncchecksuite "Reservations module": check not called - test "OnAvailabilitySaved called when availability totalCollateral is increased": + test "OnAvailabilitySaved called when availability totalRemainingCollateral is increased": var availability = createAvailability() var added: Availability reservations.OnAvailabilitySaved = proc(a: Availability) {.async: (raises: []).} = added = a - availability.totalCollateral = availability.totalCollateral + 1.u256 + availability.totalRemainingCollateral = + availability.totalRemainingCollateral + 1.u256 discard await reservations.update(availability) check added == availability - test "OnAvailabilitySaved is not called when availability totalCollateral is decreased": + test "OnAvailabilitySaved is not called when availability totalRemainingCollateral is decreased": var availability = createAvailability() var called = false reservations.OnAvailabilitySaved = proc(a: Availability) {.async: (raises: []).} = called = true - availability.totalCollateral = availability.totalCollateral - 1.u256 + availability.totalRemainingCollateral = + availability.totalRemainingCollateral - 1.u256 discard await reservations.update(availability) check not called diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index 0717e8fe..6d47ab9a 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -575,7 +575,7 @@ ethersuite "On-Chain Market": switchAccount(host) await market.reserveSlot(request.id, 0.uint64) await market.fillSlot(request.id, 0.uint64, proof, request.ask.collateralPerSlot) - let filledAt = (await ethProvider.currentTime()) + let filledAt = await ethProvider.blockTime(BlockTag.latest) for slotIndex in 1 ..< request.ask.slots: await market.reserveSlot(request.id, slotIndex.uint64) diff --git a/tests/integration/testmarketplace.nim b/tests/integration/testmarketplace.nim index 9b16f121..d66e7613 100644 --- a/tests/integration/testmarketplace.nim +++ b/tests/integration/testmarketplace.nim @@ -290,9 +290,7 @@ marketplacesuite "Marketplace payouts": await ethProvider.advanceTime(expiry.u256) check eventually( - await providerApi.saleStateIs(slotId, "SaleCancelled"), - timeout = 5 * 1000, - pollInterval = 200, + await providerApi.saleStateIs(slotId, "SaleCancelled"), pollInterval = 100 ) await advanceToNextPeriod()