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 =
|
||||
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)
|
||||
doAssert s.isOk # TODO Handle this in a better way
|
||||
|
||||
let sqliteStore = SqStoreRef.init(dir, "nbc", Keyspaces).expect(
|
||||
"working database")
|
||||
|
||||
T(backend: kvStore sqliteStore,
|
||||
deposits: createSeq(sqliteStore, dir, "deposits", DepositData),
|
||||
validators: createSeq(sqliteStore, dir, "validators", ImmutableValidatorData),
|
||||
validatorsByKey: createMap(sqliteStore, int validatorIndexFromPubKey,
|
||||
ValidatorPubKey, ValidatorIndex))
|
||||
if inMemory:
|
||||
T(backend: kvStore MemStoreRef.init())
|
||||
else:
|
||||
T(backend: kvStore sqliteStore,
|
||||
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] =
|
||||
try:
|
||||
|
|
|
@ -38,14 +38,14 @@ func withDigest(blck: TrustedBeaconBlock): TrustedSignedBeaconBlock =
|
|||
suiteReport "Beacon chain DB" & preset():
|
||||
wrappedTimedTest "empty database" & preset():
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
db = init(BeaconChainDB, "", inMemory = true)
|
||||
check:
|
||||
db.getStateRef(Eth2Digest()).isNil
|
||||
db.getBlock(Eth2Digest()).isNone
|
||||
|
||||
wrappedTimedTest "sanity check blocks" & preset():
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
db = init(BeaconChainDB, "", inMemory = true)
|
||||
|
||||
let
|
||||
signedBlock = withDigest(TrustedBeaconBlock())
|
||||
|
@ -70,7 +70,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||
|
||||
wrappedTimedTest "sanity check states" & preset():
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
db = init(BeaconChainDB, "", inMemory = true)
|
||||
|
||||
let
|
||||
state = BeaconStateRef()
|
||||
|
@ -86,7 +86,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||
|
||||
wrappedTimedTest "find ancestors" & preset():
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
db = init(BeaconChainDB, "", inMemory = true)
|
||||
|
||||
let
|
||||
a0 = withDigest(
|
||||
|
@ -120,7 +120,7 @@ suiteReport "Beacon chain DB" & preset():
|
|||
# serialization where an all-zero default-initialized bls signature could
|
||||
# not be deserialized because the deserialization was too strict.
|
||||
var
|
||||
db = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
db = init(BeaconChainDB, "", inMemory = true)
|
||||
|
||||
let
|
||||
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.
|
||||
|
||||
import
|
||||
algorithm, strformat, stats, times, tables, std/monotimes, stew/endians2,
|
||||
os, algorithm, strformat, stats, times, tables, std/monotimes, stew/endians2,
|
||||
testutils/markdown_reports, chronicles,
|
||||
../beacon_chain/[beacon_chain_db, extras, ssz],
|
||||
../beacon_chain/spec/[digest, beaconstate, datatypes, presets],
|
||||
../beacon_chain/block_pools/chain_dag,
|
||||
eth/db/kvstore,
|
||||
eth/db/[kvstore, kvstore_sqlite3],
|
||||
testblockutil
|
||||
|
||||
type
|
||||
|
@ -98,7 +98,7 @@ template timedTest*(name, body) =
|
|||
testTimes.add (f, name)
|
||||
|
||||
proc makeTestDB*(tailState: BeaconState, tailBlock: SignedBeaconBlock): BeaconChainDB =
|
||||
result = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
result = init(BeaconChainDB, "", inMemory = true)
|
||||
ChainDAGRef.preInit(result, tailState, tailState, tailBlock)
|
||||
|
||||
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
||||
|
|
Loading…
Reference in New Issue