remove slot from waitUntilStarted signature

This commit is contained in:
Eric Mastro 2022-11-11 13:33:28 +11:00 committed by markspanbroek
parent b2de745d9a
commit 47bf5d37cf
3 changed files with 25 additions and 25 deletions

View File

@ -178,7 +178,7 @@ describe("Marketplace", function () {
}) })
it("is rejected when request is finished", async function () { it("is rejected when request is finished", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await expect( await expect(
marketplace.fillSlot(slot.request, slot.index, proof) marketplace.fillSlot(slot.request, slot.index, proof)
@ -186,7 +186,7 @@ describe("Marketplace", function () {
}) })
it("is rejected when request is failed", async function () { it("is rejected when request is failed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFailed(marketplace, request, slot) await waitUntilFailed(marketplace, request, slot)
await expect( await expect(
marketplace.fillSlot(slot.request, slot.index, proof) marketplace.fillSlot(slot.request, slot.index, proof)
@ -246,7 +246,7 @@ describe("Marketplace", function () {
}) })
it("sets proof end time to the past once failed", async function () { it("sets proof end time to the past once failed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFailed(marketplace, request, slot) await waitUntilFailed(marketplace, request, slot)
let slot0 = { ...slot, index: request.ask.maxSlotLoss + 1 } let slot0 = { ...slot, index: request.ask.maxSlotLoss + 1 }
const now = await currentTime() const now = await currentTime()
@ -261,7 +261,7 @@ describe("Marketplace", function () {
}) })
it("checks that proof end time is in the past once finished", async function () { it("checks that proof end time is in the past once finished", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
const now = await currentTime() const now = await currentTime()
// in the process of calling currentTime and proofEnd, // in the process of calling currentTime and proofEnd,
@ -306,7 +306,7 @@ describe("Marketplace", function () {
}) })
it("sets request end time to the past once failed", async function () { it("sets request end time to the past once failed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFailed(marketplace, request, slot) await waitUntilFailed(marketplace, request, slot)
let slot0 = { ...slot, index: request.ask.maxSlotLoss + 1 } let slot0 = { ...slot, index: request.ask.maxSlotLoss + 1 }
const now = await currentTime() const now = await currentTime()
@ -325,7 +325,7 @@ describe("Marketplace", function () {
}) })
it("checks that request end time is in the past once finished", async function () { it("checks that request end time is in the past once finished", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
const now = await currentTime() const now = await currentTime()
// in the process of calling currentTime and proofEnd, // in the process of calling currentTime and proofEnd,
@ -368,7 +368,7 @@ describe("Marketplace", function () {
}) })
it("fails to free slot when finished", async function () { it("fails to free slot when finished", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith( await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith(
"Slot not accepting proofs" "Slot not accepting proofs"
@ -376,19 +376,19 @@ describe("Marketplace", function () {
}) })
it("successfully frees slot", async function () { it("successfully frees slot", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await expect(marketplace.freeSlot(id)).not.to.be.reverted await expect(marketplace.freeSlot(id)).not.to.be.reverted
}) })
it("emits event once slot is freed", async function () { it("emits event once slot is freed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await expect(await marketplace.freeSlot(id)) await expect(await marketplace.freeSlot(id))
.to.emit(marketplace, "SlotFreed") .to.emit(marketplace, "SlotFreed")
.withArgs(slot.request, id) .withArgs(slot.request, id)
}) })
it("cannot get slot once freed", async function () { it("cannot get slot once freed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await marketplace.freeSlot(id) await marketplace.freeSlot(id)
await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty") await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty")
}) })
@ -405,7 +405,7 @@ describe("Marketplace", function () {
}) })
it("pays the host", async function () { it("pays the host", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
const startBalance = await token.balanceOf(host.address) const startBalance = await token.balanceOf(host.address)
await marketplace.payoutSlot(slot.request, slot.index) await marketplace.payoutSlot(slot.request, slot.index)
@ -421,7 +421,7 @@ describe("Marketplace", function () {
}) })
it("can only be done once", async function () { it("can only be done once", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.payoutSlot(slot.request, slot.index) await marketplace.payoutSlot(slot.request, slot.index)
await expect( await expect(
@ -430,7 +430,7 @@ describe("Marketplace", function () {
}) })
it("cannot be filled again", async function () { it("cannot be filled again", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.payoutSlot(slot.request, slot.index) await marketplace.payoutSlot(slot.request, slot.index)
await expect(marketplace.fillSlot(slot.request, slot.index, proof)).to.be await expect(marketplace.fillSlot(slot.request, slot.index, proof)).to.be
@ -558,14 +558,14 @@ describe("Marketplace", function () {
}) })
it("changes state to Started once all slots are filled", async function () { it("changes state to Started once all slots are filled", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.state(slot.request)).to.equal(
RequestState.Started RequestState.Started
) )
}) })
it("state is Failed once too many slots are freed", async function () { it("state is Failed once too many slots are freed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFailed(marketplace, request, slot) await waitUntilFailed(marketplace, request, slot)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.state(slot.request)).to.equal(
RequestState.Failed RequestState.Failed
@ -573,7 +573,7 @@ describe("Marketplace", function () {
}) })
it("state is Finished once slot is paid out", async function () { it("state is Finished once slot is paid out", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.payoutSlot(slot.request, slot.index) await marketplace.payoutSlot(slot.request, slot.index)
await expect(await marketplace.state(slot.request)).to.equal( await expect(await marketplace.state(slot.request)).to.equal(
@ -661,7 +661,7 @@ describe("Marketplace", function () {
}) })
it("fails when request Finished (isFinished is true)", async function () { it("fails when request Finished (isFinished is true)", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await expect( await expect(
marketplace.testAcceptsProofs(slotId(slot)) marketplace.testAcceptsProofs(slotId(slot))
@ -669,7 +669,7 @@ describe("Marketplace", function () {
}) })
it("fails when request Finished (state set to Finished)", async function () { it("fails when request Finished (state set to Finished)", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.payoutSlot(slot.request, slot.index) await marketplace.payoutSlot(slot.request, slot.index)
await expect( await expect(
@ -678,7 +678,7 @@ describe("Marketplace", function () {
}) })
it("fails when request Failed", async function () { it("fails when request Failed", async function () {
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
for (let i = 0; i <= request.ask.maxSlotLoss; i++) { for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
slot.index = i slot.index = i
let id = slotId(slot) let id = slotId(slot)
@ -715,7 +715,7 @@ describe("Marketplace", function () {
it("removes request from list when request fails", async function () { it("removes request from list when request fails", async function () {
await marketplace.requestStorage(request) await marketplace.requestStorage(request)
switchAccount(host) switchAccount(host)
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFailed(marketplace, request, slot) await waitUntilFailed(marketplace, request, slot)
switchAccount(client) switchAccount(client)
expect(await marketplace.myRequests()).to.deep.equal([]) expect(await marketplace.myRequests()).to.deep.equal([])
@ -724,7 +724,7 @@ describe("Marketplace", function () {
it("removes request from list when request finishes", async function () { it("removes request from list when request finishes", async function () {
await marketplace.requestStorage(request) await marketplace.requestStorage(request)
switchAccount(host) switchAccount(host)
await waitUntilStarted(marketplace, request, slot, proof) await waitUntilStarted(marketplace, request, proof)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.payoutSlot(slot.request, slot.index) await marketplace.payoutSlot(slot.request, slot.index)
switchAccount(client) switchAccount(client)

View File

@ -121,7 +121,7 @@ describe("Storage", function () {
it("frees slot when collateral slashed below minimum threshold", async function () { it("frees slot when collateral slashed below minimum threshold", async function () {
const id = slotId(slot) const id = slotId(slot)
await waitUntilStarted(storage, request, slot, proof) await waitUntilStarted(storage, request, proof)
// max slashes before dropping below collateral threshold // max slashes before dropping below collateral threshold
const maxSlashes = 10 const maxSlashes = 10

View File

@ -1,13 +1,13 @@
const { advanceTimeTo } = require("./evm") const { advanceTimeTo } = require("./evm")
const { slotId } = require("./ids") const { slotId, requestId } = require("./ids")
async function waitUntilCancelled(request) { async function waitUntilCancelled(request) {
await advanceTimeTo(request.expiry + 1) await advanceTimeTo(request.expiry + 1)
} }
async function waitUntilStarted(contract, request, slot, proof) { async function waitUntilStarted(contract, request, proof) {
for (let i = 0; i < request.ask.slots; i++) { for (let i = 0; i < request.ask.slots; i++) {
await contract.fillSlot(slot.request, i, proof) await contract.fillSlot(requestId(request), i, proof)
} }
} }