[marketplace] Add method to get request end time
This commit is contained in:
parent
2ac6c0b2de
commit
9a6a321d5b
|
@ -268,7 +268,7 @@ contract Marketplace is Collateral, Proofs {
|
||||||
|
|
||||||
function proofEnd(SlotId slotId) public view returns (uint256) {
|
function proofEnd(SlotId slotId) public view returns (uint256) {
|
||||||
Slot memory slot = _slot(slotId);
|
Slot memory slot = _slot(slotId);
|
||||||
uint256 end = _end(_toEndId(slot.requestId));
|
uint256 end = requestEnd(slot.requestId);
|
||||||
if (_slotAcceptsProofs(slotId)) {
|
if (_slotAcceptsProofs(slotId)) {
|
||||||
return end;
|
return end;
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,6 +276,10 @@ contract Marketplace is Collateral, Proofs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requestEnd(RequestId requestId) public view returns (uint256) {
|
||||||
|
return _end(_toEndId(requestId));
|
||||||
|
}
|
||||||
|
|
||||||
function _price(
|
function _price(
|
||||||
uint64 numSlots,
|
uint64 numSlots,
|
||||||
uint256 duration,
|
uint256 duration,
|
||||||
|
|
|
@ -179,7 +179,7 @@ describe("Marketplace", function () {
|
||||||
|
|
||||||
it("is rejected when request is finished", async function () {
|
it("is rejected when request is finished", async function () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
await waitUntilFinished(marketplace, requestId(request))
|
||||||
await expect(
|
await expect(
|
||||||
marketplace.fillSlot(slot.request, slot.index, proof)
|
marketplace.fillSlot(slot.request, slot.index, proof)
|
||||||
).to.be.revertedWith("Request not accepting proofs")
|
).to.be.revertedWith("Request not accepting proofs")
|
||||||
|
@ -262,7 +262,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 () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
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,
|
||||||
// block.timestamp has advanced by 1, so the expected proof end time will
|
// block.timestamp has advanced by 1, so the expected proof end time will
|
||||||
|
@ -303,7 +303,7 @@ describe("Marketplace", function () {
|
||||||
|
|
||||||
it("fails to free slot when finished", async function () {
|
it("fails to free slot when finished", async function () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
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"
|
||||||
)
|
)
|
||||||
|
@ -340,7 +340,7 @@ describe("Marketplace", function () {
|
||||||
|
|
||||||
it("pays the host", async function () {
|
it("pays the host", async function () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
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)
|
||||||
const endBalance = await token.balanceOf(host.address)
|
const endBalance = await token.balanceOf(host.address)
|
||||||
|
@ -356,7 +356,7 @@ describe("Marketplace", function () {
|
||||||
|
|
||||||
it("can only be done once", async function () {
|
it("can only be done once", async function () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
await waitUntilFinished(marketplace, requestId(request))
|
||||||
await marketplace.payoutSlot(slot.request, slot.index)
|
await marketplace.payoutSlot(slot.request, slot.index)
|
||||||
await expect(
|
await expect(
|
||||||
marketplace.payoutSlot(slot.request, slot.index)
|
marketplace.payoutSlot(slot.request, slot.index)
|
||||||
|
@ -365,7 +365,7 @@ describe("Marketplace", function () {
|
||||||
|
|
||||||
it("cannot be filled again", async function () {
|
it("cannot be filled again", async function () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
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
|
||||||
.reverted
|
.reverted
|
||||||
|
@ -508,7 +508,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 () {
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
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(
|
||||||
RequestState.Finished
|
RequestState.Finished
|
||||||
|
@ -601,7 +601,7 @@ describe("Marketplace", function () {
|
||||||
slot,
|
slot,
|
||||||
proof
|
proof
|
||||||
)
|
)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
await waitUntilFinished(marketplace, requestId(request))
|
||||||
await expect(
|
await expect(
|
||||||
marketplace.testAcceptsProofs(slotId(slot))
|
marketplace.testAcceptsProofs(slotId(slot))
|
||||||
).to.be.revertedWith("Slot not accepting proofs")
|
).to.be.revertedWith("Slot not accepting proofs")
|
||||||
|
@ -614,7 +614,7 @@ describe("Marketplace", function () {
|
||||||
slot,
|
slot,
|
||||||
proof
|
proof
|
||||||
)
|
)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
await waitUntilFinished(marketplace, requestId(request))
|
||||||
await marketplace.payoutSlot(slot.request, slot.index)
|
await marketplace.payoutSlot(slot.request, slot.index)
|
||||||
await expect(
|
await expect(
|
||||||
marketplace.testAcceptsProofs(slotId(slot))
|
marketplace.testAcceptsProofs(slotId(slot))
|
||||||
|
@ -669,7 +669,7 @@ describe("Marketplace", function () {
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
const lastSlot = await waitUntilStarted(marketplace, request, slot, proof)
|
||||||
await waitUntilFinished(marketplace, lastSlot)
|
await waitUntilFinished(marketplace, requestId(request))
|
||||||
await marketplace.payoutSlot(slot.request, slot.index)
|
await marketplace.payoutSlot(slot.request, slot.index)
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
expect(await marketplace.myRequests()).to.deep.equal([])
|
expect(await marketplace.myRequests()).to.deep.equal([])
|
||||||
|
|
|
@ -76,7 +76,7 @@ describe("Storage", function () {
|
||||||
describe("ending the contract", function () {
|
describe("ending the contract", function () {
|
||||||
it("unlocks the host collateral", async function () {
|
it("unlocks the host collateral", async function () {
|
||||||
await storage.fillSlot(slot.request, slot.index, proof)
|
await storage.fillSlot(slot.request, slot.index, proof)
|
||||||
await waitUntilFinished(storage, slot)
|
await waitUntilFinished(storage, slot.request)
|
||||||
await expect(storage.withdraw()).not.to.be.reverted
|
await expect(storage.withdraw()).not.to.be.reverted
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,9 +13,8 @@ async function waitUntilStarted(contract, request, slot, proof) {
|
||||||
return { ...slot, index: lastSlotIdx }
|
return { ...slot, index: lastSlotIdx }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function waitUntilFinished(contract, lastSlot) {
|
async function waitUntilFinished(contract, requestId) {
|
||||||
const lastSlotId = slotId(lastSlot)
|
const end = (await contract.requestEnd(requestId)).toNumber()
|
||||||
const end = (await contract.proofEnd(lastSlotId)).toNumber()
|
|
||||||
await advanceTimeTo(end + 1)
|
await advanceTimeTo(end + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue