diff --git a/.github/workflows/docker-dist-tests.yml b/.github/workflows/docker-dist-tests.yml index e6e0973b..5ae2e30a 100644 --- a/.github/workflows/docker-dist-tests.yml +++ b/.github/workflows/docker-dist-tests.yml @@ -24,7 +24,7 @@ jobs: name: Build and Push uses: ./.github/workflows/docker-reusable.yml with: - nimflags: '-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_simulated_proof_failures -d:codex_enable_log_counter=true' + nimflags: '-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_use_hardhat=false -d:codex_enable_log_counter=true' nat_ip_auto: true tag_latest: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/') }} tag_suffix: dist-tests diff --git a/build.nims b/build.nims index 037ecd09..568b16f0 100644 --- a/build.nims +++ b/build.nims @@ -25,13 +25,13 @@ task codex, "build codex binary": buildBinary "codex", params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE" task testCodex, "Build & run Codex tests": - test "testCodex", params = "-d:codex_testing=true" + test "testCodex", params = "-d:codex_enable_proof_failures=true -d:codex_use_hardhat=true" task testContracts, "Build & run Codex Contract tests": test "testContracts" task testIntegration, "Run integration tests": - buildBinary "codex", params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE -d:codex_testing=true" + buildBinary "codex", params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE -d:codex_enable_proof_failures=true -d:codex_use_hardhat=true" test "testIntegration" task build, "build codex binary": diff --git a/codex/codex.nim b/codex/codex.nim index 31ff6053..4fc0f922 100644 --- a/codex/codex.nim +++ b/codex/codex.nim @@ -118,7 +118,7 @@ proc bootstrapInteractions( if config.persistence: # This is used for simulation purposes. Normal nodes won't be compiled with this flag # and hence the proof failure will always be 0. - when codex_testing: + when codex_enable_proof_failures: let proofFailures = config.simulateProofFailures if proofFailures > 0: warn "Enabling proof failure simulation!" diff --git a/codex/conf.nim b/codex/conf.nim index 019f0c41..4a0e70f4 100644 --- a/codex/conf.nim +++ b/codex/conf.nim @@ -44,7 +44,8 @@ export net, DefaultQuotaBytes, DefaultBlockTtl, DefaultBlockMaintenanceInterval, const codex_enable_api_debug_peers* {.booldefine.} = false - codex_testing* {.booldefine.} = false + codex_enable_proof_failures* {.booldefine.} = false + codex_use_hardhat* {.booldefine.} = false codex_enable_log_counter* {.booldefine.} = false type diff --git a/codex/contracts/clock.nim b/codex/contracts/clock.nim index 4c6b5fd5..26d2d263 100644 --- a/codex/contracts/clock.nim +++ b/codex/contracts/clock.nim @@ -23,7 +23,6 @@ proc new*(_: type OnChainClock, provider: Provider): OnChainClock = method start*(clock: OnChainClock) {.async.} = if clock.started: return - clock.started = true proc onBlock(blck: Block) {.upraises:[].} = clock.lastBlockTime = blck.timestamp @@ -33,16 +32,17 @@ method start*(clock: OnChainClock) {.async.} = onBlock(latestBlock) clock.subscription = await clock.provider.subscribe(onBlock) + clock.started = true method stop*(clock: OnChainClock) {.async.} = if not clock.started: return - clock.started = false await clock.subscription.unsubscribe() + clock.started = false method now*(clock: OnChainClock): SecondsSince1970 = - when codex_testing: + when codex_use_hardhat: # hardhat's latest block.timestamp is usually 1s behind the block timestamp # in the newHeads event. When testing, always return the latest block. try: @@ -56,6 +56,7 @@ method now*(clock: OnChainClock): SecondsSince1970 = return clock.lastBlockTime.truncate(int64) else: + doAssert clock.started, "clock should be started before calling now()" trace "using cached block timestamp (newHeads) for clock.now", timestamp = clock.lastBlockTime.truncate(int64) return clock.lastBlockTime.truncate(int64) diff --git a/codex/sales/states/filled.nim b/codex/sales/states/filled.nim index 4fe551fd..c5bc4c27 100644 --- a/codex/sales/states/filled.nim +++ b/codex/sales/states/filled.nim @@ -51,7 +51,7 @@ method run*(state: SaleFilled, machine: Machine): Future[?State] {.async.} = if err =? (await onExpiryUpdate(request.content.cid, requestEnd)).errorOption: return some State(SaleErrored(error: err)) - when codex_testing: + when codex_enable_proof_failures: if context.simulateProofFailures > 0: info "Proving with failure rate", rate = context.simulateProofFailures return some State(SaleProvingSimulated(failEveryNProofs: context.simulateProofFailures)) diff --git a/codex/sales/states/provingsimulated.nim b/codex/sales/states/provingsimulated.nim index b0ae7206..f5753cf2 100644 --- a/codex/sales/states/provingsimulated.nim +++ b/codex/sales/states/provingsimulated.nim @@ -1,5 +1,5 @@ import ../../conf -when codex_testing: +when codex_enable_proof_failures: import std/strutils import pkg/chronicles import pkg/stint diff --git a/config.nims b/config.nims index 3acc58b5..a93d958c 100644 --- a/config.nims +++ b/config.nims @@ -95,8 +95,6 @@ if not defined(macosx): --define:nimStackTraceOverride switch("import", "libbacktrace") -switch("define", "codex_testing=true") - # `switch("warning[CaseTransition]", "off")` fails with "Error: invalid command line option: '--warning[CaseTransition]'" switch("warning", "CaseTransition:off")