Skip to content

Commit 3c76516

Browse files
committed
address reviews
1 parent b81a658 commit 3c76516

3 files changed

Lines changed: 52 additions & 31 deletions

File tree

packages/testing/src/execution_testing/ssz/__init__.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
SSZ container types and helpers for the REST+SSZ Engine API.
33
"""
44

5-
from typing import Any, Mapping, Sequence, Type, TypeVar
5+
from typing import Any, Dict, Mapping, Sequence, Type, TypeVar
66

7+
from remerkleable.complex import Container
78
from remerkleable.core import View
89

910
from .constants import (
@@ -15,8 +16,6 @@
1516
MAX_WITHDRAWALS_PER_PAYLOAD,
1617
)
1718
from .containers import (
18-
EXECUTION_PAYLOAD_BY_FORK,
19-
EXECUTION_PAYLOAD_ENVELOPE_BY_FORK,
2019
BlobAndProofV1,
2120
BlobAndProofV2,
2221
BlobCellsAndProofs,
@@ -114,6 +113,26 @@ def hash_tree_root(value: View) -> bytes:
114113
return bytes(value.hash_tree_root())
115114

116115

116+
EXECUTION_PAYLOAD_BY_FORK: Dict[str, Type[Container]] = {
117+
"Paris": ExecutionPayloadParis,
118+
"Shanghai": ExecutionPayloadShanghai,
119+
"Cancun": ExecutionPayloadCancun,
120+
"Prague": ExecutionPayloadPrague,
121+
"Osaka": ExecutionPayloadOsaka,
122+
"Amsterdam": ExecutionPayloadAmsterdam,
123+
}
124+
125+
126+
EXECUTION_PAYLOAD_ENVELOPE_BY_FORK: Dict[str, Type[Container]] = {
127+
"Paris": ExecutionPayloadEnvelopeParis,
128+
"Shanghai": ExecutionPayloadEnvelopeShanghai,
129+
"Cancun": ExecutionPayloadEnvelopeCancun,
130+
"Prague": ExecutionPayloadEnvelopePrague,
131+
"Osaka": ExecutionPayloadEnvelopeOsaka,
132+
"Amsterdam": ExecutionPayloadEnvelopeAmsterdam,
133+
}
134+
135+
117136
def _build(cls: Any, fork: str, candidates: Mapping[str, Any]) -> View:
118137
kwargs = {}
119138
for name in cls.fields():

packages/testing/src/execution_testing/ssz/containers.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
SSZ container definitions for the REST+SSZ Engine API.
33
"""
44

5-
from typing import Dict, Type
6-
75
from remerkleable.basic import boolean, uint8, uint64, uint256
86
from remerkleable.bitfields import Bitvector
97
from remerkleable.byte_arrays import ByteList, ByteVector
@@ -182,16 +180,6 @@ class ExecutionPayloadAmsterdam(Container):
182180
slot_number: uint64
183181

184182

185-
EXECUTION_PAYLOAD_BY_FORK: Dict[str, Type[Container]] = {
186-
"Paris": ExecutionPayloadParis,
187-
"Shanghai": ExecutionPayloadShanghai,
188-
"Cancun": ExecutionPayloadCancun,
189-
"Prague": ExecutionPayloadPrague,
190-
"Osaka": ExecutionPayloadOsaka,
191-
"Amsterdam": ExecutionPayloadAmsterdam,
192-
}
193-
194-
195183
class ExecutionPayloadEnvelopeParis(Container):
196184
"""The Paris `newPayload` envelope."""
197185

@@ -244,16 +232,6 @@ class ExecutionPayloadEnvelopeAmsterdam(Container):
244232
]
245233

246234

247-
EXECUTION_PAYLOAD_ENVELOPE_BY_FORK: Dict[str, Type[Container]] = {
248-
"Paris": ExecutionPayloadEnvelopeParis,
249-
"Shanghai": ExecutionPayloadEnvelopeShanghai,
250-
"Cancun": ExecutionPayloadEnvelopeCancun,
251-
"Prague": ExecutionPayloadEnvelopePrague,
252-
"Osaka": ExecutionPayloadEnvelopeOsaka,
253-
"Amsterdam": ExecutionPayloadEnvelopeAmsterdam,
254-
}
255-
256-
257235
class PayloadAttributesParis(Container):
258236
"""The Paris payload attributes."""
259237

