13
13
expect_assertion_error ,
14
14
spec_state_test ,
15
15
with_bellatrix_and_later ,
16
+ with_bellatrix_until_eip7732 ,
16
17
with_phases ,
17
18
)
19
+ from eth2spec .test .helpers .keys import privkeys
18
20
from eth2spec .test .helpers .state import next_slot
21
+ from eth2spec .test .helpers .forks import is_post_eip7732
19
22
20
23
21
24
def 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,
28
31
If ``valid == False``, run expecting ``AssertionError``
29
32
"""
30
33
# 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 )
32
57
33
58
yield 'pre' , state
34
59
yield 'execution' , {'execution_valid' : execution_valid }
35
- yield 'body' , body
60
+ if not is_post_eip7732 (spec ):
61
+ yield 'body' , body
36
62
37
63
called_new_block = False
38
64
39
65
class TestEngine (spec .NoopExecutionEngine ):
40
66
def verify_and_notify_new_payload (self , new_payload_request ) -> bool :
41
67
nonlocal called_new_block , execution_valid
42
68
called_new_block = True
43
- assert new_payload_request .execution_payload == body . execution_payload
69
+ assert new_payload_request .execution_payload == execution_payload
44
70
return execution_valid
45
71
46
72
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 ()))
48
77
yield 'post' , None
49
78
return
50
79
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 ())
52
84
53
85
# Make sure we called the engine
54
86
assert called_new_block
55
87
56
88
yield 'post' , state
57
89
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 )
59
96
60
97
61
98
def run_success_test (spec , state ):
@@ -65,15 +102,15 @@ def run_success_test(spec, state):
65
102
yield from run_execution_payload_processing (spec , state , execution_payload )
66
103
67
104
68
- @with_bellatrix_and_later
105
+ @with_bellatrix_until_eip7732
69
106
@spec_state_test
70
107
def test_success_first_payload (spec , state ):
71
108
state = build_state_with_incomplete_transition (spec , state )
72
109
73
110
yield from run_success_test (spec , state )
74
111
75
112
76
- @with_bellatrix_and_later
113
+ @with_bellatrix_until_eip7732
77
114
@spec_state_test
78
115
def test_success_regular_payload (spec , state ):
79
116
state = build_state_with_complete_transition (spec , state )
@@ -89,14 +126,14 @@ def run_gap_slot_test(spec, state):
89
126
yield from run_execution_payload_processing (spec , state , execution_payload )
90
127
91
128
92
- @with_bellatrix_and_later
129
+ @with_bellatrix_until_eip7732
93
130
@spec_state_test
94
131
def test_success_first_payload_with_gap_slot (spec , state ):
95
132
state = build_state_with_incomplete_transition (spec , state )
96
133
yield from run_gap_slot_test (spec , state )
97
134
98
135
99
- @with_bellatrix_and_later
136
+ @with_bellatrix_until_eip7732
100
137
@spec_state_test
101
138
def test_success_regular_payload_with_gap_slot (spec , state ):
102
139
state = build_state_with_complete_transition (spec , state )
@@ -111,14 +148,14 @@ def run_bad_execution_test(spec, state):
111
148
yield from run_execution_payload_processing (spec , state , execution_payload , valid = False , execution_valid = False )
112
149
113
150
114
- @with_bellatrix_and_later
151
+ @with_bellatrix_until_eip7732
115
152
@spec_state_test
116
153
def test_invalid_bad_execution_first_payload (spec , state ):
117
154
state = build_state_with_incomplete_transition (spec , state )
118
155
yield from run_bad_execution_test (spec , state )
119
156
120
157
121
- @with_bellatrix_and_later
158
+ @with_bellatrix_until_eip7732
122
159
@spec_state_test
123
160
def test_invalid_bad_execution_regular_payload (spec , state ):
124
161
state = build_state_with_complete_transition (spec , state )
@@ -255,14 +292,14 @@ def run_non_empty_extra_data_test(spec, state):
255
292
assert state .latest_execution_payload_header .extra_data == execution_payload .extra_data
256
293
257
294
258
- @with_bellatrix_and_later
295
+ @with_bellatrix_until_eip7732
259
296
@spec_state_test
260
297
def test_non_empty_extra_data_first_payload (spec , state ):
261
298
state = build_state_with_incomplete_transition (spec , state )
262
299
yield from run_non_empty_extra_data_test (spec , state )
263
300
264
301
265
- @with_bellatrix_and_later
302
+ @with_bellatrix_until_eip7732
266
303
@spec_state_test
267
304
def test_non_empty_extra_data_regular_payload (spec , state ):
268
305
state = build_state_with_complete_transition (spec , state )
@@ -284,14 +321,14 @@ def run_non_empty_transactions_test(spec, state):
284
321
assert state .latest_execution_payload_header .transactions_root == execution_payload .transactions .hash_tree_root ()
285
322
286
323
287
- @with_bellatrix_and_later
324
+ @with_bellatrix_until_eip7732
288
325
@spec_state_test
289
326
def test_non_empty_transactions_first_payload (spec , state ):
290
327
state = build_state_with_incomplete_transition (spec , state )
291
328
yield from run_non_empty_extra_data_test (spec , state )
292
329
293
330
294
- @with_bellatrix_and_later
331
+ @with_bellatrix_until_eip7732
295
332
@spec_state_test
296
333
def test_non_empty_transactions_regular_payload (spec , state ):
297
334
state = build_state_with_complete_transition (spec , state )
@@ -310,14 +347,14 @@ def run_zero_length_transaction_test(spec, state):
310
347
assert state .latest_execution_payload_header .transactions_root == execution_payload .transactions .hash_tree_root ()
311
348
312
349
313
- @with_bellatrix_and_later
350
+ @with_bellatrix_until_eip7732
314
351
@spec_state_test
315
352
def test_zero_length_transaction_first_payload (spec , state ):
316
353
state = build_state_with_incomplete_transition (spec , state )
317
354
yield from run_zero_length_transaction_test (spec , state )
318
355
319
356
320
- @with_bellatrix_and_later
357
+ @with_bellatrix_until_eip7732
321
358
@spec_state_test
322
359
def test_zero_length_transaction_regular_payload (spec , state ):
323
360
state = build_state_with_complete_transition (spec , state )
@@ -328,38 +365,43 @@ def run_randomized_non_validated_execution_fields_test(spec, state, rng, executi
328
365
next_slot (spec , state )
329
366
execution_payload = build_randomized_execution_payload (spec , state , rng )
330
367
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
+
331
373
yield from run_execution_payload_processing (
332
374
spec , state ,
333
375
execution_payload ,
334
376
valid = execution_valid , execution_valid = execution_valid
335
377
)
336
378
337
379
338
- @with_bellatrix_and_later
380
+ @with_bellatrix_until_eip7732
339
381
@spec_state_test
340
382
def test_randomized_non_validated_execution_fields_first_payload__execution_valid (spec , state ):
341
383
rng = Random (1111 )
342
384
state = build_state_with_incomplete_transition (spec , state )
343
385
yield from run_randomized_non_validated_execution_fields_test (spec , state , rng )
344
386
345
387
346
- @with_bellatrix_and_later
388
+ @with_bellatrix_until_eip7732
347
389
@spec_state_test
348
390
def test_randomized_non_validated_execution_fields_regular_payload__execution_valid (spec , state ):
349
391
rng = Random (2222 )
350
392
state = build_state_with_complete_transition (spec , state )
351
393
yield from run_randomized_non_validated_execution_fields_test (spec , state , rng )
352
394
353
395
354
- @with_bellatrix_and_later
396
+ @with_bellatrix_until_eip7732
355
397
@spec_state_test
356
398
def test_invalid_randomized_non_validated_execution_fields_first_payload__execution_invalid (spec , state ):
357
399
rng = Random (3333 )
358
400
state = build_state_with_incomplete_transition (spec , state )
359
401
yield from run_randomized_non_validated_execution_fields_test (spec , state , rng , execution_valid = False )
360
402
361
403
362
- @with_bellatrix_and_later
404
+ @with_bellatrix_until_eip7732
363
405
@spec_state_test
364
406
def test_invalid_randomized_non_validated_execution_fields_regular_payload__execution_invalid (spec , state ):
365
407
rng = Random (4444 )
0 commit comments