1313 expect_assertion_error ,
1414 spec_state_test ,
1515 with_bellatrix_and_later ,
16+ with_bellatrix_until_eip7732 ,
1617 with_phases ,
1718)
19+ from eth2spec .test .helpers .keys import privkeys
1820from eth2spec .test .helpers .state import next_slot
21+ from eth2spec .test .helpers .forks import is_post_eip7732
1922
2023
2124def run_execution_payload_processing (spec , state , execution_payload , valid = True , execution_valid = True ):
@@ -28,34 +31,68 @@ def run_execution_payload_processing(spec, state, execution_payload, valid=True,
2831 If ``valid == False``, run expecting ``AssertionError``
2932 """
3033 # Before Deneb, only `body.execution_payload` matters. `BeaconBlockBody` is just a wrapper.
31- body = spec .BeaconBlockBody (execution_payload = execution_payload )
34+ # after EIP-7732 the execution payload is no longer in the body
35+ if is_post_eip7732 (spec ):
36+ envelope = spec .ExecutionPayloadEnvelope (
37+ payload = execution_payload ,
38+ beacon_block_root = state .latest_block_header .hash_tree_root (),
39+ payload_withheld = False ,
40+ )
41+ post_state = state .copy ()
42+ post_state .latest_block_hash = execution_payload .block_hash
43+ post_state .latest_full_slot = state .slot
44+ envelope .state_root = post_state .hash_tree_root ()
45+ privkey = privkeys [envelope .builder_index ]
46+ signature = spec .get_execution_payload_envelope_signature (
47+ state ,
48+ envelope ,
49+ privkey ,
50+ )
51+ signed_envelope = spec .SignedExecutionPayloadEnvelope (
52+ message = envelope ,
53+ signature = signature ,
54+ )
55+ else :
56+ body = spec .BeaconBlockBody (execution_payload = execution_payload )
3257
3358 yield 'pre' , state
3459 yield 'execution' , {'execution_valid' : execution_valid }
35- yield 'body' , body
60+ if not is_post_eip7732 (spec ):
61+ yield 'body' , body
3662
3763 called_new_block = False
3864
3965 class TestEngine (spec .NoopExecutionEngine ):
4066 def verify_and_notify_new_payload (self , new_payload_request ) -> bool :
4167 nonlocal called_new_block , execution_valid
4268 called_new_block = True
43- assert new_payload_request .execution_payload == body . execution_payload
69+ assert new_payload_request .execution_payload == execution_payload
4470 return execution_valid
4571
4672 if not valid :
47- expect_assertion_error (lambda : spec .process_execution_payload (state , body , TestEngine ()))
73+ if is_post_eip7732 (spec ):
74+ expect_assertion_error (lambda : spec .process_execution_payload (state , signed_envelope , TestEngine ()))
75+ else :
76+ expect_assertion_error (lambda : spec .process_execution_payload (state , body , TestEngine ()))
4877 yield 'post' , None
4978 return
5079
51- spec .process_execution_payload (state , body , TestEngine ())
80+ if is_post_eip7732 (spec ):
81+ spec .process_execution_payload (state , signed_envelope , TestEngine ())
82+ else :
83+ spec .process_execution_payload (state , body , TestEngine ())
5284
5385 # Make sure we called the engine
5486 assert called_new_block
5587
5688 yield 'post' , state
5789
58- assert state .latest_execution_payload_header == get_execution_payload_header (spec , body .execution_payload )
90+ if is_post_eip7732 (spec ):
91+ assert state .latest_full_slot == state .slot
92+ assert state .latest_block_hash == execution_payload .block_hash
93+ else :
94+ assert state .latest_execution_payload_header == get_execution_payload_header (
95+ spec , state , body .execution_payload )
5996
6097
6198def run_success_test (spec , state ):
@@ -65,15 +102,15 @@ def run_success_test(spec, state):
65102 yield from run_execution_payload_processing (spec , state , execution_payload )
66103
67104
68- @with_bellatrix_and_later
105+ @with_bellatrix_until_eip7732
69106@spec_state_test
70107def test_success_first_payload (spec , state ):
71108 state = build_state_with_incomplete_transition (spec , state )
72109
73110 yield from run_success_test (spec , state )
74111
75112
76- @with_bellatrix_and_later
113+ @with_bellatrix_until_eip7732
77114@spec_state_test
78115def test_success_regular_payload (spec , state ):
79116 state = build_state_with_complete_transition (spec , state )
@@ -89,14 +126,14 @@ def run_gap_slot_test(spec, state):
89126 yield from run_execution_payload_processing (spec , state , execution_payload )
90127
91128
92- @with_bellatrix_and_later
129+ @with_bellatrix_until_eip7732
93130@spec_state_test
94131def test_success_first_payload_with_gap_slot (spec , state ):
95132 state = build_state_with_incomplete_transition (spec , state )
96133 yield from run_gap_slot_test (spec , state )
97134
98135
99- @with_bellatrix_and_later
136+ @with_bellatrix_until_eip7732
100137@spec_state_test
101138def test_success_regular_payload_with_gap_slot (spec , state ):
102139 state = build_state_with_complete_transition (spec , state )
@@ -111,14 +148,14 @@ def run_bad_execution_test(spec, state):
111148 yield from run_execution_payload_processing (spec , state , execution_payload , valid = False , execution_valid = False )
112149
113150
114- @with_bellatrix_and_later
151+ @with_bellatrix_until_eip7732
115152@spec_state_test
116153def test_invalid_bad_execution_first_payload (spec , state ):
117154 state = build_state_with_incomplete_transition (spec , state )
118155 yield from run_bad_execution_test (spec , state )
119156
120157
121- @with_bellatrix_and_later
158+ @with_bellatrix_until_eip7732
122159@spec_state_test
123160def test_invalid_bad_execution_regular_payload (spec , state ):
124161 state = build_state_with_complete_transition (spec , state )
@@ -255,14 +292,14 @@ def run_non_empty_extra_data_test(spec, state):
255292 assert state .latest_execution_payload_header .extra_data == execution_payload .extra_data
256293
257294
258- @with_bellatrix_and_later
295+ @with_bellatrix_until_eip7732
259296@spec_state_test
260297def test_non_empty_extra_data_first_payload (spec , state ):
261298 state = build_state_with_incomplete_transition (spec , state )
262299 yield from run_non_empty_extra_data_test (spec , state )
263300
264301
265- @with_bellatrix_and_later
302+ @with_bellatrix_until_eip7732
266303@spec_state_test
267304def test_non_empty_extra_data_regular_payload (spec , state ):
268305 state = build_state_with_complete_transition (spec , state )
@@ -284,14 +321,14 @@ def run_non_empty_transactions_test(spec, state):
284321 assert state .latest_execution_payload_header .transactions_root == execution_payload .transactions .hash_tree_root ()
285322
286323
287- @with_bellatrix_and_later
324+ @with_bellatrix_until_eip7732
288325@spec_state_test
289326def test_non_empty_transactions_first_payload (spec , state ):
290327 state = build_state_with_incomplete_transition (spec , state )
291328 yield from run_non_empty_extra_data_test (spec , state )
292329
293330
294- @with_bellatrix_and_later
331+ @with_bellatrix_until_eip7732
295332@spec_state_test
296333def test_non_empty_transactions_regular_payload (spec , state ):
297334 state = build_state_with_complete_transition (spec , state )
@@ -310,14 +347,14 @@ def run_zero_length_transaction_test(spec, state):
310347 assert state .latest_execution_payload_header .transactions_root == execution_payload .transactions .hash_tree_root ()
311348
312349
313- @with_bellatrix_and_later
350+ @with_bellatrix_until_eip7732
314351@spec_state_test
315352def test_zero_length_transaction_first_payload (spec , state ):
316353 state = build_state_with_incomplete_transition (spec , state )
317354 yield from run_zero_length_transaction_test (spec , state )
318355
319356
320- @with_bellatrix_and_later
357+ @with_bellatrix_until_eip7732
321358@spec_state_test
322359def test_zero_length_transaction_regular_payload (spec , state ):
323360 state = build_state_with_complete_transition (spec , state )
@@ -328,38 +365,43 @@ def run_randomized_non_validated_execution_fields_test(spec, state, rng, executi
328365 next_slot (spec , state )
329366 execution_payload = build_randomized_execution_payload (spec , state , rng )
330367
368+ if is_post_eip7732 (spec ):
369+ state .latest_execution_payload_header .block_hash = execution_payload .block_hash
370+ state .latest_execution_payload_header .gas_limit = execution_payload .gas_limit
371+ state .latest_block_hash = execution_payload .parent_hash
372+
331373 yield from run_execution_payload_processing (
332374 spec , state ,
333375 execution_payload ,
334376 valid = execution_valid , execution_valid = execution_valid
335377 )
336378
337379
338- @with_bellatrix_and_later
380+ @with_bellatrix_until_eip7732
339381@spec_state_test
340382def test_randomized_non_validated_execution_fields_first_payload__execution_valid (spec , state ):
341383 rng = Random (1111 )
342384 state = build_state_with_incomplete_transition (spec , state )
343385 yield from run_randomized_non_validated_execution_fields_test (spec , state , rng )
344386
345387
346- @with_bellatrix_and_later
388+ @with_bellatrix_until_eip7732
347389@spec_state_test
348390def test_randomized_non_validated_execution_fields_regular_payload__execution_valid (spec , state ):
349391 rng = Random (2222 )
350392 state = build_state_with_complete_transition (spec , state )
351393 yield from run_randomized_non_validated_execution_fields_test (spec , state , rng )
352394
353395
354- @with_bellatrix_and_later
396+ @with_bellatrix_until_eip7732
355397@spec_state_test
356398def test_invalid_randomized_non_validated_execution_fields_first_payload__execution_invalid (spec , state ):
357399 rng = Random (3333 )
358400 state = build_state_with_incomplete_transition (spec , state )
359401 yield from run_randomized_non_validated_execution_fields_test (spec , state , rng , execution_valid = False )
360402
361403
362- @with_bellatrix_and_later
404+ @with_bellatrix_until_eip7732
363405@spec_state_test
364406def test_invalid_randomized_non_validated_execution_fields_regular_payload__execution_invalid (spec , state ):
365407 rng = Random (4444 )
0 commit comments