codex-contracts-eth/test/marketplace.js

44 lines
987 B
JavaScript
Raw Normal View History

const { advanceTimeTo } = require("./evm")
const { slotId } = require("./ids")
async function waitUntilCancelled(request) {
await advanceTimeTo(request.expiry + 1)
}
async function waitUntilStarted(contract, request, slot, proof) {
const lastSlotIdx = request.ask.slots - 1
for (let i = 0; i <= lastSlotIdx; i++) {
await contract.fillSlot(slot.request, i, proof)
2022-09-13 07:20:07 +00:00
}
return { ...slot, index: lastSlotIdx }
2022-09-13 07:20:07 +00:00
}
async function waitUntilFinished(contract, requestId) {
const end = (await contract.requestEnd(requestId)).toNumber()
await advanceTimeTo(end + 1)
}
async function waitUntilFailed(contract, request, slot) {
for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
slot.index = i
let id = slotId(slot)
await contract.freeSlot(id)
}
}
const RequestState = {
New: 0,
Started: 1,
Cancelled: 2,
Finished: 3,
Failed: 4,
}
module.exports = {
waitUntilCancelled,
waitUntilStarted,
waitUntilFinished,
waitUntilFailed,
RequestState,
}