Skip to content

Commit efa07f7

Browse files
authored
Merge pull request #2016 from carver/tests-9.0.4
Update ethereum/tests to 9.0.4
2 parents 8462802 + 5363e58 commit efa07f7

File tree

15 files changed

+73
-47
lines changed

15 files changed

+73
-47
lines changed

eth/tools/_utils/normalization.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,17 +465,39 @@ def normalize_vmtest_fixture(fixture: Dict[str, Any]) -> Iterable[Tuple[str, Any
465465

466466

467467
def normalize_signed_transaction(transaction: Dict[str, Any]) -> Dict[str, Any]:
468-
return {
468+
normalized_universal_transaction = {
469469
'data': robust_decode_hex(transaction['data']),
470470
'gasLimit': to_int(transaction['gasLimit']),
471-
'gasPrice': to_int(transaction['gasPrice']),
472471
'nonce': to_int(transaction['nonce']),
473472
'r': to_int(transaction['r']),
474473
's': to_int(transaction['s']),
475474
'v': to_int(transaction['v']),
476475
'to': decode_hex(transaction['to']),
477476
'value': to_int(transaction['value']),
478477
}
478+
if 'type' in transaction:
479+
type_id = to_int(transaction['type'])
480+
if type_id == 1:
481+
custom_fields = {
482+
'type': type_id,
483+
'gasPrice': to_int(transaction['gasPrice']),
484+
'chainId': to_int(transaction['chainId']),
485+
}
486+
elif type_id == 2:
487+
custom_fields = {
488+
'type': type_id,
489+
'chainId': to_int(transaction['chainId']),
490+
'maxFeePerGas': to_int(transaction['maxFeePerGas']),
491+
'maxPriorityFeePerGas': to_int(transaction['maxPriorityFeePerGas']),
492+
}
493+
else:
494+
raise ValidationError(f"Did not recognize transaction type {type_id}")
495+
else:
496+
custom_fields = {
497+
'gasPrice': to_int(transaction['gasPrice']),
498+
}
499+
500+
return merge(normalized_universal_transaction, custom_fields)
479501

480502

481503
@curry

eth/tools/fixtures/generation.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import hashlib
2-
import os
32

43
from typing import (
54
Any,
@@ -14,7 +13,6 @@
1413

1514
from .loading import (
1615
find_fixtures,
17-
find_fixture_files,
1816
)
1917

2018

@@ -59,31 +57,8 @@ def generate_fixture_tests(metafunc: Any,
5957
fixtures (such as expanding the statetest fixtures to be multiple tests for
6058
each fork.
6159
"""
62-
fixture_namespace = os.path.basename(base_fixture_path)
63-
6460
if 'fixture_data' in metafunc.fixturenames:
65-
all_fixture_paths = find_fixture_files(base_fixture_path)
66-
current_file_hash = get_fixtures_file_hash(all_fixture_paths)
67-
68-
data_cache_key = f'pyevm/statetest/fixtures/{fixture_namespace}/data'
69-
file_hash_cache_key = f'pyevm/statetest/fixtures/{fixture_namespace}/data-hash'
70-
71-
cached_file_hash = metafunc.config.cache.get(file_hash_cache_key, None)
72-
cached_fixture_data = metafunc.config.cache.get(data_cache_key, None)
73-
74-
bust_cache = any((
75-
cached_file_hash is None,
76-
cached_fixture_data is None,
77-
cached_file_hash != current_file_hash,
78-
))
79-
80-
if bust_cache:
81-
all_fixtures = find_fixtures(base_fixture_path)
82-
83-
metafunc.config.cache.set(data_cache_key, all_fixtures)
84-
metafunc.config.cache.set(file_hash_cache_key, current_file_hash)
85-
else:
86-
all_fixtures = cached_fixture_data
61+
all_fixtures = find_fixtures(base_fixture_path)
8762

8863
if not all_fixtures:
8964
raise AssertionError(

eth/tools/fixtures/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
SpuriousDragonVM,
4949
IstanbulVM,
5050
BerlinVM,
51+
LondonVM,
5152
)
5253

5354

@@ -162,6 +163,11 @@ def chain_vm_configuration(fixture: Dict[str, Any]) -> Iterable[Tuple[int, Type[
162163
(0, ByzantiumVM),
163164
(5, PetersburgVM),
164165
)
166+
elif network == 'BerlinToLondonAt5':
167+
return (
168+
(0, BerlinVM),
169+
(5, LondonVM),
170+
)
165171
else:
166172
raise ValueError(f"Network {network} does not match any known VM rules")
167173

eth/tools/fixtures/loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def filter_fixtures(all_fixtures: Iterable[Any],
101101
if mark:
102102
yield pytest.param(
103103
(fixture_path, *fixture_data[1:]),
104-
marks=mark,
104+
marks=mark, # type: ignore # we don't annotate the test code that calls this
105105
)
106106
continue
107107

eth/vm/forks/berlin/receipts.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class TypedReceipt(ReceiptAPI, ReceiptDecoderAPI):
4343
type_id: int
4444
rlp_type = Binary(min_length=1) # must have at least one byte for the type
4545
_inner: ReceiptAPI
46+
codecs = TYPED_RECEIPT_BODY_CODECS
4647

4748
def __init__(self, type_id: int, proxy_target: ReceiptAPI) -> None:
4849
self.type_id = type_id
@@ -69,8 +70,8 @@ def encode(self) -> bytes:
6970

7071
@classmethod
7172
def get_payload_codec(cls, type_id: int) -> Type[ReceiptDecoderAPI]:
72-
if type_id in TYPED_RECEIPT_BODY_CODECS:
73-
return TYPED_RECEIPT_BODY_CODECS[type_id]
73+
if type_id in cls.codecs:
74+
return cls.codecs[type_id]
7475
elif type_id in VALID_TRANSACTION_TYPES:
7576
raise UnrecognizedTransactionType(type_id, "Unknown receipt type")
7677
else:
@@ -124,23 +125,23 @@ def __eq__(self, other: Any) -> bool:
124125

125126
class BerlinReceiptBuilder(ReceiptBuilderAPI):
126127
legacy_sedes = Receipt
127-
codecs = TYPED_RECEIPT_BODY_CODECS
128+
typed_receipt_class = TypedReceipt
128129

129130
@classmethod
130131
def decode(cls, encoded: bytes) -> ReceiptAPI:
131132
if len(encoded) == 0:
132133
raise ValidationError("Encoded receipt was empty, which makes it invalid")
133134

134135
type_id = to_int(encoded[0])
135-
if type_id in cls.codecs:
136-
return TypedReceipt.decode(encoded)
136+
if type_id in cls.typed_receipt_class.codecs:
137+
return cls.typed_receipt_class.decode(encoded)
137138
else:
138139
return rlp.decode(encoded, sedes=cls.legacy_sedes)
139140

140141
@classmethod
141142
def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> ReceiptAPI:
142143
if isinstance(encoded, bytes):
143-
return TypedReceipt.deserialize(encoded)
144+
return cls.typed_receipt_class.deserialize(encoded)
144145
else:
145146
return cls.legacy_sedes.deserialize(encoded)
146147

eth/vm/forks/berlin/transactions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
VALID_TRANSACTION_TYPES,
6464
)
6565
from .receipts import (
66-
TypedReceipt,
66+
BerlinReceiptBuilder,
6767
)
6868

6969

@@ -246,6 +246,7 @@ class TypedTransaction(SignedTransactionMethods, SignedTransactionAPI, Transacti
246246
decoders: Dict[int, Type[TransactionDecoderAPI]] = {
247247
ACCESS_LIST_TRANSACTION_TYPE: AccessListPayloadDecoder,
248248
}
249+
receipt_builder = BerlinReceiptBuilder
249250

250251
def __init__(self, type_id: int, proxy_target: SignedTransactionAPI) -> None:
251252
self.type_id = type_id
@@ -373,7 +374,7 @@ def make_receipt(
373374

374375
inner_receipt = self._inner.make_receipt(status, gas_used, log_entries)
375376

376-
return TypedReceipt(ACCESS_LIST_TRANSACTION_TYPE, inner_receipt)
377+
return self.receipt_builder.typed_receipt_class(self.type_id, inner_receipt)
377378

378379
def __hash__(self) -> int:
379380
return hash((self.type_id, self._inner))

eth/vm/forks/london/blocks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ class LondonMiningHeader(rlp.Serializable, MiningHeaderAPI):
8484

8585

8686
class LondonBlockHeader(rlp.Serializable, BlockHeaderAPI):
87-
fields = UNMINED_LONDON_HEADER_FIELDS + [
87+
fields = UNMINED_LONDON_HEADER_FIELDS[:-1] + [
8888
('mix_hash', binary),
8989
('nonce', Binary(8, allow_empty=True)),
90-
]
90+
] + UNMINED_LONDON_HEADER_FIELDS[-1:]
9191

9292
def __init__(self,
9393
difficulty: int,
@@ -144,7 +144,8 @@ def hash(self) -> Hash32:
144144

145145
@property
146146
def mining_hash(self) -> Hash32:
147-
result = keccak(rlp.encode(self[:-2], LondonMiningHeader))
147+
non_pow_fields = self[:-3] + self[-1:]
148+
result = keccak(rlp.encode(non_pow_fields, LondonMiningHeader))
148149
return cast(Hash32, result)
149150

150151
@property

eth/vm/forks/london/receipts.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
Receipt,
88
)
99
from eth.vm.forks.berlin.receipts import (
10-
BerlinReceiptBuilder
10+
BerlinReceiptBuilder,
11+
TypedReceipt as BerlinTypedReceipt,
1112
)
1213
from eth.vm.forks.berlin.constants import (
1314
ACCESS_LIST_TRANSACTION_TYPE,
@@ -16,8 +17,12 @@
1617
from .constants import DYNAMIC_FEE_TRANSACTION_TYPE
1718

1819

19-
class LondonReceiptBuilder(BerlinReceiptBuilder):
20+
class LondonTypedReceipt(BerlinTypedReceipt):
2021
codecs: Dict[int, Type[Receipt]] = {
2122
ACCESS_LIST_TRANSACTION_TYPE: Receipt,
2223
DYNAMIC_FEE_TRANSACTION_TYPE: Receipt,
2324
}
25+
26+
27+
class LondonReceiptBuilder(BerlinReceiptBuilder):
28+
typed_receipt_class = LondonTypedReceipt

eth/vm/forks/london/transactions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
)
5555

5656
from .constants import DYNAMIC_FEE_TRANSACTION_TYPE
57+
from .receipts import LondonReceiptBuilder
5758

5859

5960
class LondonLegacyTransaction(BerlinLegacyTransaction):
@@ -218,6 +219,7 @@ class LondonTypedTransaction(TypedTransaction):
218219
ACCESS_LIST_TRANSACTION_TYPE: AccessListPayloadDecoder,
219220
DYNAMIC_FEE_TRANSACTION_TYPE: DynamicFeePayloadDecoder,
220221
}
222+
receipt_builder = LondonReceiptBuilder
221223

222224

223225
class LondonTransactionBuilder(BerlinTransactionBuilder):

fixtures

0 commit comments

Comments
 (0)