mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
Fix the test suite
This commit is contained in:
parent
f0892ce934
commit
4d66914f5a
@ -167,18 +167,21 @@ proc insert*[K, V](m: DbMap[K, V], key: K, value: V) =
|
|||||||
proc contains*[K, V](m: DbMap[K, V], key: K): bool =
|
proc contains*[K, V](m: DbMap[K, V], key: K): bool =
|
||||||
contains(m.db, SSZ.encode key).expect("working database")
|
contains(m.db, SSZ.encode key).expect("working database")
|
||||||
|
|
||||||
proc init*(T: type BeaconChainDB, dir: string): BeaconChainDB =
|
proc init*(T: type BeaconChainDB, dir: string, inMemory = false): BeaconChainDB =
|
||||||
let s = createPath(dir, 0o750)
|
let s = createPath(dir, 0o750)
|
||||||
doAssert s.isOk # TODO Handle this in a better way
|
doAssert s.isOk # TODO Handle this in a better way
|
||||||
|
|
||||||
let sqliteStore = SqStoreRef.init(dir, "nbc", Keyspaces).expect(
|
let sqliteStore = SqStoreRef.init(dir, "nbc", Keyspaces).expect(
|
||||||
"working database")
|
"working database")
|
||||||
|
|
||||||
T(backend: kvStore sqliteStore,
|
if inMemory:
|
||||||
deposits: createSeq(sqliteStore, dir, "deposits", DepositData),
|
T(backend: kvStore MemStoreRef.init())
|
||||||
validators: createSeq(sqliteStore, dir, "validators", ImmutableValidatorData),
|
else:
|
||||||
validatorsByKey: createMap(sqliteStore, int validatorIndexFromPubKey,
|
T(backend: kvStore sqliteStore,
|
||||||
ValidatorPubKey, ValidatorIndex))
|
deposits: createSeq(sqliteStore, dir, "deposits", DepositData),
|
||||||
|
validators: createSeq(sqliteStore, dir, "validators", ImmutableValidatorData),
|
||||||
|
validatorsByKey: createMap(sqliteStore, int validatorIndexFromPubKey,
|
||||||
|
ValidatorPubKey, ValidatorIndex))
|
||||||
|
|
||||||
proc snappyEncode(inp: openArray[byte]): seq[byte] =
|
proc snappyEncode(inp: openArray[byte]): seq[byte] =
|
||||||
try:
|
try:
|
||||||
|
@ -38,14 +38,14 @@ func withDigest(blck: TrustedBeaconBlock): TrustedSignedBeaconBlock =
|
|||||||
suiteReport "Beacon chain DB" & preset():
|
suiteReport "Beacon chain DB" & preset():
|
||||||
wrappedTimedTest "empty database" & preset():
|
wrappedTimedTest "empty database" & preset():
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, "", inMemory = true)
|
||||||
check:
|
check:
|
||||||
db.getStateRef(Eth2Digest()).isNil
|
db.getStateRef(Eth2Digest()).isNil
|
||||||
db.getBlock(Eth2Digest()).isNone
|
db.getBlock(Eth2Digest()).isNone
|
||||||
|
|
||||||
wrappedTimedTest "sanity check blocks" & preset():
|
wrappedTimedTest "sanity check blocks" & preset():
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, "", inMemory = true)
|
||||||
|
|
||||||
let
|
let
|
||||||
signedBlock = withDigest(TrustedBeaconBlock())
|
signedBlock = withDigest(TrustedBeaconBlock())
|
||||||
@ -70,7 +70,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||||||
|
|
||||||
wrappedTimedTest "sanity check states" & preset():
|
wrappedTimedTest "sanity check states" & preset():
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, "", inMemory = true)
|
||||||
|
|
||||||
let
|
let
|
||||||
state = BeaconStateRef()
|
state = BeaconStateRef()
|
||||||
@ -86,7 +86,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||||||
|
|
||||||
wrappedTimedTest "find ancestors" & preset():
|
wrappedTimedTest "find ancestors" & preset():
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, "", inMemory = true)
|
||||||
|
|
||||||
let
|
let
|
||||||
a0 = withDigest(
|
a0 = withDigest(
|
||||||
@ -120,7 +120,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||||||
# serialization where an all-zero default-initialized bls signature could
|
# serialization where an all-zero default-initialized bls signature could
|
||||||
# not be deserialized because the deserialization was too strict.
|
# not be deserialized because the deserialization was too strict.
|
||||||
var
|
var
|
||||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
db = init(BeaconChainDB, "", inMemory = true)
|
||||||
|
|
||||||
let
|
let
|
||||||
state = initialize_beacon_state_from_eth1(
|
state = initialize_beacon_state_from_eth1(
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
algorithm, strformat, stats, times, tables, std/monotimes, stew/endians2,
|
os, algorithm, strformat, stats, times, tables, std/monotimes, stew/endians2,
|
||||||
testutils/markdown_reports, chronicles,
|
testutils/markdown_reports, chronicles,
|
||||||
../beacon_chain/[beacon_chain_db, extras, ssz],
|
../beacon_chain/[beacon_chain_db, extras, ssz],
|
||||||
../beacon_chain/spec/[digest, beaconstate, datatypes, presets],
|
../beacon_chain/spec/[digest, beaconstate, datatypes, presets],
|
||||||
../beacon_chain/block_pools/chain_dag,
|
../beacon_chain/block_pools/chain_dag,
|
||||||
eth/db/kvstore,
|
eth/db/[kvstore, kvstore_sqlite3],
|
||||||
testblockutil
|
testblockutil
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -98,7 +98,7 @@ template timedTest*(name, body) =
|
|||||||
testTimes.add (f, name)
|
testTimes.add (f, name)
|
||||||
|
|
||||||
proc makeTestDB*(tailState: BeaconState, tailBlock: SignedBeaconBlock): BeaconChainDB =
|
proc makeTestDB*(tailState: BeaconState, tailBlock: SignedBeaconBlock): BeaconChainDB =
|
||||||
result = init(BeaconChainDB, kvStore MemStoreRef.init())
|
result = init(BeaconChainDB, "", inMemory = true)
|
||||||
ChainDAGRef.preInit(result, tailState, tailState, tailBlock)
|
ChainDAGRef.preInit(result, tailState, tailState, tailBlock)
|
||||||
|
|
||||||
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user