2022-09-21 09:57:26 +00:00
|
|
|
const { advanceTimeTo } = require("./evm")
|
2022-11-11 02:33:28 +00:00
|
|
|
const { slotId, requestId } = require("./ids")
|
2022-09-07 05:25:01 +00:00
|
|
|
|
2022-09-23 02:33:39 +00:00
|
|
|
async function waitUntilCancelled(request) {
|
|
|
|
await advanceTimeTo(request.expiry + 1)
|
2022-08-04 02:14:36 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 02:33:28 +00:00
|
|
|
async function waitUntilStarted(contract, request, proof) {
|
2022-10-26 02:37:30 +00:00
|
|
|
for (let i = 0; i < request.ask.slots; i++) {
|
2022-11-11 02:33:28 +00:00
|
|
|
await contract.fillSlot(requestId(request), i, proof)
|
2022-09-13 07:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 12:49:37 +00:00
|
|
|
async function waitUntilFinished(contract, requestId) {
|
|
|
|
const end = (await contract.requestEnd(requestId)).toNumber()
|
2022-09-21 09:57:26 +00:00
|
|
|
await advanceTimeTo(end + 1)
|
|
|
|
}
|
|
|
|
|
2022-09-23 02:33:39 +00:00
|
|
|
async function waitUntilFailed(contract, request, slot) {
|
|
|
|
for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
|
2022-09-21 09:57:26 +00:00
|
|
|
slot.index = i
|
|
|
|
let id = slotId(slot)
|
|
|
|
await contract.freeSlot(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 02:21:49 +00:00
|
|
|
const RequestState = {
|
|
|
|
New: 0,
|
|
|
|
Started: 1,
|
|
|
|
Cancelled: 2,
|
|
|
|
Finished: 3,
|
|
|
|
Failed: 4,
|
|
|
|
}
|
|
|
|
|
2022-09-21 09:57:26 +00:00
|
|
|
module.exports = {
|
|
|
|
waitUntilCancelled,
|
|
|
|
waitUntilStarted,
|
|
|
|
waitUntilFinished,
|
|
|
|
waitUntilFailed,
|
2022-09-22 02:21:49 +00:00
|
|
|
RequestState,
|
2022-09-21 09:57:26 +00:00
|
|
|
}
|