Skip to content

Commit b8716f1

Browse files
authored
Require passing RuntimeConfig explicitly when using makeTestDB (#7611)
* Require passing RuntimeConfig explicitly when using makeTestDB Avoid mishaps by requiring explicit passing of RuntimeConfig in tests. * Lint
1 parent 6c0e40e commit b8716f1

10 files changed

+32
-34
lines changed

tests/test_attestation_pool.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ suite "Attestation pool electra processing" & preset():
8686
validatorMonitor = newClone(ValidatorMonitor.init())
8787
dag = init(
8888
ChainDAGRef, cfg,
89-
makeTestDB(
90-
TOTAL_COMMITTEES * TARGET_COMMITTEE_SIZE * SLOTS_PER_EPOCH, cfg = cfg),
89+
cfg.makeTestDB(
90+
TOTAL_COMMITTEES * TARGET_COMMITTEE_SIZE * SLOTS_PER_EPOCH),
9191
validatorMonitor, {})
9292
taskpool = Taskpool.new()
9393
verifier {.used.} = BatchVerifier.init(rng, taskpool)

tests/test_beacon_chain_db.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ proc getTestStates(
114114
cfg: RuntimeConfig,
115115
consensusFork: ConsensusFork): seq[ref ForkedHashedBeaconState] =
116116
let
117-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
117+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
118118
validatorMonitor = newClone(ValidatorMonitor.init())
119119
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
120120
var testStates = getTestStates(dag.headState, consensusFork)
@@ -198,7 +198,7 @@ suite "Beacon chain DB" & preset():
198198

199199
template doStateTest(consensusFork: static ConsensusFork): untyped =
200200
block:
201-
let db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
201+
let db = cfg.makeTestDB(SLOTS_PER_EPOCH)
202202

203203
for state in testStates[consensusFork]:
204204
let root = state[].forky(consensusFork).root
@@ -227,7 +227,7 @@ suite "Beacon chain DB" & preset():
227227
consensusFork: static ConsensusFork): untyped =
228228
block:
229229
let
230-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
230+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
231231
stateBuffer = (consensusFork.BeaconStateRef)()
232232

