mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-07 14:13:28 +00:00
Allow proof ending to be extending once a contract is started, so that all filled slots share an ending time that is equal to the contract end time. Added tests. Add a mapping for proof id to endId so that proof expectations can be extended for all proofs that share a given endId. Add function modifiers that require the request state to allow proofs, with accompanying tests. General clean up of each function’s request state context, with accompanying tests. General clean up of all tests, including state change “wait” functions and normalising the time advancement functions.
34 lines
799 B
JavaScript
34 lines
799 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)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
waitUntilCancelled,
|
|
waitUntilStarted,
|
|
waitUntilFinished,
|
|
waitUntilFailed,
|
|
}
|