mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-02-18 01:27:11 +00:00
[proofs] Submitting proof emits event containing proof
This commit is contained in:
parent
7cbb717de7
commit
2bf01da728
@ -136,10 +136,11 @@ contract Proofs {
|
|||||||
return isRequired && pointer < downtime;
|
return isRequired && pointer < downtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _submitProof(bytes32 id, bool proof) internal {
|
function _submitProof(bytes32 id, bytes calldata proof) internal {
|
||||||
require(proof, "Invalid proof"); // TODO: replace bool by actual proof
|
require(proof.length > 0, "Invalid proof"); // TODO: replace by actual check
|
||||||
require(!received[id][currentPeriod()], "Proof already submitted");
|
require(!received[id][currentPeriod()], "Proof already submitted");
|
||||||
received[id][currentPeriod()] = true;
|
received[id][currentPeriod()] = true;
|
||||||
|
emit ProofSubmitted(id, proof);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _markProofAsMissing(bytes32 id, uint256 missedPeriod) internal {
|
function _markProofAsMissing(bytes32 id, uint256 missedPeriod) internal {
|
||||||
@ -152,4 +153,6 @@ contract Proofs {
|
|||||||
missing[id][missedPeriod] = true;
|
missing[id][missedPeriod] = true;
|
||||||
missed[id] += 1;
|
missed[id] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event ProofSubmitted(bytes32 id, bytes proof);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ contract Storage is Collateral, Marketplace, Proofs {
|
|||||||
return _getPointer(id);
|
return _getPointer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitProof(bytes32 contractId, bool proof) public {
|
function submitProof(bytes32 contractId, bytes calldata proof) public {
|
||||||
_submitProof(contractId, proof);
|
_submitProof(contractId, proof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ contract TestProofs is Proofs {
|
|||||||
return _getPointer(id);
|
return _getPointer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitProof(bytes32 id, bool proof) public {
|
function submitProof(bytes32 id, bytes calldata proof) public {
|
||||||
_submitProof(id, proof);
|
_submitProof(id, proof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const { expect } = require("chai")
|
const { expect } = require("chai")
|
||||||
const { ethers } = require("hardhat")
|
const { ethers } = require("hardhat")
|
||||||
|
const { hexlify, randomBytes } = ethers.utils
|
||||||
const {
|
const {
|
||||||
snapshot,
|
snapshot,
|
||||||
revert,
|
revert,
|
||||||
@ -12,7 +13,7 @@ const {
|
|||||||
const { periodic } = require("./time")
|
const { periodic } = require("./time")
|
||||||
|
|
||||||
describe("Proofs", function () {
|
describe("Proofs", function () {
|
||||||
const id = ethers.utils.randomBytes(32)
|
const id = hexlify(randomBytes(32))
|
||||||
const period = 30 * 60
|
const period = 30 * 60
|
||||||
const timeout = 5
|
const timeout = 5
|
||||||
const downtime = 64
|
const downtime = 64
|
||||||
@ -84,9 +85,9 @@ describe("Proofs", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("requires proofs for different ids at different times", async function () {
|
it("requires proofs for different ids at different times", async function () {
|
||||||
let id1 = ethers.utils.randomBytes(32)
|
let id1 = hexlify(randomBytes(32))
|
||||||
let id2 = ethers.utils.randomBytes(32)
|
let id2 = hexlify(randomBytes(32))
|
||||||
let id3 = ethers.utils.randomBytes(32)
|
let id3 = hexlify(randomBytes(32))
|
||||||
for (let id of [id1, id2, id3]) {
|
for (let id of [id1, id2, id3]) {
|
||||||
await proofs.expectProofs(id, probability, duration)
|
await proofs.expectProofs(id, probability, duration)
|
||||||
}
|
}
|
||||||
@ -140,6 +141,8 @@ describe("Proofs", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("when proofs are required", function () {
|
describe("when proofs are required", function () {
|
||||||
|
const proof = hexlify(randomBytes(42))
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
await proofs.expectProofs(id, probability, duration)
|
await proofs.expectProofs(id, probability, duration)
|
||||||
})
|
})
|
||||||
@ -165,8 +168,8 @@ describe("Proofs", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("provides different challenges per id", async function () {
|
it("provides different challenges per id", async function () {
|
||||||
const id2 = ethers.utils.randomBytes(32)
|
const id2 = hexlify(randomBytes(32))
|
||||||
const id3 = ethers.utils.randomBytes(32)
|
const id3 = hexlify(randomBytes(32))
|
||||||
const challenge1 = await proofs.getChallenge(id)
|
const challenge1 = await proofs.getChallenge(id)
|
||||||
const challenge2 = await proofs.getChallenge(id2)
|
const challenge2 = await proofs.getChallenge(id2)
|
||||||
const challenge3 = await proofs.getChallenge(id3)
|
const challenge3 = await proofs.getChallenge(id3)
|
||||||
@ -174,19 +177,25 @@ describe("Proofs", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("submits a correct proof", async function () {
|
it("submits a correct proof", async function () {
|
||||||
await proofs.submitProof(id, true)
|
await proofs.submitProof(id, proof)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("fails proof submission when proof is incorrect", async function () {
|
it("fails proof submission when proof is incorrect", async function () {
|
||||||
await expect(proofs.submitProof(id, false)).to.be.revertedWith(
|
await expect(proofs.submitProof(id, [])).to.be.revertedWith(
|
||||||
"Invalid proof"
|
"Invalid proof"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("emits an event when proof was submitted", async function () {
|
||||||
|
await expect(proofs.submitProof(id, proof))
|
||||||
|
.to.emit(proofs, "ProofSubmitted")
|
||||||
|
.withArgs(id, proof)
|
||||||
|
})
|
||||||
|
|
||||||
it("fails proof submission when already submitted", async function () {
|
it("fails proof submission when already submitted", async function () {
|
||||||
await advanceTimeTo(periodEnd(periodOf(await currentTime())))
|
await advanceTimeTo(periodEnd(periodOf(await currentTime())))
|
||||||
await proofs.submitProof(id, true)
|
await proofs.submitProof(id, proof)
|
||||||
await expect(proofs.submitProof(id, true)).to.be.revertedWith(
|
await expect(proofs.submitProof(id, proof)).to.be.revertedWith(
|
||||||
"Proof already submitted"
|
"Proof already submitted"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -220,7 +229,7 @@ describe("Proofs", function () {
|
|||||||
it("does not mark a submitted proof as missing", async function () {
|
it("does not mark a submitted proof as missing", async function () {
|
||||||
await waitUntilProofIsRequired(id)
|
await waitUntilProofIsRequired(id)
|
||||||
let submittedPeriod = periodOf(await currentTime())
|
let submittedPeriod = periodOf(await currentTime())
|
||||||
await proofs.submitProof(id, true)
|
await proofs.submitProof(id, proof)
|
||||||
await advanceTimeTo(periodEnd(submittedPeriod))
|
await advanceTimeTo(periodEnd(submittedPeriod))
|
||||||
await expect(
|
await expect(
|
||||||
proofs.markProofAsMissing(id, submittedPeriod)
|
proofs.markProofAsMissing(id, submittedPeriod)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user