packages/testing/src/execution_testing/ssz/tests/test_containers.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
"""Round-trip and structural tests for the SSZ containers."""
22

33
from remerkleable.basic import uint64, uint256
4+
from remerkleable.byte_arrays import ByteList
5+
from remerkleable.complex import List
46

5-
from .. import decode_bytes, encode_bytes, hash_tree_root
6-
from ..containers import (
7+
from .. import (
78
EXECUTION_PAYLOAD_BY_FORK,
89
EXECUTION_PAYLOAD_ENVELOPE_BY_FORK,
10+
decode_bytes,
11+
encode_bytes,
12+
hash_tree_root,
13+
)
14+
from ..constants import (
15+
MAX_BAL_BYTES,
16+
MAX_BYTES_PER_EXECUTION_REQUEST,
17+
MAX_BYTES_PER_TX,
18+
MAX_EXECUTION_REQUESTS_PER_PAYLOAD,
19+
MAX_TXS_PER_PAYLOAD,
20+
)
21+
from ..containers import (
922
ExecutionPayloadAmsterdam,
1023
ExecutionPayloadEnvelopeAmsterdam,
1124
Withdrawal,
1225
)
1326
from ..ssz_types import Address, Bloom, Bytes32, Hash32, Root
1427

28+
29+
Transactions = List[ByteList[MAX_BYTES_PER_TX], MAX_TXS_PER_PAYLOAD]
30+
BlockAccessList = ByteList[MAX_BAL_BYTES]
31+
ExecutionRequests = List[
32+
ByteList[MAX_BYTES_PER_EXECUTION_REQUEST],
33+
MAX_EXECUTION_REQUESTS_PER_PAYLOAD,
34+
]
35+
36+
1537
TRANSACTIONS = [
1638
bytes.fromhex("02f86b01"),
1739
bytes.fromhex("01" * 21),
@@ -44,11 +66,11 @@ def _random_payload() -> ExecutionPayloadAmsterdam:
4466
extra_data=bytes.fromhex("dead"),
4567
base_fee_per_gas=uint256(10**18),
4668
block_hash=Hash32(bytes.fromhex("ff" * 32)),
47-
transactions=list(TRANSACTIONS),
69+
transactions=Transactions(*TRANSACTIONS),
4870
withdrawals=[_withdrawal()],
4971
blob_gas_used=uint64(131_072),
5072
excess_blob_gas=uint64(0),
51-
block_access_list=bytes.fromhex("c0de"),
73+
block_access_list=BlockAccessList(bytes.fromhex("c0de")),
5274
slot_number=uint64(9_999),
5375
)
5476

@@ -58,7 +80,9 @@ def _max_envelope() -> ExecutionPayloadEnvelopeAmsterdam:
5880
return ExecutionPayloadEnvelopeAmsterdam(
5981
payload=_random_payload(),
6082
parent_beacon_block_root=Root(bytes.fromhex("12" * 32)),
61-
execution_requests=[bytes.fromhex("00aa"), bytes.fromhex("01bbcc")],
83+
execution_requests=ExecutionRequests(
84+
bytes.fromhex("00aa"), bytes.fromhex("01bbcc")
85+
),
6286
)
6387

6488

@@ -101,7 +125,7 @@ def test_transactions_two_level_offsets() -> None:
101125
assert [bytes(tx) for tx in decoded.transactions] == TRANSACTIONS
102126

103127
reordered = _random_payload()
104-
reordered.transactions = list(reversed(TRANSACTIONS))
128+
reordered.transactions = Transactions(*reversed(TRANSACTIONS))
105129
assert hash_tree_root(reordered) != hash_tree_root(value)
106130

107131

0 commit comments

Comments
 (0)