nim-codex/tests/contracts/testProofs.nim
Eric Mastro 6df5a7cf54 [chore] clean up array[32, byte] types
- rename `ContractId` to `SlotId`
- add `RequestId`, `PurchaseId`, `Nonce` types as aliases of `array[32, byte]`
- rename `Proving.contracts` to `Proving.slots`
- change signatures of `isSlotCancelled` and `isCancelled` to use `SlotId` and `RequestId` types, respectively.
- change all references to `RequestId`, `SlotId`, and `PurchaseId`
2022-08-26 13:29:09 +10:00

52 lines
1.4 KiB
Nim

import codex/contracts
import ../ethertest
import ./examples
import ./time
ethersuite "On-Chain Proofs":
let contractId = SlotId.example
let proof = seq[byte].example
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":
var receivedIds: seq[SlotId]
var receivedProofs: seq[seq[byte]]
proc onProofSubmission(id: SlotId, proof: seq[byte]) =
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()