[marketplace] rewrite slot freeing test

To make it independent of values chosen in exampleRequest().
Uses the recently introduced slotState().
This commit is contained in:
Mark Spanbroek 2023-01-18 15:35:01 +01:00 committed by markspanbroek
parent b62eeb564a
commit 019c1c34c0
1 changed files with 12 additions and 24 deletions

View File

@ -763,30 +763,18 @@ describe("Marketplace", function () {
}) })
}) })
describe("freeing a slot", function () { it("frees slot when collateral slashed below minimum threshold", async function () {
it("frees slot when collateral slashed below minimum threshold", async function () { const minimum = config.collateral.minimumAmount
const id = slotId(slot) await waitUntilStarted(marketplace, request, proof)
while ((await marketplace.slotState(slotId(slot))) === SlotState.Filled) {
await waitUntilStarted(marketplace, request, proof) expect(await marketplace.balanceOf(host.address)).to.be.gt(minimum)
await waitUntilProofIsRequired(slotId(slot))
const maxSlashes = 10 // slashes before going below collateral minimum const missedPeriod = periodOf(await currentTime())
const slashMisses = config.collateral.slashCriterion await advanceTime(period)
for (let i = 0; i < maxSlashes; i++) { await marketplace.markProofAsMissing(slotId(slot), missedPeriod)
for (let j = 0; j < slashMisses; j++) { }
await waitUntilProofIsRequired(id) expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free)
let missedPeriod = periodOf(await currentTime()) expect(await marketplace.balanceOf(host.address)).to.be.lte(minimum)
await advanceTime(period)
if (i === maxSlashes - 1 && j === slashMisses - 1) {
await expect(
await marketplace.markProofAsMissing(id, missedPeriod)
).to.emit(marketplace, "SlotFreed")
expect(await marketplace.getHost(id)).to.equal(AddressZero)
} else {
await marketplace.markProofAsMissing(id, missedPeriod)
}
}
}
})
}) })
}) })