2022-02-16 09:50:00 +00:00
|
|
|
const { ethers } = require("hardhat")
|
2022-06-13 08:40:18 +00:00
|
|
|
const { hexlify, randomBytes } = ethers.utils
|
2022-02-16 09:50:00 +00:00
|
|
|
const { expect } = require("chai")
|
2022-06-13 10:17:37 +00:00
|
|
|
const { exampleRequest } = require("./examples")
|
2022-09-22 02:21:49 +00:00
|
|
|
const { hours, minutes } = require("./time")
|
2022-07-19 09:33:54 +00:00
|
|
|
const { requestId, slotId, askToArray } = require("./ids")
|
2022-09-22 02:21:49 +00:00
|
|
|
const {
|
2022-09-21 09:57:26 +00:00
|
|
|
waitUntilCancelled,
|
|
|
|
waitUntilStarted,
|
|
|
|
waitUntilFinished,
|
|
|
|
waitUntilFailed,
|
2022-10-25 02:04:16 +00:00
|
|
|
RequestState,
|
2022-09-21 09:57:26 +00:00
|
|
|
} = require("./marketplace")
|
2022-07-20 09:07:20 +00:00
|
|
|
const { price, pricePerSlot } = require("./price")
|
2022-07-19 15:09:35 +00:00
|
|
|
const {
|
|
|
|
snapshot,
|
|
|
|
revert,
|
|
|
|
ensureMinimumBlockHeight,
|
2022-09-21 09:57:26 +00:00
|
|
|
advanceTime,
|
2022-09-22 02:21:49 +00:00
|
|
|
currentTime,
|
2022-07-19 15:09:35 +00:00
|
|
|
} = require("./evm")
|
2022-02-16 09:50:00 +00:00
|
|
|
|
|
|
|
describe("Marketplace", function () {
|
2022-02-16 13:38:19 +00:00
|
|
|
const collateral = 100
|
2022-06-13 08:40:18 +00:00
|
|
|
const proofPeriod = 30 * 60
|
|
|
|
const proofTimeout = 5
|
|
|
|
const proofDowntime = 64
|
2022-07-19 15:09:35 +00:00
|
|
|
const proof = hexlify(randomBytes(42))
|
2022-02-16 09:50:00 +00:00
|
|
|
|
|
|
|
let marketplace
|
|
|
|
let token
|
2022-02-21 10:31:37 +00:00
|
|
|
let client, host, host1, host2, host3
|
2022-06-13 10:17:37 +00:00
|
|
|
let request
|
2022-07-19 15:09:35 +00:00
|
|
|
let slot
|
2022-02-16 09:50:00 +00:00
|
|
|
|
|
|
|
beforeEach(async function () {
|
2022-06-13 08:40:18 +00:00
|
|
|
await snapshot()
|
|
|
|
await ensureMinimumBlockHeight(256)
|
2022-02-21 10:31:37 +00:00
|
|
|
;[client, host1, host2, host3] = await ethers.getSigners()
|
|
|
|
host = host1
|
2022-02-17 10:00:18 +00:00
|
|
|
|
2022-02-16 09:50:00 +00:00
|
|
|
const TestToken = await ethers.getContractFactory("TestToken")
|
|
|
|
token = await TestToken.deploy()
|
2022-02-21 10:31:37 +00:00
|
|
|
for (account of [client, host1, host2, host3]) {
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.mint(account.address, 1_000_000_000)
|
2022-02-21 10:31:37 +00:00
|
|
|
}
|
2022-02-17 10:00:18 +00:00
|
|
|
|
2022-09-08 07:56:01 +00:00
|
|
|
const Marketplace = await ethers.getContractFactory("TestMarketplace")
|
2022-06-13 08:40:18 +00:00
|
|
|
marketplace = await Marketplace.deploy(
|
|
|
|
token.address,
|
|
|
|
collateral,
|
|
|
|
proofPeriod,
|
|
|
|
proofTimeout,
|
|
|
|
proofDowntime
|
|
|
|
)
|
2022-02-17 10:00:18 +00:00
|
|
|
|
2022-09-22 02:21:49 +00:00
|
|
|
request = await exampleRequest()
|
2022-02-17 10:00:18 +00:00
|
|
|
request.client = client.address
|
2022-07-19 15:09:35 +00:00
|
|
|
|
|
|
|
slot = {
|
|
|
|
request: requestId(request),
|
2022-07-20 08:44:22 +00:00
|
|
|
index: request.ask.slots / 2,
|
2022-07-19 15:09:35 +00:00
|
|
|
}
|
2022-02-16 09:50:00 +00:00
|
|
|
})
|
|
|
|
|
2022-06-13 08:40:18 +00:00
|
|
|
afterEach(async function () {
|
|
|
|
await revert()
|
|
|
|
})
|
|
|
|
|
2022-02-17 10:00:18 +00:00
|
|
|
function switchAccount(account) {
|
|
|
|
token = token.connect(account)
|
|
|
|
marketplace = marketplace.connect(account)
|
|
|
|
}
|
|
|
|
|
2022-02-16 09:50:00 +00:00
|
|
|
describe("requesting storage", function () {
|
2022-02-17 10:00:18 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
switchAccount(client)
|
|
|
|
})
|
|
|
|
|
2022-02-16 09:50:00 +00:00
|
|
|
it("emits event when storage is requested", async function () {
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(request))
|
2022-02-16 09:50:00 +00:00
|
|
|
await expect(marketplace.requestStorage(request))
|
|
|
|
.to.emit(marketplace, "StorageRequested")
|
2022-04-06 12:26:56 +00:00
|
|
|
.withArgs(requestId(request), askToArray(request.ask))
|
2022-02-16 09:50:00 +00:00
|
|
|
})
|
|
|
|
|
2022-02-17 10:00:18 +00:00
|
|
|
it("rejects request with invalid client address", async function () {
|
|
|
|
let invalid = { ...request, client: host.address }
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(invalid))
|
2022-02-17 10:00:18 +00:00
|
|
|
await expect(marketplace.requestStorage(invalid)).to.be.revertedWith(
|
|
|
|
"Invalid client address"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-02-16 09:50:00 +00:00
|
|
|
it("rejects request with insufficient payment", async function () {
|
2022-07-20 09:07:20 +00:00
|
|
|
let insufficient = price(request) - 1
|
2022-02-16 09:50:00 +00:00
|
|
|
await token.approve(marketplace.address, insufficient)
|
|
|
|
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
2022-03-15 15:18:44 +00:00
|
|
|
"ERC20: insufficient allowance"
|
2022-02-16 09:50:00 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("rejects resubmission of request", async function () {
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(request) * 2)
|
2022-02-16 09:50:00 +00:00
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
|
|
|
"Request already exists"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2022-02-16 13:38:19 +00:00
|
|
|
|
2022-07-19 09:33:54 +00:00
|
|
|
describe("filling a slot", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
switchAccount(client)
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(request))
|
2022-07-19 09:33:54 +00:00
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
switchAccount(host)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("emits event when slot is filled", async function () {
|
|
|
|
await expect(marketplace.fillSlot(slot.request, slot.index, proof))
|
|
|
|
.to.emit(marketplace, "SlotFilled")
|
|
|
|
.withArgs(slot.request, slot.index, slotId(slot))
|
|
|
|
})
|
|
|
|
|
|
|
|
it("locks collateral of host", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await expect(marketplace.withdraw()).to.be.revertedWith("Account locked")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("starts requiring storage proofs", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
expect(await marketplace.proofEnd(slotId(slot))).to.be.gt(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("is rejected when proof is incorrect", async function () {
|
|
|
|
let invalid = hexlify([])
|
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, slot.index, invalid)
|
|
|
|
).to.be.revertedWith("Invalid proof")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("is rejected when collateral is insufficient", async function () {
|
|
|
|
let insufficient = collateral - 1
|
|
|
|
await marketplace.withdraw()
|
|
|
|
await token.approve(marketplace.address, insufficient)
|
|
|
|
await marketplace.deposit(insufficient)
|
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
).to.be.revertedWith("Insufficient collateral")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("is rejected when slot already filled", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
).to.be.revertedWith("Slot already filled")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("is rejected when request is unknown", async function () {
|
2022-09-22 02:21:49 +00:00
|
|
|
let unknown = await exampleRequest()
|
2022-07-19 09:33:54 +00:00
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(requestId(unknown), 0, proof)
|
|
|
|
).to.be.revertedWith("Unknown request")
|
|
|
|
})
|
|
|
|
|
2022-09-21 09:13:12 +00:00
|
|
|
it("is rejected when request is cancelled", async function () {
|
2022-07-19 09:33:54 +00:00
|
|
|
switchAccount(client)
|
2022-09-22 02:21:49 +00:00
|
|
|
let expired = { ...request, expiry: (await currentTime()) - hours(1) }
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(request))
|
2022-07-19 09:33:54 +00:00
|
|
|
await marketplace.requestStorage(expired)
|
|
|
|
switchAccount(host)
|
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(requestId(expired), slot.index, proof)
|
2022-09-21 09:13:12 +00:00
|
|
|
).to.be.revertedWith("Request not accepting proofs")
|
2022-07-19 09:33:54 +00:00
|
|
|
})
|
|
|
|
|
2022-09-21 09:57:26 +00:00
|
|
|
it("is rejected when request is finished", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-09-21 09:57:26 +00:00
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, slot.index, proof)
|
2022-09-22 02:21:49 +00:00
|
|
|
).to.be.revertedWith("Request not accepting proofs")
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("is rejected when request is failed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
2022-09-21 09:57:26 +00:00
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, slot.index, proof)
|
2022-09-22 02:21:49 +00:00
|
|
|
).to.be.revertedWith("Request not accepting proofs")
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
2022-07-19 09:33:54 +00:00
|
|
|
it("is rejected when slot index not in range", async function () {
|
2022-07-20 08:44:22 +00:00
|
|
|
const invalid = request.ask.slots
|
2022-07-19 09:33:54 +00:00
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, invalid, proof)
|
|
|
|
).to.be.revertedWith("Invalid slot")
|
|
|
|
})
|
2022-09-07 05:25:01 +00:00
|
|
|
|
|
|
|
it("fails when all slots are already filled", async function () {
|
|
|
|
const lastSlot = request.ask.slots - 1
|
|
|
|
for (let i = 0; i <= lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, lastSlot, proof)
|
2022-09-21 09:13:12 +00:00
|
|
|
).to.be.revertedWith("Slot already filled")
|
2022-09-07 05:25:01 +00:00
|
|
|
})
|
2022-09-23 02:33:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("proof end", function () {
|
2022-09-29 10:07:55 +00:00
|
|
|
var requestTime
|
2022-09-23 02:33:39 +00:00
|
|
|
beforeEach(async function () {
|
|
|
|
switchAccount(client)
|
|
|
|
await token.approve(marketplace.address, price(request))
|
|
|
|
await marketplace.requestStorage(request)
|
2022-09-29 10:07:55 +00:00
|
|
|
requestTime = await currentTime()
|
2022-09-23 02:33:39 +00:00
|
|
|
switchAccount(host)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
})
|
|
|
|
|
2022-09-21 09:57:26 +00:00
|
|
|
it("shares proof end time for all slots in request", async function () {
|
|
|
|
const lastSlot = request.ask.slots - 1
|
|
|
|
for (let i = 0; i < lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
|
|
|
advanceTime(minutes(10))
|
|
|
|
await marketplace.fillSlot(slot.request, lastSlot, proof)
|
|
|
|
let slot0 = { ...slot, index: 0 }
|
|
|
|
let end = await marketplace.proofEnd(slotId(slot0))
|
|
|
|
for (let i = 1; i <= lastSlot; i++) {
|
|
|
|
let sloti = { ...slot, index: i }
|
|
|
|
await expect((await marketplace.proofEnd(slotId(sloti))) === end)
|
|
|
|
}
|
|
|
|
})
|
2022-09-23 02:33:39 +00:00
|
|
|
|
2022-09-29 10:07:55 +00:00
|
|
|
it("sets the proof end time to now + duration", async function () {
|
2022-09-23 02:33:39 +00:00
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
2022-09-29 10:07:55 +00:00
|
|
|
await expect(
|
|
|
|
(await marketplace.proofEnd(slotId(slot))).toNumber()
|
|
|
|
).to.be.closeTo(requestTime + request.ask.duration, 1)
|
2022-09-23 02:33:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("sets proof end time to the past once failed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
|
|
|
let slot0 = { ...slot, index: request.ask.maxSlotLoss + 1 }
|
|
|
|
const now = await currentTime()
|
|
|
|
await expect(await marketplace.proofEnd(slotId(slot0))).to.be.eq(now - 1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("sets proof end time to the past once cancelled", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await waitUntilCancelled(request)
|
|
|
|
const now = await currentTime()
|
|
|
|
await expect(await marketplace.proofEnd(slotId(slot))).to.be.eq(now - 1)
|
|
|
|
})
|
|
|
|
|
2022-09-29 10:07:55 +00:00
|
|
|
it("checks that proof end time is in the past once finished", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-09-23 02:33:39 +00:00
|
|
|
const now = await currentTime()
|
2022-09-29 10:07:55 +00:00
|
|
|
// in the process of calling currentTime and proofEnd,
|
2022-09-23 02:33:39 +00:00
|
|
|
// block.timestamp has advanced by 1, so the expected proof end time will
|
2022-09-29 10:07:55 +00:00
|
|
|
// be block.timestamp - 1.
|
|
|
|
await expect(await marketplace.proofEnd(slotId(slot))).to.be.eq(now - 1)
|
2022-09-23 02:33:39 +00:00
|
|
|
})
|
2022-07-19 09:33:54 +00:00
|
|
|
})
|
|
|
|
|
2022-10-26 02:15:42 +00:00
|
|
|
describe("request end", function () {
|
|
|
|
var requestTime
|
|
|
|
beforeEach(async function () {
|
|
|
|
switchAccount(client)
|
|
|
|
await token.approve(marketplace.address, price(request))
|
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
requestTime = await currentTime()
|
|
|
|
switchAccount(host)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("shares request end time for all slots in request", async function () {
|
|
|
|
const lastSlot = request.ask.slots - 1
|
|
|
|
for (let i = 0; i < lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
|
|
|
advanceTime(minutes(10))
|
|
|
|
await marketplace.fillSlot(slot.request, lastSlot, proof)
|
|
|
|
let slot0 = { ...slot, index: 0 }
|
|
|
|
let end = await marketplace.requestEnd(requestId(request))
|
|
|
|
for (let i = 1; i <= lastSlot; i++) {
|
|
|
|
let sloti = { ...slot, index: i }
|
|
|
|
await expect((await marketplace.proofEnd(slotId(sloti))) === end)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it("sets the request end time to now + duration", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await expect(
|
|
|
|
(await marketplace.requestEnd(requestId(request))).toNumber()
|
|
|
|
).to.be.closeTo(requestTime + request.ask.duration, 1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("sets request end time to the past once failed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-26 02:15:42 +00:00
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
|
|
|
let slot0 = { ...slot, index: request.ask.maxSlotLoss + 1 }
|
|
|
|
const now = await currentTime()
|
|
|
|
await expect(await marketplace.requestEnd(requestId(request))).to.be.eq(
|
|
|
|
now - 1
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("sets request end time to the past once cancelled", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await waitUntilCancelled(request)
|
|
|
|
const now = await currentTime()
|
|
|
|
await expect(await marketplace.requestEnd(requestId(request))).to.be.eq(
|
|
|
|
now - 1
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("checks that request end time is in the past once finished", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-26 02:15:42 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
|
|
|
const now = await currentTime()
|
|
|
|
// in the process of calling currentTime and proofEnd,
|
|
|
|
// block.timestamp has advanced by 1, so the expected proof end time will
|
|
|
|
// be block.timestamp - 1.
|
|
|
|
await expect(await marketplace.requestEnd(requestId(request))).to.be.eq(
|
|
|
|
now - 1
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-09-13 07:32:02 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-09-23 02:33:39 +00:00
|
|
|
it("fails to free slot when cancelled", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await waitUntilCancelled(request)
|
|
|
|
await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith(
|
|
|
|
"Slot not accepting proofs"
|
2022-09-22 02:21:49 +00:00
|
|
|
)
|
2022-09-23 02:33:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("fails to free slot when finished", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-09-23 02:33:39 +00:00
|
|
|
await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith(
|
2022-09-22 02:21:49 +00:00
|
|
|
"Slot not accepting proofs"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-09-13 07:32:02 +00:00
|
|
|
it("successfully frees slot", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-13 07:32:02 +00:00
|
|
|
await expect(marketplace.freeSlot(id)).not.to.be.reverted
|
|
|
|
})
|
|
|
|
|
|
|
|
it("emits event once slot is freed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-13 07:32:02 +00:00
|
|
|
await expect(await marketplace.freeSlot(id))
|
|
|
|
.to.emit(marketplace, "SlotFreed")
|
|
|
|
.withArgs(slot.request, id)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("cannot get slot once freed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-13 07:32:02 +00:00
|
|
|
await marketplace.freeSlot(id)
|
|
|
|
await expect(marketplace.slot(id)).to.be.revertedWith("Slot empty")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-19 15:09:35 +00:00
|
|
|
describe("paying out a slot", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
switchAccount(client)
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(request))
|
2022-07-19 15:09:35 +00:00
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
switchAccount(host)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("pays the host", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-07-19 15:09:35 +00:00
|
|
|
const startBalance = await token.balanceOf(host.address)
|
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
const endBalance = await token.balanceOf(host.address)
|
2022-07-20 09:07:20 +00:00
|
|
|
expect(endBalance - startBalance).to.equal(pricePerSlot(request))
|
2022-07-19 15:09:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("is only allowed when the contract has ended", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await expect(
|
|
|
|
marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
).to.be.revertedWith("Contract not ended")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("can only be done once", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-07-19 15:09:35 +00:00
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
await expect(
|
|
|
|
marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
).to.be.revertedWith("Already paid")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("cannot be filled again", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-07-19 15:09:35 +00:00
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
await expect(marketplace.fillSlot(slot.request, slot.index, proof)).to.be
|
|
|
|
.reverted
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-20 08:29:24 +00:00
|
|
|
describe("fulfilling a request", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
switchAccount(client)
|
2022-07-20 09:07:20 +00:00
|
|
|
await token.approve(marketplace.address, price(request))
|
2022-07-20 08:29:24 +00:00
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
switchAccount(host)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("emits event when all slots are filled", async function () {
|
2022-07-20 08:44:22 +00:00
|
|
|
const lastSlot = request.ask.slots - 1
|
2022-07-20 08:29:24 +00:00
|
|
|
for (let i = 0; i < lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
|
|
|
await expect(marketplace.fillSlot(slot.request, lastSlot, proof))
|
|
|
|
.to.emit(marketplace, "RequestFulfilled")
|
|
|
|
.withArgs(requestId(request))
|
|
|
|
})
|
2022-08-03 09:54:29 +00:00
|
|
|
it("sets state when all slots are filled", async function () {
|
|
|
|
const lastSlot = request.ask.slots - 1
|
|
|
|
for (let i = 0; i <= lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
2022-09-07 05:25:01 +00:00
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
2022-09-22 02:21:49 +00:00
|
|
|
RequestState.Started
|
|
|
|
)
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
it("fails when all slots are already filled", async function () {
|
|
|
|
const lastSlot = request.ask.slots - 1
|
|
|
|
for (let i = 0; i <= lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
|
|
|
await expect(
|
|
|
|
marketplace.fillSlot(slot.request, lastSlot, proof)
|
|
|
|
).to.be.revertedWith("Slot already filled")
|
2022-08-04 02:14:36 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("withdrawing funds", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
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("rejects withdraw when request not yet timed out", async function () {
|
|
|
|
switchAccount(client)
|
|
|
|
await expect(marketplace.withdrawFunds(slot.request)).to.be.revertedWith(
|
|
|
|
"Request not yet timed out"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("rejects withdraw when wrong account used", async function () {
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-08-04 02:14:36 +00:00
|
|
|
await expect(marketplace.withdrawFunds(slot.request)).to.be.revertedWith(
|
|
|
|
"Invalid client address"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("rejects withdraw when in wrong state", async function () {
|
|
|
|
// fill all slots, should change state to RequestState.Started
|
|
|
|
const lastSlot = request.ask.slots - 1
|
|
|
|
for (let i = 0; i <= lastSlot; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-08-04 02:14:36 +00:00
|
|
|
switchAccount(client)
|
|
|
|
await expect(marketplace.withdrawFunds(slot.request)).to.be.revertedWith(
|
|
|
|
"Invalid state"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("emits event once request is cancelled", async function () {
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-08-04 02:14:36 +00:00
|
|
|
switchAccount(client)
|
|
|
|
await expect(marketplace.withdrawFunds(slot.request))
|
|
|
|
.to.emit(marketplace, "RequestCancelled")
|
|
|
|
.withArgs(requestId(request))
|
|
|
|
})
|
|
|
|
|
|
|
|
it("withdraws to the client", async function () {
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-08-04 02:14:36 +00:00
|
|
|
switchAccount(client)
|
|
|
|
const startBalance = await token.balanceOf(client.address)
|
|
|
|
await marketplace.withdrawFunds(slot.request)
|
|
|
|
const endBalance = await token.balanceOf(client.address)
|
|
|
|
expect(endBalance - startBalance).to.equal(price(request))
|
|
|
|
})
|
2022-07-20 08:29:24 +00:00
|
|
|
})
|
2022-08-12 01:40:04 +00:00
|
|
|
|
|
|
|
describe("contract state", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2022-09-22 02:21:49 +00:00
|
|
|
it("changes state to Cancelled when client withdraws funds", async function () {
|
2022-08-12 01:40:04 +00:00
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.New
|
|
|
|
)
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("state is Cancelled when client withdraws funds", async function () {
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-08-12 01:40:04 +00:00
|
|
|
switchAccount(client)
|
|
|
|
await marketplace.withdrawFunds(slot.request)
|
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.Cancelled
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-09-08 07:56:01 +00:00
|
|
|
it("changes state to Started once all slots are filled", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-08-12 01:40:04 +00:00
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.Started
|
|
|
|
)
|
|
|
|
})
|
2022-09-08 07:56:01 +00:00
|
|
|
|
2022-09-21 09:57:26 +00:00
|
|
|
it("state is Failed once too many slots are freed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
2022-09-13 07:20:07 +00:00
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.Failed
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-09-21 09:57:26 +00:00
|
|
|
it("state is Finished once slot is paid out", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-09-21 09:57:26 +00:00
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.Finished
|
|
|
|
)
|
|
|
|
})
|
2022-09-21 09:13:12 +00:00
|
|
|
it("does not change state to Failed if too many slots freed but contract not started", async function () {
|
|
|
|
for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
|
|
|
|
await marketplace.fillSlot(slot.request, i, proof)
|
|
|
|
}
|
|
|
|
for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
|
|
|
|
slot.index = i
|
|
|
|
let id = slotId(slot)
|
|
|
|
await marketplace.freeSlot(id)
|
|
|
|
}
|
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.New
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2022-09-08 07:56:01 +00:00
|
|
|
it("changes state to Cancelled once request is cancelled", async function () {
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-09-08 07:56:01 +00:00
|
|
|
await expect(await marketplace.state(slot.request)).to.equal(
|
|
|
|
RequestState.Cancelled
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("changes isCancelled to true once request is cancelled", async function () {
|
|
|
|
await expect(await marketplace.isCancelled(slot.request)).to.be.false
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-09-08 07:56:01 +00:00
|
|
|
await expect(await marketplace.isCancelled(slot.request)).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it("rejects isSlotCancelled when slot is empty", async function () {
|
|
|
|
await expect(
|
|
|
|
marketplace.isSlotCancelled(slotId(slot))
|
|
|
|
).to.be.revertedWith("Slot empty")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("changes isSlotCancelled to true once request is cancelled", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await expect(await marketplace.isSlotCancelled(slotId(slot))).to.be.false
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-09-08 07:56:01 +00:00
|
|
|
await expect(await marketplace.isSlotCancelled(slotId(slot))).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it("changes proofEnd to the past when request is cancelled", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
await expect(await marketplace.proofEnd(slotId(slot))).to.be.gt(
|
|
|
|
await currentTime()
|
|
|
|
)
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-09-08 07:56:01 +00:00
|
|
|
await expect(await marketplace.proofEnd(slotId(slot))).to.be.lt(
|
|
|
|
await currentTime()
|
|
|
|
)
|
|
|
|
})
|
2022-08-12 01:40:04 +00:00
|
|
|
})
|
2022-09-21 09:57:26 +00:00
|
|
|
describe("modifiers", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("accepting proofs", function () {
|
|
|
|
it("fails when request Cancelled (isCancelled is true)", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-09-21 09:57:26 +00:00
|
|
|
await expect(
|
|
|
|
marketplace.testAcceptsProofs(slotId(slot))
|
2022-09-22 02:21:49 +00:00
|
|
|
).to.be.revertedWith("Slot not accepting proofs")
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("fails when request Cancelled (state set to Cancelled)", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
2022-09-23 02:33:39 +00:00
|
|
|
await waitUntilCancelled(request)
|
2022-09-21 09:57:26 +00:00
|
|
|
switchAccount(client)
|
|
|
|
await marketplace.withdrawFunds(slot.request)
|
|
|
|
await expect(
|
|
|
|
marketplace.testAcceptsProofs(slotId(slot))
|
2022-09-22 02:21:49 +00:00
|
|
|
).to.be.revertedWith("Slot not accepting proofs")
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("fails when request Finished (isFinished is true)", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-09-21 09:57:26 +00:00
|
|
|
await expect(
|
|
|
|
marketplace.testAcceptsProofs(slotId(slot))
|
2022-09-22 02:21:49 +00:00
|
|
|
).to.be.revertedWith("Slot not accepting proofs")
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("fails when request Finished (state set to Finished)", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-09-21 09:57:26 +00:00
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
await expect(
|
|
|
|
marketplace.testAcceptsProofs(slotId(slot))
|
2022-09-22 02:21:49 +00:00
|
|
|
).to.be.revertedWith("Slot not accepting proofs")
|
2022-09-21 09:57:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("fails when request Failed", async function () {
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-09-21 09:57:26 +00:00
|
|
|
for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
|
|
|
|
slot.index = i
|
|
|
|
let id = slotId(slot)
|
|
|
|
await marketplace.freeSlot(id)
|
|
|
|
}
|
|
|
|
await expect(
|
|
|
|
marketplace.testAcceptsProofs(slotId(slot))
|
|
|
|
).to.be.revertedWith("Slot empty")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2022-10-25 02:06:52 +00:00
|
|
|
|
|
|
|
describe("list of active requests", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
switchAccount(host)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
switchAccount(client)
|
|
|
|
await token.approve(marketplace.address, price(request))
|
|
|
|
})
|
|
|
|
|
|
|
|
it("adds request to list when requesting storage", async function () {
|
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
expect(await marketplace.myRequests()).to.deep.equal([requestId(request)])
|
|
|
|
})
|
|
|
|
|
2022-11-23 11:39:49 +00:00
|
|
|
it("keeps request in list when cancelled", async function () {
|
2022-11-22 13:14:39 +00:00
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
await waitUntilCancelled(request)
|
2022-11-23 11:39:49 +00:00
|
|
|
expect(await marketplace.myRequests()).to.deep.equal([requestId(request)])
|
2022-11-22 13:14:39 +00:00
|
|
|
})
|
|
|
|
|
2022-10-25 02:06:52 +00:00
|
|
|
it("removes request from list when funds are withdrawn", async function () {
|
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
await waitUntilCancelled(request)
|
|
|
|
await marketplace.withdrawFunds(requestId(request))
|
|
|
|
expect(await marketplace.myRequests()).to.deep.equal([])
|
|
|
|
})
|
|
|
|
|
2022-11-23 11:39:49 +00:00
|
|
|
it("keeps request in list when request fails", async function () {
|
2022-10-25 02:06:52 +00:00
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
switchAccount(host)
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 02:06:52 +00:00
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
|
|
|
switchAccount(client)
|
2022-11-23 11:39:49 +00:00
|
|
|
expect(await marketplace.myRequests()).to.deep.equal([requestId(request)])
|
2022-10-25 02:06:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("removes request from list when request finishes", async function () {
|
|
|
|
await marketplace.requestStorage(request)
|
|
|
|
switchAccount(host)
|
2022-11-11 02:33:28 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-10-25 12:49:37 +00:00
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
2022-10-25 02:06:52 +00:00
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
|
|
|
switchAccount(client)
|
|
|
|
expect(await marketplace.myRequests()).to.deep.equal([])
|
|
|
|
})
|
|
|
|
})
|
2022-11-11 02:33:02 +00:00
|
|
|
|
|
|
|
describe("list of active slots", function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
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("adds slot to list when filling slot", async function () {
|
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
let slot1 = { ...slot, index: slot.index + 1 }
|
|
|
|
await marketplace.fillSlot(slot.request, slot1.index, proof)
|
2022-11-23 11:25:47 +00:00
|
|
|
expect(await marketplace.mySlots()).to.have.members([
|
2022-11-11 02:33:02 +00:00
|
|
|
slotId(slot),
|
|
|
|
slotId(slot1),
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
2022-11-23 13:18:42 +00:00
|
|
|
it("removes slot from list when slot is freed", async function () {
|
2022-11-11 02:33:02 +00:00
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
let slot1 = { ...slot, index: slot.index + 1 }
|
|
|
|
await marketplace.fillSlot(slot.request, slot1.index, proof)
|
|
|
|
await marketplace.freeSlot(slotId(slot))
|
2022-11-23 11:25:47 +00:00
|
|
|
expect(await marketplace.mySlots()).to.have.members([slotId(slot1)])
|
2022-11-11 02:33:02 +00:00
|
|
|
})
|
|
|
|
|
2022-11-23 13:18:42 +00:00
|
|
|
it("keeps slots when cancelled", async function () {
|
2022-11-22 13:14:39 +00:00
|
|
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
|
|
|
let slot1 = { ...slot, index: slot.index + 1 }
|
|
|
|
await marketplace.fillSlot(slot.request, slot1.index, proof)
|
|
|
|
await waitUntilCancelled(request)
|
2022-11-23 13:18:42 +00:00
|
|
|
expect(await marketplace.mySlots()).to.have.members([
|
|
|
|
slotId(slot),
|
|
|
|
slotId(slot1),
|
|
|
|
])
|
2022-11-22 13:14:39 +00:00
|
|
|
})
|
|
|
|
|
2022-11-16 04:52:22 +00:00
|
|
|
it("removes active slots for all hosts in a request when it fails", async function () {
|
|
|
|
let halfOfSlots = request.ask.slots / 2
|
|
|
|
|
|
|
|
// fill half the slots with host1
|
|
|
|
for (let i = 0; i < Math.floor(halfOfSlots); i++) {
|
|
|
|
await marketplace.fillSlot(requestId(request), i, proof)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fill other half of slots with host2
|
|
|
|
switchAccount(host2)
|
|
|
|
await token.approve(marketplace.address, collateral)
|
|
|
|
await marketplace.deposit(collateral)
|
|
|
|
for (let i = Math.floor(halfOfSlots); i < request.ask.slots; i++) {
|
|
|
|
await marketplace.fillSlot(requestId(request), i, proof)
|
|
|
|
}
|
|
|
|
|
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
2022-11-23 11:25:47 +00:00
|
|
|
expect(await marketplace.mySlots()).to.have.members([])
|
2022-11-16 04:52:22 +00:00
|
|
|
switchAccount(host)
|
2022-11-23 11:25:47 +00:00
|
|
|
expect(await marketplace.mySlots()).to.have.members([])
|
2022-11-16 04:52:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("doesn't remove active slots for hosts in request that didn't fail", async function () {
|
2022-11-15 10:18:18 +00:00
|
|
|
// start first request
|
2022-11-11 02:33:02 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
2022-11-15 10:18:18 +00:00
|
|
|
|
|
|
|
// start a second request
|
|
|
|
let request2 = await exampleRequest()
|
|
|
|
request2.client = client.address
|
|
|
|
switchAccount(client)
|
|
|
|
await token.approve(marketplace.address, price(request2))
|
|
|
|
await marketplace.requestStorage(request2)
|
|
|
|
switchAccount(host)
|
|
|
|
await waitUntilStarted(marketplace, request2, proof)
|
|
|
|
|
|
|
|
// wait until first request fails
|
2022-11-11 02:33:02 +00:00
|
|
|
await waitUntilFailed(marketplace, request, slot)
|
2022-11-15 10:18:18 +00:00
|
|
|
|
|
|
|
// check that our active slots only contains slotIds from second request
|
|
|
|
let expected = []
|
|
|
|
let expectedSlot = { ...slot, index: 0, request: requestId(request2) }
|
|
|
|
for (let i = 0; i < request2.ask.slots; i++) {
|
|
|
|
expectedSlot.index = i
|
|
|
|
let id = slotId(expectedSlot)
|
|
|
|
expected.push(id)
|
|
|
|
}
|
2022-11-23 11:25:47 +00:00
|
|
|
expect(await marketplace.mySlots()).to.have.members(expected)
|
2022-11-11 02:33:02 +00:00
|
|
|
})
|
|
|
|
|
2022-11-23 11:25:47 +00:00
|
|
|
it("removes slot from list when slot is paid out", async function () {
|
2022-11-11 02:33:02 +00:00
|
|
|
await waitUntilStarted(marketplace, request, proof)
|
|
|
|
await waitUntilFinished(marketplace, requestId(request))
|
|
|
|
await marketplace.payoutSlot(slot.request, slot.index)
|
2022-11-23 11:25:47 +00:00
|
|
|
expect(await marketplace.mySlots()).to.not.contain(slotId(slot))
|
2022-11-11 02:33:02 +00:00
|
|
|
})
|
|
|
|
})
|
2022-02-16 09:50:00 +00:00
|
|
|
})
|