mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-10 04:55:40 +00:00
6df5a7cf54
- 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`
52 lines
1.4 KiB
Nim
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()
|