[Proofs] rename expectProofs -> startRequiringProofs

This commit is contained in:
Mark Spanbroek 2023-01-10 12:51:26 +01:00 committed by markspanbroek
parent f224cb8eda
commit c0690cd5d1
4 changed files with 23 additions and 23 deletions

View File

@ -96,7 +96,7 @@ contract Marketplace is Collateral, Proofs {
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
_expectProofs(slotId, request.ask.proofProbability);
_startRequiringProofs(slotId, request.ask.proofProbability);
submitProof(slotId, proof);
slot.host = msg.sender;
@ -162,7 +162,7 @@ contract Marketplace is Collateral, Proofs {
// Slot collateral is not yet implemented as the design decision was
// not finalised.
_unexpectProofs(slotId);
_stopRequiringProofs(slotId);
slotsPerHost[slot.host].remove(SlotId.unwrap(slotId));

View File

@ -52,14 +52,14 @@ abstract contract Proofs {
/// @notice Informs the contract that proofs should be expected for id
/// @dev Requires that the id is not already in use
/// @param probability The probability that a proof should be expected
function _expectProofs(SlotId id, uint256 probability) internal {
require(!slotIds[id], "Slot id already in use");
function _startRequiringProofs(SlotId id, uint256 probability) internal {
require(!slotIds[id], "Proofs already required for slot");
slotIds[id] = true;
probabilities[id] = probability;
}
function _unexpectProofs(SlotId id) internal {
require(slotIds[id], "Proof id not in use");
function _stopRequiringProofs(SlotId id) internal {
require(slotIds[id], "Proofs not required for slot");
slotIds[id] = false;
}

View File

@ -35,12 +35,12 @@ contract TestProofs is Proofs {
return _timeout();
}
function expectProofs(SlotId slot, uint256 _probability) public {
_expectProofs(slot, _probability);
function startRequiringProofs(SlotId slot, uint256 _probability) public {
_startRequiringProofs(slot, _probability);
}
function unexpectProofs(SlotId id) public {
_unexpectProofs(id);
function stopRequiringProofs(SlotId id) public {
_stopRequiringProofs(id);
}
function isProofRequired(SlotId id) public view returns (bool) {

View File

@ -42,14 +42,14 @@ describe("Proofs", function () {
})
it("does not allow ids to be reused", async function () {
await proofs.expectProofs(slotId, probability)
await expect(proofs.expectProofs(slotId, probability)).to.be.revertedWith(
"Slot id already in use"
)
await proofs.startRequiringProofs(slotId, probability)
await expect(
proofs.startRequiringProofs(slotId, probability)
).to.be.revertedWith("Proofs already required for slot")
})
it("requires proofs with an agreed upon probability", async function () {
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
let amount = 0
for (let i = 0; i < 100; i++) {
if (await proofs.isProofRequired(slotId)) {
@ -64,7 +64,7 @@ describe("Proofs", function () {
it("requires no proofs in the start period", async function () {
const startPeriod = Math.floor((await currentTime()) / period)
const probability = 1
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
while (Math.floor((await currentTime()) / period) == startPeriod) {
expect(await proofs.isProofRequired(slotId)).to.be.false
await advanceTime(Math.floor(period / 10))
@ -73,14 +73,14 @@ describe("Proofs", function () {
it("requires no proofs in the end period", async function () {
const probability = 1
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
await advanceTime(duration)
expect(await proofs.isProofRequired(slotId)).to.be.false
})
it("requires no proofs after the end time", async function () {
const probability = 1
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
await advanceTime(duration + timeout)
expect(await proofs.isProofRequired(slotId)).to.be.false
})
@ -92,7 +92,7 @@ describe("Proofs", function () {
for (let slotId of [id1, id2, id3]) {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
}
let req1, req2, req3
while (req1 === req2 && req2 === req3) {
@ -124,7 +124,7 @@ describe("Proofs", function () {
beforeEach(async function () {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
await advanceTimeTo(periodEnd(periodOf(await currentTime())))
await waitUntilProofWillBeRequired()
})
@ -148,7 +148,7 @@ describe("Proofs", function () {
it("will not require proofs when no longer expected", async function () {
expect(await proofs.getPointer(slotId)).to.be.lt(downtime)
expect(await proofs.willProofBeRequired(slotId)).to.be.true
await proofs.unexpectProofs(slotId)
await proofs.stopRequiringProofs(slotId)
expect(await proofs.willProofBeRequired(slotId)).to.be.false
})
})
@ -159,7 +159,7 @@ describe("Proofs", function () {
beforeEach(async function () {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
await proofs.expectProofs(slotId, probability)
await proofs.startRequiringProofs(slotId, probability)
})
async function waitUntilProofIsRequired(slotId) {
@ -274,7 +274,7 @@ describe("Proofs", function () {
it("requires no proofs when no longer expected", async function () {
await waitUntilProofIsRequired(slotId)
await proofs.unexpectProofs(slotId)
await proofs.stopRequiringProofs(slotId)
await expect(await proofs.isProofRequired(slotId)).to.be.false
})
})