2021-05-17 11:35:16 +00:00
|
|
|
# Nimbus
|
2024-02-23 09:17:24 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2021-05-17 11:35:16 +00:00
|
|
|
# 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,
|
2024-03-22 05:49:26 +00:00
|
|
|
results,
|
2022-12-02 04:39:12 +00:00
|
|
|
chronicles,
|
|
|
|
../../../nimbus/core/block_import,
|
|
|
|
../../../nimbus/common,
|
2024-03-22 05:49:26 +00:00
|
|
|
../../../nimbus/core/eip4844,
|
2022-04-20 07:57:50 +00:00
|
|
|
../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)
|
2024-02-23 09:17:24 +00:00
|
|
|
com = CommonRef.new(newCoreDbRef DefaultDbMemory,
|
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
|
|
|
)
|
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
com.initializeEmptyDb()
|
2023-06-27 00:30:05 +00:00
|
|
|
|
|
|
|
for bytes in cd.blocksRlp:
|
|
|
|
# ignore return value here
|
|
|
|
# because good blocks maybe interleaved with
|
|
|
|
# bad blocks
|
|
|
|
discard importRlpBlock(bytes, com, "consensus_sim")
|
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
let head = com.db.getCanonicalHead()
|
2021-05-17 11:35:16 +00:00
|
|
|
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,
|
2024-06-14 07:31:08 +00:00
|
|
|
number=head.number,
|
2022-12-02 04:39:12 +00:00
|
|
|
expected=cd.lastBlockHash
|
2022-04-20 07:57:50 +00:00
|
|
|
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()
|
|
|
|
|
2024-03-22 05:49:26 +00:00
|
|
|
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 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()
|