mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-07 14:13:28 +00:00
321132b6fa
1. Replace all instances of `now()` with `await currentTime()` to get a more accurate representation of time from the block timestamp. Update examples.js to be async. 2. Move `RequestState` to `marketplace.js` 3. Delete `TestStorage` as `slashAmount` function no longer needed.
43 lines
909 B
JavaScript
43 lines
909 B
JavaScript
const { advanceTimeTo } = require("./evm")
|
|
const { slotId } = require("./ids")
|
|
|
|
async function waitUntilCancelled(expiry) {
|
|
await advanceTimeTo(expiry + 1)
|
|
}
|
|
|
|
async function waitUntilStarted(contract, numSlots, requestId, proof) {
|
|
const lastSlot = numSlots - 1
|
|
for (let i = 0; i <= lastSlot; i++) {
|
|
await contract.fillSlot(requestId, i, proof)
|
|
}
|
|
}
|
|
|
|
async function waitUntilFinished(contract, slotId) {
|
|
const end = (await contract.proofEnd(slotId)).toNumber()
|
|
await advanceTimeTo(end + 1)
|
|
}
|
|
|
|
async function waitUntilFailed(contract, slot, maxSlotLoss) {
|
|
for (let i = 0; i <= 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,
|
|
}
|