nimbus-eth1/hive_integration/nodocker/consensus/consensus_sim.nim

94 lines
2.5 KiB
Nim
Raw Normal View History

# Nimbus
# Copyright (c) 2021-2024 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-12-02 04:39:12 +00:00
stew/byteutils,
results,
2022-12-02 04:39:12 +00:00
chronicles,
../../../nimbus/core/chain,
2022-12-02 04:39:12 +00:00
../../../nimbus/core/block_import,
../../../nimbus/common,
../../../nimbus/core/eip4844,
2022-04-20 07:57:50 +00:00
../sim_utils,
./extract_consensus_data
2022-04-20 07:57:50 +00:00
proc processChainData(cd: ChainData): TestStatus =
let
networkId = NetworkId(cd.params.config.chainId)
com = CommonRef.new(newCoreDbRef DefaultDbMemory,
2022-04-20 07:57:50 +00:00
networkId,
cd.params
)
let c = newForkedChain(com, com.genesisHeader)
for bytes in cd.blocksRlp:
# ignore return value here
# because good blocks maybe interleaved with
# bad blocks
discard importRlpBlocks(bytes, c, finalize = true)
2022-12-02 04:39:12 +00:00
let head = com.db.getCanonicalHead()
let blockHash = "0x" & head.blockHash.data.toHex
2022-04-20 07:57:50 +00:00
if blockHash == cd.lastBlockHash:
TestStatus.OK
else:
2022-12-02 04:39:12 +00:00
trace "block hash not equal",
got=blockHash,
number=head.number,
2022-12-02 04:39:12 +00:00
expected=cd.lastBlockHash
2022-04-20 07:57:50 +00:00
TestStatus.Failed
# except loopMul, all other tests are related to total difficulty
# which is not supported in ForkedChain
const unsupportedTests = [
"lotsOfBranchesOverrideAtTheMiddle.json",
"sideChainWithMoreTransactions.json",
"uncleBlockAtBlock3afterBlock4.json",
"CallContractFromNotBestBlock.json",
"ChainAtoChainB_difficultyB.json",
"ForkStressTest.json",
"blockChainFrontierWithLargerTDvsHomesteadBlockchain.json",
"blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json",
"lotsOfLeafs.json",
"loopMul.json"
]
proc main() =
const basePath = "tests/fixtures/eth_tests/BlockchainTests"
2022-04-20 07:57:50 +00:00
var stat: SimStat
let start = getTime()
let res = loadKzgTrustedSetup()
if res.isErr:
echo "FATAL: ", res.error
quit(QuitFailure)
2022-04-20 07:57:50 +00:00
for fileName in walkDirRec(basePath):
if not fileName.endsWith(".json"):
continue
let (_, name) = fileName.splitPath()
if name in unsupportedTests:
let n = json.parseFile(fileName)
stat.skipped += n.len
continue
2022-04-20 07:57:50 +00:00
let n = json.parseFile(fileName)
for caseName, unit in n:
2022-04-20 07:57:50 +00:00
let cd = extractChainData(unit)
let status = processChainData(cd)
stat.inc(caseName, status)
2022-04-20 07:57:50 +00:00
let elpd = getTime() - start
print(stat, elpd, "consensus")
main()