From 78233a4edc5ffbfc8ef1b755d8d2e78aa5dbffaa Mon Sep 17 00:00:00 2001 From: Jamie Lokier Date: Mon, 17 May 2021 06:41:58 +0100 Subject: [PATCH] Tests: Explain rules of "to" for call/create, use `ZERO_ADDRESS` The conditions mentioned in the old TODO comment have been checked. All fixtures have either 40 hex digits or empty string for "to". There is a test with all-zeros, and it means send to that account, not contract creation. Empty string means contract creation. This patch does not change the relaxed parsing where fewer than 40 digits is accepted. We should probably be stricter about this. Signed-off-by: Jamie Lokier --- tests/test_helpers.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index e5969bd38..6beae33da 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -9,7 +9,7 @@ import os, macros, json, strformat, strutils, parseutils, os, tables, stew/byteutils, net, eth/[common, keys, rlp, p2p], unittest2, testutils/markdown_reports, - ../nimbus/[config, transaction, utils, errors], + ../nimbus/[constants, config, transaction, utils, errors], ../nimbus/vm_types2, ../nimbus/db/accounts_cache, ../nimbus/random_keys @@ -221,11 +221,18 @@ proc getFixtureTransaction*(j: JsonNode, dataIndex, gasIndex, valueIndex: int): var toAddr: EthAddress var contract: bool - # TODO: there are a couple fixtures which appear to distinguish between - # empty and 0 transaction.to; check/verify whether correct conditions. + # Fixture transactions with `"to": ""` are contract creations. + # + # Fixture transactions with `"to": "0x..."` or `"to": "..."` where `...` are + # 40 hex digits are call/transfer transactions. Even if the digits are all + # zeros, because the all-zeros address is a legitimate account. + # + # There are no other formats. The number of digits if present is always 40, + # "0x" prefix is used in some but not all fixtures, and upper case hex digits + # occur in a few. let rawTo = j["to"].getStr if rawTo == "": - toAddr = "0x".parseAddress + toAddr = ZERO_ADDRESS contract = true else: toAddr = rawTo.parseAddress