mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-07 14:13:28 +00:00
[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);
|
pointer = _getPointer(id, period);
|
||||||
bytes32 challenge = _getChallenge(pointer);
|
bytes32 challenge = _getChallenge(pointer);
|
||||||
uint256 probability = (_probabilities[id] * (256 - _config.downtime)) / 256;
|
uint256 probability = (_probabilities[id] * (256 - _config.downtime)) / 256;
|
||||||
isRequired = uint256(challenge) % probability == 0;
|
isRequired = probability == 0 || uint256(challenge) % probability == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _isProofRequired(
|
function _isProofRequired(
|
||||||
|
@ -41,6 +41,7 @@ describe("Proofs", function () {
|
|||||||
|
|
||||||
it("requires proofs with an agreed upon probability", async function () {
|
it("requires proofs with an agreed upon probability", async function () {
|
||||||
await proofs.startRequiringProofs(slotId, probability)
|
await proofs.startRequiringProofs(slotId, probability)
|
||||||
|
await advanceTime(period)
|
||||||
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)) {
|
||||||
@ -52,6 +53,15 @@ describe("Proofs", function () {
|
|||||||
expect(amount).to.be.closeTo(expected, expected / 2)
|
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 () {
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user