233233
for state in testStates[consensusFork]:
@@ -257,7 +257,7 @@ suite "Beacon chain DB" & preset():
257257
template doRollbackTest(consensusFork: static ConsensusFork): untyped =
258258
block:
259259
var
260-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
260+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
261261
validatorMonitor = newClone(ValidatorMonitor.init())
262262
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
263263
state = ForkedHashedBeaconState.new(
@@ -380,7 +380,7 @@ suite "Beacon chain DB" & preset():
380380
blobSidecar1 = BlobSidecar(signed_block_header: blockHeader0, index: 2)
381381
blobSidecar2 = BlobSidecar(signed_block_header: blockHeader1, index: 2)
382382

383-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
383+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
384384

385385
var
386386
buf: seq[byte]
@@ -480,7 +480,7 @@ suite "Beacon chain DB" & preset():
480480
dataColumnSidecar1 = fulu.DataColumnSidecar(signed_block_header: blockHeader0, index: 2)
481481
dataColumnSidecar2 = fulu.DataColumnSidecar(signed_block_header: blockHeader1, index: 2)
482482

483-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
483+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
484484

485485
var
486486
buf: seq[byte]

tests/test_block_processor.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ suite "Block processor" & preset():
4242
res.ALTAIR_FORK_EPOCH = GENESIS_EPOCH
4343
res.BELLATRIX_FORK_EPOCH = GENESIS_EPOCH
4444
res
45-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
45+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
4646
validatorMonitor = newClone(ValidatorMonitor.init())
4747
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
4848
var

tests/test_blockchain_dag.nim

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ suite "Block pool processing" & preset():
4646
rng = HmacDrbgContext.new()
4747
cfg = defaultRuntimeConfig
4848
var
49-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
49+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
5050
validatorMonitor = newClone(ValidatorMonitor.init())
5151
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
5252
taskpool = Taskpool.new()
@@ -282,7 +282,7 @@ suite "Block pool altair processing" & preset():
282282
res.ALTAIR_FORK_EPOCH = Epoch(1)
283283
res
284284
var
285-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
285+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
286286
validatorMonitor = newClone(ValidatorMonitor.init())
287287
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
288288
taskpool = Taskpool.new()
@@ -359,7 +359,7 @@ suite "chain DAG finalization tests" & preset():
359359
rng = HmacDrbgContext.new()
360360
cfg = defaultRuntimeConfig
361361
var
362-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
362+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
363363
validatorMonitor = newClone(ValidatorMonitor.init())
364364
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
365365
taskpool = Taskpool.new()
@@ -713,7 +713,7 @@ suite "Diverging hardforks":
713713
res.ALTAIR_FORK_EPOCH = 2.Epoch
714714
res
715715
var
716-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = phase0RuntimeConfig)
716+
db = phase0RuntimeConfig.makeTestDB(SLOTS_PER_EPOCH)
717717
validatorMonitor = newClone(ValidatorMonitor.init())
718718
dag = init(ChainDAGRef, phase0RuntimeConfig, db, validatorMonitor, {})
719719
taskpool = Taskpool.new()
@@ -1170,7 +1170,7 @@ suite "Latest valid hash" & preset():
11701170
res.BELLATRIX_FORK_EPOCH = 2.Epoch
11711171
res
11721172
var
1173-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
1173+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
11741174
validatorMonitor = newClone(ValidatorMonitor.init())
11751175
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
11761176
taskpool = Taskpool.new()
@@ -1237,7 +1237,7 @@ suite "Pruning":
12371237
res.MIN_EPOCHS_FOR_BLOCK_REQUESTS = res.safeMinEpochsForBlockRequests()
12381238
doAssert res.MIN_EPOCHS_FOR_BLOCK_REQUESTS == 4
12391239
res
1240-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
1240+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
12411241
validatorMonitor = newClone(ValidatorMonitor.init())
12421242
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
12431243
tmpState = assignClone(dag.headState)
@@ -1292,7 +1292,7 @@ suite "State history":
12921292
cfg = defaultRuntimeConfig
12931293
validatorMonitor = newClone(ValidatorMonitor.init())
12941294
dag = ChainDAGRef.init(
1295-
cfg, makeTestDB(numValidators, cfg = cfg),
1295+
cfg, cfg.makeTestDB(numValidators),
12961296
validatorMonitor, {})
12971297
quarantine = newClone(Quarantine.init(dag.cfg))
12981298
rng = HmacDrbgContext.new()
@@ -1413,7 +1413,7 @@ suite "Ancestry":
14131413
cfg = defaultRuntimeConfig
14141414
validatorMonitor = newClone(ValidatorMonitor.init())
14151415
dag = ChainDAGRef.init(
1416-
cfg, makeTestDB(numValidators, cfg = cfg),
1416+
cfg, cfg.makeTestDB(numValidators),
14171417
validatorMonitor, {})
14181418
quarantine = newClone(Quarantine.init(dag.cfg))
14191419
rng = HmacDrbgContext.new()
@@ -1706,9 +1706,8 @@ template runShufflingTests(cfg: RuntimeConfig, numRandomTests: int) =
17061706
deposit_count: deposits.lenu64)
17071707
validatorMonitor = newClone(ValidatorMonitor.init())
17081708
dag = ChainDAGRef.init(
1709-
cfg, makeTestDB(
1710-
numValidators, eth1Data = Opt.some(eth1Data),
1711-
flags = {}, cfg = cfg),
1709+
cfg, cfg.makeTestDB(
1710+
numValidators, eth1Data = Opt.some(eth1Data), flags = {}),
17121711
validatorMonitor, {})
17131712
quarantine = newClone(Quarantine.init(dag.cfg))
17141713
rng = HmacDrbgContext.new()

