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-06-22 16:52:31 +00:00
|
|
|
std/[os, parseopt, strformat, json],
|
|
|
|
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) =
|
|
|
|
var msg: string
|
|
|
|
var opt = initOptParser("--customnetwork:" & genesisFile)
|
|
|
|
let res = processArguments(msg, opt)
|
|
|
|
if res != Success:
|
|
|
|
echo msg
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
|
let
|
|
|
|
conf = getConfiguration()
|
|
|
|
chainDB = newBaseChainDB(newMemoryDb(),
|
|
|
|
pruneTrie = false,
|
2021-05-20 06:01:57 +00:00
|
|
|
conf.net.networkId
|
2021-05-17 11:35:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
initializeEmptyDb(chainDB)
|
|
|
|
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()
|