mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-19 17:30:02 +00:00
03fa370624
* Add Proving object, which maintains contract id's to watch * [proving] invoke callback when proof is required # Conflicts: # dagger/por/timing/periods.nim # dagger/por/timing/prooftiming.nim * [proving] check proof requirements for all our contracts # Conflicts: # tests/dagger/helpers/mockprooftiming.nim * Update vendor/dagger-contracts * [proving] call onProofRequired() when proof is required soon * [proving] stop checking contracts that have ended * [proving] Remove duplicated funcs * [proving] Implement ProofTiming on top of smart contract * [proving] Fix race condition in waitUntilNextPeriod() Sometimes waitUntilNextPeriod would take a while to determine the current period, leading to unexpected results. Splits waitUntilNextPeriod() into getCurrentPeriod() and waitUntilPeriod(), to ensure that we're really waiting for the period that we think we're waiting for.
48 lines
1.4 KiB
Nim
48 lines
1.4 KiB
Nim
import ./ethertest
|
|
import dagger/contracts
|
|
import ./examples
|
|
import ./time
|
|
|
|
ethersuite "On-Chain Proof Timing":
|
|
|
|
var timing: OnChainProofTiming
|
|
var storage: Storage
|
|
|
|
setup:
|
|
let deployment = deployment()
|
|
storage = Storage.new(!deployment.address(Storage), provider)
|
|
timing = OnChainProofTiming.new(storage)
|
|
|
|
test "can retrieve proof periodicity":
|
|
let periodicity = await timing.periodicity()
|
|
let periodLength = await storage.proofPeriod()
|
|
check periodicity.seconds == periodLength
|
|
|
|
test "supports waiting until next period":
|
|
let periodicity = await timing.periodicity()
|
|
let currentPeriod = await timing.getCurrentPeriod()
|
|
|
|
let pollInterval = 200.milliseconds
|
|
timing.pollInterval = pollInterval
|
|
|
|
proc waitForPoll {.async.} =
|
|
await sleepAsync(pollInterval * 2)
|
|
|
|
let future = timing.waitUntilPeriod(currentPeriod + 1)
|
|
|
|
check not future.completed
|
|
|
|
await provider.advanceTimeTo(periodicity.periodEnd(currentPeriod))
|
|
await waitForPoll()
|
|
|
|
check future.completed
|
|
|
|
test "supports checking whether proof is required now":
|
|
check (await timing.isProofRequired(ContractId.example)) == false
|
|
|
|
test "supports checking whether proof is required soon":
|
|
check (await timing.willProofBeRequired(ContractId.example)) == false
|
|
|
|
test "retrieves proof end time":
|
|
check (await timing.getProofEnd(ContractId.example)) == 0.u256
|