mirror of
https://github.com/codex-storage/codex-contracts-eth.git
synced 2025-02-19 14:54:20 +00:00
[Proofs] rename expectProofs -> startRequiringProofs
This commit is contained in:
parent
f224cb8eda
commit
c0690cd5d1
@ -96,7 +96,7 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
|
|
||||||
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
|
require(balanceOf(msg.sender) >= collateral, "Insufficient collateral");
|
||||||
|
|
||||||
_expectProofs(slotId, request.ask.proofProbability);
|
_startRequiringProofs(slotId, request.ask.proofProbability);
|
||||||
submitProof(slotId, proof);
|
submitProof(slotId, proof);
|
||||||
|
|
||||||
slot.host = msg.sender;
|
slot.host = msg.sender;
|
||||||
@ -162,7 +162,7 @@ contract Marketplace is Collateral, Proofs {
|
|||||||
// Slot collateral is not yet implemented as the design decision was
|
// Slot collateral is not yet implemented as the design decision was
|
||||||
// not finalised.
|
// not finalised.
|
||||||
|
|
||||||
_unexpectProofs(slotId);
|
_stopRequiringProofs(slotId);
|
||||||
|
|
||||||
slotsPerHost[slot.host].remove(SlotId.unwrap(slotId));
|
slotsPerHost[slot.host].remove(SlotId.unwrap(slotId));
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ abstract contract Proofs {
|
|||||||
/// @notice Informs the contract that proofs should be expected for id
|
/// @notice Informs the contract that proofs should be expected for id
|
||||||
/// @dev Requires that the id is not already in use
|
/// @dev Requires that the id is not already in use
|
||||||
/// @param probability The probability that a proof should be expected
|
/// @param probability The probability that a proof should be expected
|
||||||
function _expectProofs(SlotId id, uint256 probability) internal {
|
function _startRequiringProofs(SlotId id, uint256 probability) internal {
|
||||||
require(!slotIds[id], "Slot id already in use");
|
require(!slotIds[id], "Proofs already required for slot");
|
||||||
slotIds[id] = true;
|
slotIds[id] = true;
|
||||||
probabilities[id] = probability;
|
probabilities[id] = probability;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _unexpectProofs(SlotId id) internal {
|
function _stopRequiringProofs(SlotId id) internal {
|
||||||
require(slotIds[id], "Proof id not in use");
|
require(slotIds[id], "Proofs not required for slot");
|
||||||
slotIds[id] = false;
|
slotIds[id] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ contract TestProofs is Proofs {
|
|||||||
return _timeout();
|
return _timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectProofs(SlotId slot, uint256 _probability) public {
|
function startRequiringProofs(SlotId slot, uint256 _probability) public {
|
||||||
_expectProofs(slot, _probability);
|
_startRequiringProofs(slot, _probability);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unexpectProofs(SlotId id) public {
|
function stopRequiringProofs(SlotId id) public {
|
||||||
_unexpectProofs(id);
|
_stopRequiringProofs(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isProofRequired(SlotId id) public view returns (bool) {
|
function isProofRequired(SlotId id) public view returns (bool) {
|
||||||
|
@ -42,14 +42,14 @@ describe("Proofs", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("does not allow ids to be reused", async function () {
|
it("does not allow ids to be reused", async function () {
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
await expect(proofs.expectProofs(slotId, probability)).to.be.revertedWith(
|
await expect(
|
||||||
"Slot id already in use"
|
proofs.startRequiringProofs(slotId, probability)
|
||||||
)
|
).to.be.revertedWith("Proofs already required for slot")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("requires proofs with an agreed upon probability", async function () {
|
it("requires proofs with an agreed upon probability", async function () {
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
let amount = 0
|
let amount = 0
|
||||||
for (let i = 0; i < 100; i++) {
|
for (let i = 0; i < 100; i++) {
|
||||||
if (await proofs.isProofRequired(slotId)) {
|
if (await proofs.isProofRequired(slotId)) {
|
||||||
@ -64,7 +64,7 @@ describe("Proofs", function () {
|
|||||||
it("requires no proofs in the start period", async function () {
|
it("requires no proofs in the start period", async function () {
|
||||||
const startPeriod = Math.floor((await currentTime()) / period)
|
const startPeriod = Math.floor((await currentTime()) / period)
|
||||||
const probability = 1
|
const probability = 1
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
while (Math.floor((await currentTime()) / period) == startPeriod) {
|
while (Math.floor((await currentTime()) / period) == startPeriod) {
|
||||||
expect(await proofs.isProofRequired(slotId)).to.be.false
|
expect(await proofs.isProofRequired(slotId)).to.be.false
|
||||||
await advanceTime(Math.floor(period / 10))
|
await advanceTime(Math.floor(period / 10))
|
||||||
@ -73,14 +73,14 @@ describe("Proofs", function () {
|
|||||||
|
|
||||||
it("requires no proofs in the end period", async function () {
|
it("requires no proofs in the end period", async function () {
|
||||||
const probability = 1
|
const probability = 1
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
await advanceTime(duration)
|
await advanceTime(duration)
|
||||||
expect(await proofs.isProofRequired(slotId)).to.be.false
|
expect(await proofs.isProofRequired(slotId)).to.be.false
|
||||||
})
|
})
|
||||||
|
|
||||||
it("requires no proofs after the end time", async function () {
|
it("requires no proofs after the end time", async function () {
|
||||||
const probability = 1
|
const probability = 1
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
await advanceTime(duration + timeout)
|
await advanceTime(duration + timeout)
|
||||||
expect(await proofs.isProofRequired(slotId)).to.be.false
|
expect(await proofs.isProofRequired(slotId)).to.be.false
|
||||||
})
|
})
|
||||||
@ -92,7 +92,7 @@ describe("Proofs", function () {
|
|||||||
for (let slotId of [id1, id2, id3]) {
|
for (let slotId of [id1, id2, id3]) {
|
||||||
await proofs.setProofStart(slotId, await currentTime())
|
await proofs.setProofStart(slotId, await currentTime())
|
||||||
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
|
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
}
|
}
|
||||||
let req1, req2, req3
|
let req1, req2, req3
|
||||||
while (req1 === req2 && req2 === req3) {
|
while (req1 === req2 && req2 === req3) {
|
||||||
@ -124,7 +124,7 @@ describe("Proofs", function () {
|
|||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await proofs.setProofStart(slotId, await currentTime())
|
await proofs.setProofStart(slotId, await currentTime())
|
||||||
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
|
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
await advanceTimeTo(periodEnd(periodOf(await currentTime())))
|
await advanceTimeTo(periodEnd(periodOf(await currentTime())))
|
||||||
await waitUntilProofWillBeRequired()
|
await waitUntilProofWillBeRequired()
|
||||||
})
|
})
|
||||||
@ -148,7 +148,7 @@ describe("Proofs", function () {
|
|||||||
it("will not require proofs when no longer expected", async function () {
|
it("will not require proofs when no longer expected", async function () {
|
||||||
expect(await proofs.getPointer(slotId)).to.be.lt(downtime)
|
expect(await proofs.getPointer(slotId)).to.be.lt(downtime)
|
||||||
expect(await proofs.willProofBeRequired(slotId)).to.be.true
|
expect(await proofs.willProofBeRequired(slotId)).to.be.true
|
||||||
await proofs.unexpectProofs(slotId)
|
await proofs.stopRequiringProofs(slotId)
|
||||||
expect(await proofs.willProofBeRequired(slotId)).to.be.false
|
expect(await proofs.willProofBeRequired(slotId)).to.be.false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -159,7 +159,7 @@ describe("Proofs", function () {
|
|||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await proofs.setProofStart(slotId, await currentTime())
|
await proofs.setProofStart(slotId, await currentTime())
|
||||||
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
|
await proofs.setProofEnd(slotId, (await currentTime()) + duration)
|
||||||
await proofs.expectProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
})
|
})
|
||||||
|
|
||||||
async function waitUntilProofIsRequired(slotId) {
|
async function waitUntilProofIsRequired(slotId) {
|
||||||
@ -274,7 +274,7 @@ describe("Proofs", function () {
|
|||||||
|
|
||||||
it("requires no proofs when no longer expected", async function () {
|
it("requires no proofs when no longer expected", async function () {
|
||||||
await waitUntilProofIsRequired(slotId)
|
await waitUntilProofIsRequired(slotId)
|
||||||
await proofs.unexpectProofs(slotId)
|
await proofs.stopRequiringProofs(slotId)
|
||||||
await expect(await proofs.isProofRequired(slotId)).to.be.false
|
await expect(await proofs.isProofRequired(slotId)).to.be.false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user