dagger-contracts/test/marketplace.js

42 lines
907 B
JavaScript

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