2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-06-17 07:56:39 +00:00
|
|
|
# Copyright (c) 2019-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +00:00
|
|
|
# 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.
|
|
|
|
|
2019-08-26 15:19:18 +00:00
|
|
|
import
|
2022-12-02 04:39:12 +00:00
|
|
|
std/[json, os, tables, strutils],
|
|
|
|
unittest2,
|
|
|
|
eth/rlp,
|
2020-04-15 11:09:49 +00:00
|
|
|
./test_helpers,
|
2024-06-18 00:55:35 +00:00
|
|
|
../nimbus/[errors, transaction],
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/utils/utils
|
2019-08-26 15:19:18 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
FIXTURE_FORK_SKIPS = ["_info", "rlp", "Constantinople"]
|
|
|
|
|
|
|
|
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
|
|
|
|
2019-09-21 05:45:23 +00:00
|
|
|
proc transactionJsonMain*() =
|
|
|
|
suite "Transactions tests":
|
2021-01-06 10:02:19 +00:00
|
|
|
jsonTest("eth_tests" / "TransactionTests", "TransactionTests", testFixture)
|
2019-09-21 05:45:23 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
transactionJsonMain()
|
2019-08-26 15:19:18 +00:00
|
|
|
|
|
|
|
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:
|
2024-09-29 12:37:09 +00:00
|
|
|
let sender = EthAddress.fromHex(forkData["sender"].getStr)
|
2019-08-26 15:19:18 +00:00
|
|
|
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
|
|
|
|
|
2020-02-11 03:34:50 +00:00
|
|
|
# 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
|
2019-08-26 15:19:18 +00:00
|
|
|
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)
|
2020-02-11 03:34:50 +00:00
|
|
|
except RlpTypeMismatch, MalformedRlpError, UnsupportedRlpError:
|
2019-08-26 15:19:18 +00:00
|
|
|
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)
|