Skip to content

Commit

Permalink
Update transaction test fixture generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Nov 5, 2021
1 parent 644d97c commit c4baafb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions eth/tools/_utils/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@ def normalize_transactiontest_fixture(fixture: Dict[str, Any], fork: str) -> Dic

normalized_fixture = {}

fork_data = fixture[fork]
fork_data = fixture['result'][fork]

try:
normalized_fixture['rlp'] = decode_hex(fixture['rlp'])
normalized_fixture['txbytes'] = decode_hex(fixture['txbytes'])
except binascii.Error:
normalized_fixture['rlpHex'] = fixture['rlp']
normalized_fixture['rlpHex'] = fixture['txbytes']

if "sender" in fork_data:
normalized_fixture['sender'] = fork_data['sender']
Expand Down
18 changes: 14 additions & 4 deletions tests/json-fixtures/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
from eth.vm.forks.istanbul.transactions import (
IstanbulTransaction
)
from eth.vm.forks.berlin.transactions import (
BerlinTransactionBuilder
)
from eth.vm.forks.london.transactions import (
LondonTransactionBuilder
)

from eth_typing.enums import (
ForkName
Expand All @@ -50,7 +56,7 @@


# Fixtures have an `_info` key at their root which we need to skip over.
FIXTURE_FORK_SKIPS = {'_info', 'rlp'}
FIXTURE_FORK_SKIPS = {'_info', 'txbytes'}


@to_tuple
Expand All @@ -62,7 +68,7 @@ def expand_fixtures_forks(all_fixtures):
"""
for fixture_path, fixture_key in all_fixtures:
fixture = load_fixture(fixture_path, fixture_key)
for fixture_fork, _ in fixture.items():
for fixture_fork, _ in fixture['result'].items():
if fixture_fork not in FIXTURE_FORK_SKIPS:
yield fixture_path, fixture_key, fixture_fork

Expand Down Expand Up @@ -105,7 +111,11 @@ def fixture_transaction_class(fixture_data):
elif fork_name == ForkName.ConstantinopleFix:
return PetersburgTransaction
elif fork_name == ForkName.Istanbul:
return IstanbulTransaction # There seem to be no new transaction tests since Istanbul
return IstanbulTransaction
elif fork_name == ForkName.Berlin:
return BerlinTransactionBuilder
elif fork_name == ForkName.London:
return LondonTransactionBuilder
elif fork_name == ForkName.Metropolis:
pytest.skip("Metropolis Transaction class has not been implemented")
else:
Expand All @@ -117,7 +127,7 @@ def test_transaction_fixtures(fixture, fixture_transaction_class):
TransactionClass = fixture_transaction_class

try:
txn = rlp.decode(fixture['rlp'], sedes=TransactionClass)
txn = rlp.decode(fixture['txbytes'], sedes=TransactionClass)
except (rlp.DeserializationError, rlp.exceptions.DecodingError):
assert 'hash' not in fixture, "Transaction was supposed to be valid"
except TypeError as err:
Expand Down

0 comments on commit c4baafb

Please sign in to comment.