2021-05-17 11:35:16 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
|
|
|
import
|
2021-09-11 14:58:01 +00:00
|
|
|
std/[os, strformat, json],
|
2021-06-22 16:52:31 +00:00
|
|
|
eth/[common, trie/db], stew/byteutils,
|
2021-05-17 11:35:16 +00:00
|
|
|
../../../nimbus/db/db_chain,
|
|
|
|
../../../nimbus/[genesis, config, conf_utils],
|
|
|
|
../sim_utils
|
|
|
|
|
|
|
|
proc processNode(genesisFile, chainFile,
|
|
|
|
lastBlockHash: string, testStatusIMPL: var TestStatus) =
|
|
|
|
|
|
|
|
let
|
2021-09-11 14:58:01 +00:00
|
|
|
conf = makeConfig(@["--customnetwork:" & genesisFile])
|
2021-05-17 11:35:16 +00:00
|
|
|
chainDB = newBaseChainDB(newMemoryDb(),
|
|
|
|
pruneTrie = false,
|
2021-09-11 14:58:01 +00:00
|
|
|
conf.networkId.get,
|
|
|
|
conf.customNetwork.get()
|
2021-05-17 11:35:16 +00:00
|
|
|
)
|
|
|
|
|
2021-09-08 13:28:17 +00:00
|
|
|
initializeEmptyDb(chainDB)
|
2021-05-17 11:35:16 +00:00
|
|
|
discard importRlpBlock(chainFile, chainDB)
|
|
|
|
let head = chainDB.getCanonicalHead()
|
|
|
|
let blockHash = "0x" & head.blockHash.data.toHex
|
|
|
|
check blockHash == lastBlockHash
|
|
|
|
|
|
|
|
proc main() =
|
|
|
|
let caseFolder = if paramCount() == 0:
|
|
|
|
"consensus_data"
|
|
|
|
else:
|
|
|
|
paramStr(1)
|
|
|
|
|
2021-06-22 16:52:31 +00:00
|
|
|
if not caseFolder.dirExists:
|
|
|
|
# Handy early error message and stop directive
|
|
|
|
let progname = getAppFilename().extractFilename
|
|
|
|
quit(&"*** {progname}: Not a case folder: {caseFolder}")
|
|
|
|
|
2021-05-17 11:35:16 +00:00
|
|
|
runTest("Consensus", caseFolder):
|
2021-06-22 16:52:31 +00:00
|
|
|
# Variable `fileName` is injected by `runTest()`
|
2021-05-17 11:35:16 +00:00
|
|
|
let node = parseFile(fileName)
|
|
|
|
processNode(fileName, node["chainfile"].getStr,
|
|
|
|
node["lastblockhash"].getStr, testStatusIMPL)
|
|
|
|
|
|
|
|
main()
|