tests/test_gossip_validation.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ suite "Gossip validation " & preset():
4444
var
4545
validatorMonitor = newClone(ValidatorMonitor.init())
4646
dag = ChainDAGRef.init(
47-
cfg, makeTestDB(SLOTS_PER_EPOCH * 3, cfg = cfg), validatorMonitor, {})
47+
cfg, cfg.makeTestDB(SLOTS_PER_EPOCH * 3), validatorMonitor, {})
4848
taskpool = Taskpool.new()
4949
verifier {.used.} = BatchVerifier.init(rng, taskpool)
5050
quarantine = newClone(Quarantine.init(dag.cfg))
@@ -307,7 +307,7 @@ suite "Gossip validation - Altair":
307307
template prepare(numValidators: Natural): untyped {.dirty.} =
308308
let
309309
dag = ChainDAGRef.init(
310-
cfg, makeTestDB(numValidators, cfg = cfg), validatorMonitor, {})
310+
cfg, cfg.makeTestDB(numValidators), validatorMonitor, {})
311311
batchCrypto = BatchCrypto.new(
312312
rng, eager = proc(): bool = false,
313313
genesis_validators_root = dag.genesis_validators_root, taskpool).expect(

tests/test_light_client.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ suite "Light client" & preset():
7979
let
8080
validatorMonitor = newClone(ValidatorMonitor.init())
8181
dag = ChainDAGRef.init(
82-
cfg, makeTestDB(num_validators, cfg = cfg), validatorMonitor, {},
82+
cfg, cfg.makeTestDB(num_validators), validatorMonitor, {},
8383
lcDataConfig = LightClientDataConfig(
8484
serve: true,
8585
importMode: LightClientDataImportMode.OnlyNew))
@@ -233,7 +233,7 @@ suite "Light client" & preset():
233233
dag.advanceToSlot(finalizedSlot, verifier, quarantine[])
234234

235235
# Initialize new DAG from checkpoint
236-
let cpDb = BeaconChainDB.new("", cfg = cfg, inMemory = true)
236+
let cpDb = BeaconChainDB.new("", cfg, inMemory = true)
237237
ChainDAGRef.preInit(cpDb, genesisState[])
238238
ChainDAGRef.preInit(cpDb, dag.headState) # dag.getForkedBlock(dag.head.bid).get)
239239
let cpDag = ChainDAGRef.init(

tests/test_light_client_processor.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ suite "Light client processor" & preset():
4343
let
4444
validatorMonitor = newClone(ValidatorMonitor.init())
4545
dag = ChainDAGRef.init(
46-
cfg, makeTestDB(numValidators, cfg = cfg), validatorMonitor, {},
46+
cfg, cfg.makeTestDB(numValidators), validatorMonitor, {},
4747
lcDataConfig = LightClientDataConfig(
4848
serve: true,
4949
importMode: LightClientDataImportMode.OnlyNew))

tests/test_statediff.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ suite "state diff tests" & preset():
4242
setup:
4343
let cfg = defaultRuntimeConfig
4444
var
45-
db = makeTestDB(SLOTS_PER_EPOCH, cfg = cfg)
45+
db = cfg.makeTestDB(SLOTS_PER_EPOCH)
4646
validatorMonitor = newClone(ValidatorMonitor.init())
4747
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
4848

tests/test_validator_change_pool.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ suite "Validator change pool testing suite":
8282
tmp
8383

8484
validatorMonitor = newClone(ValidatorMonitor.init())
85-
dag = init(
86-
ChainDAGRef, cfg, makeTestDB(SLOTS_PER_EPOCH * 3, cfg = cfg),
87-
validatorMonitor, {})
85+
dag = ChainDAGRef.init(
86+
cfg, cfg.makeTestDB(SLOTS_PER_EPOCH * 3), validatorMonitor, {})
8887
fork {.used.} = dag.forkAtEpoch(Epoch(0))
8988
genesis_validators_root = dag.genesis_validators_root
9089
pool = newClone(ValidatorChangePool.init(dag))

tests/testdbutil.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2018-2024 Status Research & Development GmbH
2+
# Copyright (c) 2018-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -21,10 +21,10 @@ from ../beacon_chain/spec/beaconstate import
2121
export beacon_chain_db, testblockutil, kvstore, kvstore_sqlite3
2222

2323
proc makeTestDB*(
24+
cfg: RuntimeConfig,
2425
validators: Natural,
2526
eth1Data = Opt.none(Eth1Data),
26-
flags: UpdateFlags = {},
27-
cfg = defaultRuntimeConfig): BeaconChainDB =
27+
flags: UpdateFlags = {}): BeaconChainDB =
2828
# Blob support requires DENEB_FORK_EPOCH != FAR_FUTURE_EPOCH
2929
# Data column support requires FULU_FORK_EPOCH != FAR_FUTURE_EPOCH
3030
var cfg = cfg
@@ -63,7 +63,7 @@ proc makeTestDB*(
6363
hash_tree_root(default(BeaconBlockBody(consensusFork)))
6464
forkyState.root = hash_tree_root(forkyState.data)
6565

66-
result = BeaconChainDB.new("", cfg = cfg, inMemory = true)
66+
result = BeaconChainDB.new("", cfg, inMemory = true)
6767
ChainDAGRef.preInit(result, genState[])
6868

6969
proc getEarliestInvalidBlockRoot*(
@@ -103,4 +103,4 @@ proc getEarliestInvalidBlockRoot*(
103103
break
104104
curBlck = curBlck.parent
105105

106-
curBlck.root
106+
curBlck.root

0 commit comments

Comments
 (0)