[proofs] support probability 1 (proofs always required)
This commit is contained in:
parent
cde5436262
commit
c9b51695aa
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue