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
This commit is contained in:
Arnaud 2025-06-02 18:47:12 +02:00 committed by GitHub
parent e43872d0b8
commit ca869f6dce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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