split codex_testing compilation flag

split codex_testing compilation flag into two flags:
1. codex_enable_proof_failures - used for simulating proof failures in the tests
2. codex_use_hardhat - used for a workaround to a Hardhat bug that obtains the current block for clock.now in the OnChainClock
This commit is contained in:
Eric 2023-12-04 13:47:50 +11:00
parent 3e4a585fa6
commit fd2721ce97
No known key found for this signature in database
8 changed files with 12 additions and 12 deletions

View File

@ -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

View File

@ -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":

View File

@ -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!"

View File

@ -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

View File

@ -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)

View File

@ -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))

View File

@ -1,5 +1,5 @@
import ../../conf
when codex_testing:
when codex_enable_proof_failures:
import std/strutils
import pkg/chronicles
import pkg/stint

View File

@ -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")