2022-05-19 19:56:03 +00:00
|
|
|
import codex/contracts
|
2022-05-11 12:17:07 +00:00
|
|
|
import ../ethertest
|
2022-04-13 16:41:48 +00:00
|
|
|
import ./examples
|
|
|
|
import ./time
|
|
|
|
|
|
|
|
ethersuite "On-Chain Proofs":
|
|
|
|
|
2022-08-17 02:29:44 +00:00
|
|
|
let contractId = SlotId.example
|
2022-11-08 07:10:17 +00:00
|
|
|
let proof = exampleProof()
|
2022-04-13 16:41:48 +00:00
|
|
|
|
|
|
|
var proofs: OnChainProofs
|
|
|
|
var storage: Storage
|
|
|
|
|
|
|
|
setup:
|
|
|
|
let deployment = deployment()
|
|
|
|
storage = Storage.new(!deployment.address(Storage), provider.getSigner())
|
|
|
|
proofs = OnChainProofs.new(storage)
|
|
|
|
|
|
|
|
test "can retrieve proof periodicity":
|
|
|
|
let periodicity = await proofs.periodicity()
|
|
|
|
let periodLength = await storage.proofPeriod()
|
|
|
|
check periodicity.seconds == periodLength
|
|
|
|
|
|
|
|
test "supports checking whether proof is required now":
|
|
|
|
check (await proofs.isProofRequired(contractId)) == false
|
|
|
|
|
|
|
|
test "supports checking whether proof is required soon":
|
|
|
|
check (await proofs.willProofBeRequired(contractId)) == false
|
|
|
|
|
|
|
|
test "retrieves proof end time":
|
|
|
|
check (await proofs.getProofEnd(contractId)) == 0.u256
|
|
|
|
|
|
|
|
test "submits proofs":
|
|
|
|
await proofs.submitProof(contractId, proof)
|
|
|
|
|
|
|
|
test "supports proof submission subscriptions":
|
2022-08-17 02:29:44 +00:00
|
|
|
var receivedIds: seq[SlotId]
|
2022-04-13 16:41:48 +00:00
|
|
|
var receivedProofs: seq[seq[byte]]
|
|
|
|
|
2022-08-17 02:29:44 +00:00
|
|
|
proc onProofSubmission(id: SlotId, proof: seq[byte]) =
|
2022-04-13 16:41:48 +00:00
|
|
|
receivedIds.add(id)
|
|
|
|
receivedProofs.add(proof)
|
|
|
|
|
|
|
|
let subscription = await proofs.subscribeProofSubmission(onProofSubmission)
|
|
|
|
|
|
|
|
await proofs.submitProof(contractId, proof)
|
|
|
|
|
|
|
|
check receivedIds == @[contractId]
|
|
|
|
check receivedProofs == @[proof]
|
|
|
|
|
|
|
|
await subscription.unsubscribe()
|
2022-09-21 02:50:11 +00:00
|
|
|
|
|
|
|
test "proof not required when slot is empty":
|
|
|
|
check not await proofs.isProofRequired(contractId)
|
|
|
|
|
|
|
|
test "proof will not be required when slot is empty":
|
|
|
|
check not await proofs.willProofBeRequired(contractId)
|
|
|
|
|
|
|
|
test "proof end is zero when slot is empty":
|
|
|
|
check (await proofs.getProofEnd(contractId)) == 0.u256
|