mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-28 20:00:43 +00:00
* Use unittest2 test runner Since upgrading to unittest2, the test runner prints the command line to re-run a failed test - this however relies on actually using the unittest2 command line runner. Previously, test files were assigned numbers - with the unittest2 runner, tests are run using suite/category names instead, like so: ``` # run the Genesis suite build/all_tests "Genesis::`` # run all tests with "blsMapG1" in the name build/all_tests "blsMapG1*" # run tests verbosely build/all_tests -v ``` A reasonable follow-up here would be to review the suite names to make them easier to run :) * lint * easier-to-compare test order * bump unittest2 (also the repo)
98 lines
2.8 KiB
Nim
98 lines
2.8 KiB
Nim
# Nimbus
|
|
# Copyright (c) 2019-2025 Status Research & Development GmbH
|
|
# Licensed under either of
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
# http://opensource.org/licenses/MIT)
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
# according to those terms.
|
|
|
|
import
|
|
std/[json, os, tables, strutils],
|
|
unittest2,
|
|
eth/rlp,
|
|
./test_helpers,
|
|
eth/common/transaction_utils,
|
|
../tools/common/helpers as chp,
|
|
../execution_chain/db/core_db,
|
|
../execution_chain/common/common,
|
|
../execution_chain/transaction,
|
|
../execution_chain/core/validate,
|
|
../execution_chain/utils/utils
|
|
|
|
const
|
|
FIXTURE_FORK_SKIPS = ["_info", "rlp", "Constantinople"]
|
|
|
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
|
|
|
proc transactionJsonMain*() =
|
|
suite "Transactions tests":
|
|
jsonTest("eth_tests" / "TransactionTests", "TransactionTests", testFixture)
|
|
|
|
transactionJsonMain()
|
|
|
|
proc txHash(tx: Transaction): string =
|
|
rlpHash(tx).toHex()
|
|
|
|
proc testTxByFork(tx: Transaction, forkData: JsonNode, forkName: string, testStatusIMPL: var TestStatus) =
|
|
let
|
|
config = getChainConfig(forkName)
|
|
memDB = newCoreDbRef DefaultDbMemory
|
|
com = CommonRef.new(memDB, nil, config)
|
|
|
|
validateTxBasic(com, tx, nameToFork[forkName]).isOkOr:
|
|
return
|
|
|
|
if forkData.len > 0 and "sender" in forkData:
|
|
let sender = Address.fromHex(forkData["sender"].getStr)
|
|
check "hash" in forkData
|
|
check tx.txHash == forkData["hash"].getStr
|
|
check tx.recoverSender().expect("valid signature") == sender
|
|
|
|
func noHash(fixture: JsonNode): bool =
|
|
result = true
|
|
for forkName, forkData in fixture:
|
|
if forkName notin FIXTURE_FORK_SKIPS:
|
|
if forkData.len == 0: return
|
|
if "hash" in forkData: return false
|
|
|
|
# nimbus rlp cannot allow type mismatch
|
|
# e.g. uint256 value put into int64
|
|
# so we skip noHash check. this behavior
|
|
# is different compared to py-evm
|
|
const SKIP_TITLES = [
|
|
"TransactionWithGasLimitxPriceOverflow",
|
|
"TransactionWithHighNonce256",
|
|
"TransactionWithHighGasPrice",
|
|
"V_equals38"
|
|
]
|
|
|
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
|
var
|
|
title: string
|
|
rlpData: seq[byte]
|
|
tx: Transaction
|
|
|
|
for key, fixture in node:
|
|
title = key
|
|
|
|
try:
|
|
rlpData = safeHexToSeqByte(fixture["rlp"].getStr)
|
|
except ValueError:
|
|
# bad rlp bytes
|
|
check noHash(fixture)
|
|
return
|
|
|
|
try:
|
|
tx = rlp.decode(rlpData, Transaction)
|
|
except RlpTypeMismatch, MalformedRlpError, UnsupportedRlpError:
|
|
if title in SKIP_TITLES:
|
|
return
|
|
check noHash(fixture)
|
|
return
|
|
|
|
for forkName, fork in fixture:
|
|
if forkName notin FIXTURE_FORK_SKIPS:
|
|
testTxByFork(tx, fork, forkName, testStatusIMPL)
|