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
|
2022-04-20 07:57:50 +00:00
|
|
|
std/[os, json, strutils, times],
|
2022-10-20 08:34:59 +00:00
|
|
|
eth/[common, trie/db], stew/byteutils,
|
2021-05-17 11:35:16 +00:00
|
|
|
../../../nimbus/db/db_chain,
|
2022-04-20 07:57:50 +00:00
|
|
|
../../../nimbus/[genesis, chain_config, conf_utils],
|
|
|
|
../sim_utils,
|
|
|
|
./extract_consensus_data
|
2021-05-17 11:35:16 +00:00
|
|
|
|
2022-04-20 07:57:50 +00:00
|
|
|
proc processChainData(cd: ChainData): TestStatus =
|
2021-05-17 11:35:16 +00:00
|
|
|
let
|
2022-11-25 05:26:29 +00:00
|
|
|
networkId = NetworkId(cd.params.config.chainId)
|
2022-04-08 04:54:11 +00:00
|
|
|
chainDB = newBaseChainDB(newMemoryDB(),
|
2021-05-17 11:35:16 +00:00
|
|
|
pruneTrie = false,
|
2022-04-20 07:57:50 +00:00
|
|
|
networkId,
|
2022-11-25 05:26:29 +00:00
|
|
|
cd.params
|
2021-05-17 11:35:16 +00:00
|
|
|
)
|
|
|
|
|
2021-09-08 13:28:17 +00:00
|
|
|
initializeEmptyDb(chainDB)
|
2022-04-20 07:57:50 +00:00
|
|
|
discard importRlpBlock(cd.blocksRlp, chainDB, "consensus_sim")
|
2021-05-17 11:35:16 +00:00
|
|
|
let head = chainDB.getCanonicalHead()
|
|
|
|
let blockHash = "0x" & head.blockHash.data.toHex
|
2022-04-20 07:57:50 +00:00
|
|
|
if blockHash == cd.lastBlockHash:
|
|
|
|
TestStatus.OK
|
|
|
|
else:
|
|
|
|
TestStatus.Failed
|
2021-05-17 11:35:16 +00:00
|
|
|
|
|
|
|
proc main() =
|
2022-04-20 07:57:50 +00:00
|
|
|
const basePath = "tests" / "fixtures" / "eth_tests" / "BlockchainTests"
|
|
|
|
var stat: SimStat
|
|
|
|
let start = getTime()
|
|
|
|
|
|
|
|
for fileName in walkDirRec(basePath):
|
|
|
|
if not fileName.endsWith(".json"):
|
|
|
|
continue
|
|
|
|
|
|
|
|
let n = json.parseFile(fileName)
|
|
|
|
for name, unit in n:
|
|
|
|
if "loopMul" in name:
|
|
|
|
inc stat.skipped
|
|
|
|
continue
|
|
|
|
|
|
|
|
let cd = extractChainData(unit)
|
|
|
|
let status = processChainData(cd)
|
|
|
|
stat.inc(name, status)
|
|
|
|
|
|
|
|
let elpd = getTime() - start
|
|
|
|
print(stat, elpd, "consensus")
|
2021-05-17 11:35:16 +00:00
|
|
|
|
|
|
|
main()
|