mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-10 20:36:31 +00:00
221e6c9e2f
* Nimbus folder environment update details: * Integrated `CoreDbRef` for the sources in the `nimbus` sub-folder. * The `nimbus` program does not compile yet as it needs the updates in the parallel `stateless` sub-folder. * Stateless environment update details: * Integrated `CoreDbRef` for the sources in the `stateless` sub-folder. * The `nimbus` program compiles now. * Premix environment update details: * Integrated `CoreDbRef` for the sources in the `premix` sub-folder. * Fluffy environment update details: * Integrated `CoreDbRef` for the sources in the `fluffy` sub-folder. * Tools environment update details: * Integrated `CoreDbRef` for the sources in the `tools` sub-folder. * Nodocker environment update details: * Integrated `CoreDbRef` for the sources in the `hive_integration/nodocker` sub-folder. * Tests environment update details: * Integrated `CoreDbRef` for the sources in the `tests` sub-folder. * The unit tests compile and run cleanly now. * Generalise `CoreDbRef` to any `select_backend` supported database why: Generalisation was just missed due to overcoming some compiler oddity which was tied to rocksdb for testing. * Suppress compiler warning for `newChainDB()` why: Warning was added to this function which must be wrapped so that any `CatchableError` is re-raised as `Defect`. * Split off persistent `CoreDbRef` constructor into separate file why: This allows to compile a memory only database version without linking the backend library. * Use memory `CoreDbRef` database by default detail: Persistent DB constructor needs to import `db/core_db/persistent why: Most tests use memory DB anyway. This avoids linking `-lrocksdb` or any other backend by default. * fix `toLegacyBackend()` availability check why: got garbled after memory/persistent split. * Clarify raw access to MPT for snap sync handler why: Logically, `kvt` is not the raw access for the hexary trie (although this holds for the legacy database)
81 lines
2.1 KiB
Nim
81 lines
2.1 KiB
Nim
import
|
|
std/[json, os, tables, strutils],
|
|
unittest2,
|
|
eth/rlp,
|
|
./test_helpers,
|
|
../nimbus/[errors, transaction, vm_types],
|
|
../nimbus/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)
|
|
|
|
when isMainModule:
|
|
transactionJsonMain()
|
|
|
|
proc txHash(tx: Transaction): string =
|
|
toLowerAscii($keccakHash(rlp.encode(tx)))
|
|
|
|
proc testTxByFork(tx: Transaction, forkData: JsonNode, forkName: string, testStatusIMPL: var TestStatus) =
|
|
try:
|
|
tx.validate(nameToFork[forkName])
|
|
except ValidationError:
|
|
return
|
|
|
|
if forkData.len > 0 and "sender" in forkData:
|
|
let sender = ethAddressFromHex(forkData["sender"].getStr)
|
|
check "hash" in forkData
|
|
check tx.txHash == forkData["hash"].getStr
|
|
check tx.getSender == 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)
|