[proofs] support probability 1 (proofs always required)

This commit is contained in:
Mark Spanbroek 2023-01-18 16:05:32 +01:00 committed by markspanbroek
parent cde5436262
commit c9b51695aa
2 changed files with 11 additions and 1 deletions

View File

@ -71,7 +71,7 @@ abstract contract Proofs is Periods {
pointer = _getPointer(id, period);
bytes32 challenge = _getChallenge(pointer);
uint256 probability = (_probabilities[id] * (256 - _config.downtime)) / 256;
isRequired = uint256(challenge) % probability == 0;
isRequired = probability == 0 || uint256(challenge) % probability == 0;
}
function _isProofRequired(

View File

@ -41,6 +41,7 @@ describe("Proofs", function () {
it("requires proofs with an agreed upon probability", async function () {
await proofs.startRequiringProofs(slotId, probability)
await advanceTime(period)
let amount = 0
for (let i = 0; i < 100; i++) {
if (await proofs.isProofRequired(slotId)) {
@ -52,6 +53,15 @@ describe("Proofs", function () {
expect(amount).to.be.closeTo(expected, expected / 2)
})
it("supports probability 1 (proofs are always required)", async function () {
await proofs.startRequiringProofs(slotId, 1)
await advanceTime(period)
while ((await proofs.getPointer(slotId)) < downtime) {
await mine()
}
expect(await proofs.isProofRequired(slotId)).to.be.true
})
it("requires no proofs in the start period", async function () {
const startPeriod = Math.floor((await currentTime()) / period)
const probability = 1