[marketplace] address PR comments
- reordered some tests - add RequestState export - change test descriptions to start with “it”
This commit is contained in:
parent
7726db2a8d
commit
9050a0d52d
|
@ -103,68 +103,6 @@ describe("Marketplace", function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe("freeing a slot", function () {
|
||||
var id
|
||||
beforeEach(async function () {
|
||||
slot.index = 0
|
||||
id = slotId(slot)
|
||||
|
||||
switchAccount(client)
|
||||
await token.approve(marketplace.address, price(request))
|
||||
await marketplace.requestStorage(request)
|
||||
switchAccount(host)
|
||||
await token.approve(marketplace.address, collateral)
|
||||
await marketplace.deposit(collateral)
|
||||
|
||||
// await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
})
|
||||
|
||||
it("fails to free slot when slot not filled", async function () {
|
||||
slot.index = 5
|
||||
let nonExistentId = slotId(slot)
|
||||
await expect(marketplace.freeSlot(nonExistentId)).to.be.revertedWith(
|
||||
"Slot empty"
|
||||
)
|
||||
})
|
||||
|
||||
it("fails to free slot when not started", async function () {
|
||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
await expect(marketplace.freeSlot(id)).to.be.revertedWith("Invalid state")
|
||||
})
|
||||
|
||||
it("successfully frees slot", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
slot.request,
|
||||
proof
|
||||
)
|
||||
await expect(marketplace.freeSlot(id)).not.to.be.reverted
|
||||
})
|
||||
|
||||
it("emits event once slot is freed", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
slot.request,
|
||||
proof
|
||||
)
|
||||
await expect(await marketplace.freeSlot(id))
|
||||
.to.emit(marketplace, "SlotFreed")
|
||||
.withArgs(slot.request, id)
|
||||
})
|
||||
|
||||
it("cannot get slot once freed", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
slot.request,
|
||||
proof
|
||||
)
|
||||
await marketplace.freeSlot(id)
|
||||
await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty")
|
||||
})
|
||||
})
|
||||
|
||||
describe("filling a slot", function () {
|
||||
beforeEach(async function () {
|
||||
|
@ -252,6 +190,67 @@ describe("Marketplace", function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe("freeing a slot", function () {
|
||||
var id
|
||||
beforeEach(async function () {
|
||||
slot.index = 0
|
||||
id = slotId(slot)
|
||||
|
||||
switchAccount(client)
|
||||
await token.approve(marketplace.address, price(request))
|
||||
await marketplace.requestStorage(request)
|
||||
switchAccount(host)
|
||||
await token.approve(marketplace.address, collateral)
|
||||
await marketplace.deposit(collateral)
|
||||
})
|
||||
|
||||
it("fails to free slot when slot not filled", async function () {
|
||||
slot.index = 5
|
||||
let nonExistentId = slotId(slot)
|
||||
await expect(marketplace.freeSlot(nonExistentId)).to.be.revertedWith(
|
||||
"Slot empty"
|
||||
)
|
||||
})
|
||||
|
||||
it("fails to free slot when not started", async function () {
|
||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||
await expect(marketplace.freeSlot(id)).to.be.revertedWith("Invalid state")
|
||||
})
|
||||
|
||||
it("successfully frees slot", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
slot.request,
|
||||
proof
|
||||
)
|
||||
await expect(marketplace.freeSlot(id)).not.to.be.reverted
|
||||
})
|
||||
|
||||
it("emits event once slot is freed", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
slot.request,
|
||||
proof
|
||||
)
|
||||
await expect(await marketplace.freeSlot(id))
|
||||
.to.emit(marketplace, "SlotFreed")
|
||||
.withArgs(slot.request, id)
|
||||
})
|
||||
|
||||
it("cannot get slot once freed", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
slot.request,
|
||||
proof
|
||||
)
|
||||
await marketplace.freeSlot(id)
|
||||
await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty")
|
||||
})
|
||||
})
|
||||
|
||||
describe("paying out a slot", function () {
|
||||
beforeEach(async function () {
|
||||
switchAccount(client)
|
||||
|
@ -429,7 +428,7 @@ describe("Marketplace", function () {
|
|||
)
|
||||
})
|
||||
|
||||
it("state is Failed once too many slots are freed", async function () {
|
||||
it("changes state to Failed once too many slots are freed", async function () {
|
||||
await waitUntilAllSlotsFilled(
|
||||
marketplace,
|
||||
request.ask.slots,
|
||||
|
|
|
@ -139,9 +139,7 @@ describe("Proofs", function () {
|
|||
expect(await proofs.isProofRequired(id)).to.be.true
|
||||
})
|
||||
|
||||
it("proofs won't be required when no longer expected", async function () {
|
||||
expect(await proofs.getPointer(id)).to.be.lt(downtime)
|
||||
expect(await proofs.willProofBeRequired(id)).to.be.true
|
||||
it("will not require proofs when no longer expected", async function () {
|
||||
await proofs.unexpectProofs(id)
|
||||
expect(await proofs.willProofBeRequired(id)).to.be.false
|
||||
})
|
||||
|
|
|
@ -17,4 +17,4 @@ async function waitUntilAllSlotsFilled(contract, numSlots, requestId, proof) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { waitUntilExpired, waitUntilAllSlotsFilled }
|
||||
module.exports = { waitUntilExpired, waitUntilAllSlotsFilled, RequestState }
|
||||
|
|
Loading…
Reference in New Issue