Move submitProof() function to Marketplace

This commit is contained in:
Mark Spanbroek 2024-01-18 14:09:36 +01:00 committed by markspanbroek
parent e6a918fed9
commit 38411c27ca
4 changed files with 20 additions and 12 deletions

View File

@ -159,6 +159,10 @@ contract Marketplace is Proofs, StateRetrieval {
} }
} }
function submitProof(SlotId id, Groth16Proof calldata proof) public {
_proofReceived(id, proof);
}
function markProofAsMissing(SlotId slotId, Period period) public { function markProofAsMissing(SlotId slotId, Period period) public {
require(slotState(slotId) == SlotState.Filled, "Slot not accepting proofs"); require(slotState(slotId) == SlotState.Filled, "Slot not accepting proofs");
_markProofAsMissing(slotId, period); _markProofAsMissing(slotId, period);

View File

@ -109,7 +109,7 @@ abstract contract Proofs is Periods {
return isRequired && pointer < _config.downtime; return isRequired && pointer < _config.downtime;
} }
function submitProof(SlotId id, Groth16Proof calldata proof) public { function _proofReceived(SlotId id, Groth16Proof calldata proof) internal {
require(!_received[id][_blockPeriod()], "Proof already submitted"); require(!_received[id][_blockPeriod()], "Proof already submitted");
// TODO: The `pubSignals` should be constructed from information that we already know: // TODO: The `pubSignals` should be constructed from information that we already know:

View File

@ -24,6 +24,10 @@ contract TestProofs is Proofs {
_markProofAsMissing(id, period); _markProofAsMissing(id, period);
} }
function proofReceived(SlotId id, Groth16Proof calldata proof) public {
_proofReceived(id, proof);
}
function setSlotState(SlotId id, SlotState state) public { function setSlotState(SlotId id, SlotState state) public {
_states[id] = state; _states[id] = state;
} }

View File

@ -200,25 +200,25 @@ describe("Proofs", function () {
expect(challenge1 === challenge2 && challenge2 === challenge3).to.be.false expect(challenge1 === challenge2 && challenge2 === challenge3).to.be.false
}) })
it("submits a correct proof", async function () { it("handles a correct proof", async function () {
await proofs.submitProof(slotId, proof) await proofs.proofReceived(slotId, proof)
}) })
it("fails proof submission when proof is incorrect", async function () { it("fails proof submission when proof is incorrect", async function () {
let invalid = exampleProof() let invalid = exampleProof()
await expect(proofs.submitProof(slotId, invalid)).to.be.reverted await expect(proofs.proofReceived(slotId, invalid)).to.be.reverted
}) })
it("emits an event when proof was submitted", async function () { it("emits an event when proof was submitted", async function () {
await expect(proofs.submitProof(slotId, proof)) await expect(proofs.proofReceived(slotId, proof))
.to.emit(proofs, "ProofSubmitted") .to.emit(proofs, "ProofSubmitted")
.withArgs(slotId) .withArgs(slotId)
}) })
it("fails proof submission when already submitted", async function () { it("fails proof submission when already submitted", async function () {
await advanceTimeToForNextBlock(periodEnd(periodOf(await currentTime()))) await advanceTimeToForNextBlock(periodEnd(periodOf(await currentTime())))
await proofs.submitProof(slotId, proof) await proofs.proofReceived(slotId, proof)
await expect(proofs.submitProof(slotId, proof)).to.be.revertedWith( await expect(proofs.proofReceived(slotId, proof)).to.be.revertedWith(
"Proof already submitted" "Proof already submitted"
) )
}) })
@ -250,14 +250,14 @@ describe("Proofs", function () {
).to.be.revertedWith("Validation timed out") ).to.be.revertedWith("Validation timed out")
}) })
it("does not mark a submitted proof as missing", async function () { it("does not mark a received proof as missing", async function () {
await waitUntilProofIsRequired(slotId) await waitUntilProofIsRequired(slotId)
let submittedPeriod = periodOf(await currentTime()) let receivedPeriod = periodOf(await currentTime())
await proofs.submitProof(slotId, proof) await proofs.proofReceived(slotId, proof)
await advanceTimeToForNextBlock(periodEnd(submittedPeriod)) await advanceTimeToForNextBlock(periodEnd(receivedPeriod))
await mine() await mine()
await expect( await expect(
proofs.markProofAsMissing(slotId, submittedPeriod) proofs.markProofAsMissing(slotId, receivedPeriod)
).to.be.revertedWith("Proof was submitted, not missing") ).to.be.revertedWith("Proof was submitted, not missing")
}) })