2019-08-26 15:19:18 +00:00
|
|
|
import
|
2019-05-30 16:42:55 +00:00
|
|
|
unittest2, json, os, tables, strformat, strutils,
|
2019-08-26 15:19:18 +00:00
|
|
|
eth/[common, rlp],
|
2019-11-20 15:25:09 +00:00
|
|
|
./test_helpers, ./test_allowed_to_fail,
|
|
|
|
../nimbus/[transaction, utils, errors]
|
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":
|
2019-11-20 15:25:09 +00:00
|
|
|
jsonTest("TransactionTests", testFixture, skipTxTests)
|
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:
|
|
|
|
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
|
|
|
|
|
|
|
|
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:
|
|
|
|
# TODO:
|
|
|
|
# nimbus rlp cannot allow type mismatch
|
|
|
|
# e.g. uint256 value put into int64
|
|
|
|
# so we skip noHash check
|
|
|
|
# this behavior different compared to
|
|
|
|
# py-evm, not sure what should we do
|
|
|
|
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)
|