mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-07 16:03:13 +00:00
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:
parent
e43872d0b8
commit
ca869f6dce
@ -351,7 +351,8 @@ proc updateAvailability(
|
|||||||
|
|
||||||
if oldAvailability.freeSize < obj.freeSize or oldAvailability.duration < obj.duration or
|
if oldAvailability.freeSize < obj.freeSize or oldAvailability.duration < obj.duration or
|
||||||
oldAvailability.minPricePerBytePerSecond < obj.minPricePerBytePerSecond 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
|
# inform subscribers that Availability has been modified (with increased
|
||||||
# size)
|
# size)
|
||||||
if OnAvailabilitySaved =? self.OnAvailabilitySaved:
|
if OnAvailabilitySaved =? self.OnAvailabilitySaved:
|
||||||
|
|||||||
@ -427,22 +427,24 @@ asyncchecksuite "Reservations module":
|
|||||||
|
|
||||||
check not called
|
check not called
|
||||||
|
|
||||||
test "OnAvailabilitySaved called when availability totalCollateral is increased":
|
test "OnAvailabilitySaved called when availability totalRemainingCollateral is increased":
|
||||||
var availability = createAvailability()
|
var availability = createAvailability()
|
||||||
var added: Availability
|
var added: Availability
|
||||||
reservations.OnAvailabilitySaved = proc(a: Availability) {.async: (raises: []).} =
|
reservations.OnAvailabilitySaved = proc(a: Availability) {.async: (raises: []).} =
|
||||||
added = a
|
added = a
|
||||||
availability.totalCollateral = availability.totalCollateral + 1.u256
|
availability.totalRemainingCollateral =
|
||||||
|
availability.totalRemainingCollateral + 1.u256
|
||||||
discard await reservations.update(availability)
|
discard await reservations.update(availability)
|
||||||
|
|
||||||
check added == 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 availability = createAvailability()
|
||||||
var called = false
|
var called = false
|
||||||
reservations.OnAvailabilitySaved = proc(a: Availability) {.async: (raises: []).} =
|
reservations.OnAvailabilitySaved = proc(a: Availability) {.async: (raises: []).} =
|
||||||
called = true
|
called = true
|
||||||
availability.totalCollateral = availability.totalCollateral - 1.u256
|
availability.totalRemainingCollateral =
|
||||||
|
availability.totalRemainingCollateral - 1.u256
|
||||||
discard await reservations.update(availability)
|
discard await reservations.update(availability)
|
||||||
|
|
||||||
check not called
|
check not called
|
||||||
|
|||||||
@ -575,7 +575,7 @@ ethersuite "On-Chain Market":
|
|||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
await market.reserveSlot(request.id, 0.uint64)
|
await market.reserveSlot(request.id, 0.uint64)
|
||||||
await market.fillSlot(request.id, 0.uint64, proof, request.ask.collateralPerSlot)
|
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:
|
for slotIndex in 1 ..< request.ask.slots:
|
||||||
await market.reserveSlot(request.id, slotIndex.uint64)
|
await market.reserveSlot(request.id, slotIndex.uint64)
|
||||||
|
|||||||
@ -290,9 +290,7 @@ marketplacesuite "Marketplace payouts":
|
|||||||
await ethProvider.advanceTime(expiry.u256)
|
await ethProvider.advanceTime(expiry.u256)
|
||||||
|
|
||||||
check eventually(
|
check eventually(
|
||||||
await providerApi.saleStateIs(slotId, "SaleCancelled"),
|
await providerApi.saleStateIs(slotId, "SaleCancelled"), pollInterval = 100
|
||||||
timeout = 5 * 1000,
|
|
||||||
pollInterval = 200,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await advanceToNextPeriod()
|
await advanceToNextPeriod()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user