2020@with_electra_and_later
2121@spec_state_test
2222def test_basic_withdrawal_request (spec , state ):
23+ rng = random .Random (1337 )
2324 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
2425 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
2526
2627 current_epoch = spec .get_current_epoch (state )
27- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
28+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
2829 validator_pubkey = state .validators [validator_index ].pubkey
2930 address = b"\x22 " * 20
3031 set_eth1_withdrawal_credential_with_balance (
@@ -40,15 +41,38 @@ def test_basic_withdrawal_request(spec, state):
4041 spec , state , withdrawal_request
4142 )
4243
44+ @with_electra_and_later
45+ @spec_state_test
46+ def test_basic_withdrawal_request_with_first_validator (spec , state ):
47+ # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
48+ state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
49+
50+ current_epoch = spec .get_current_epoch (state )
51+ validator_index = spec .get_active_validator_indices (state , current_epoch )[0 ]
52+ validator_pubkey = state .validators [validator_index ].pubkey
53+ address = b"\x22 " * 20
54+ set_eth1_withdrawal_credential_with_balance (
55+ spec , state , validator_index , address = address
56+ )
57+ withdrawal_request = spec .WithdrawalRequest (
58+ source_address = address ,
59+ validator_pubkey = validator_pubkey ,
60+ amount = spec .FULL_EXIT_REQUEST_AMOUNT ,
61+ )
62+
63+ yield from run_withdrawal_request_processing (
64+ spec , state , withdrawal_request
65+ )
4366
4467@with_electra_and_later
4568@spec_state_test
4669def test_basic_withdrawal_request_with_compounding_credentials (spec , state ):
70+ rng = random .Random (1338 )
4771 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
4872 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
4973
5074 current_epoch = spec .get_current_epoch (state )
51- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
75+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
5276 validator_pubkey = state .validators [validator_index ].pubkey
5377 address = b"\x22 " * 20
5478 set_compounding_withdrawal_credential (spec , state , validator_index , address = address )
@@ -67,9 +91,10 @@ def test_basic_withdrawal_request_with_compounding_credentials(spec, state):
6791@spec_state_test
6892@with_presets ([MINIMAL ], "need full partial withdrawal queue" )
6993def test_basic_withdrawal_request_with_full_partial_withdrawal_queue (spec , state ):
94+ rng = random .Random (1339 )
7095 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
7196 current_epoch = spec .get_current_epoch (state )
72- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
97+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
7398 validator_pubkey = state .validators [validator_index ].pubkey
7499 address = b"\x22 " * 20
75100 set_eth1_withdrawal_credential_with_balance (
@@ -103,11 +128,12 @@ def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state
103128@with_electra_and_later
104129@spec_state_test
105130def test_incorrect_source_address (spec , state ):
131+ rng = random .Random (1340 )
106132 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
107133 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
108134
109135 current_epoch = spec .get_current_epoch (state )
110- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
136+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
111137 validator_pubkey = state .validators [validator_index ].pubkey
112138 address = b"\x22 " * 20
113139 incorrect_address = b"\x33 " * 20
@@ -128,11 +154,12 @@ def test_incorrect_source_address(spec, state):
128154@with_electra_and_later
129155@spec_state_test
130156def test_incorrect_withdrawal_credential_prefix (spec , state ):
157+ rng = random .Random (1341 )
131158 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
132159 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
133160
134161 current_epoch = spec .get_current_epoch (state )
135- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
162+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
136163 validator_pubkey = state .validators [validator_index ].pubkey
137164 address = b"\x22 " * 20
138165 set_eth1_withdrawal_credential_with_balance (
@@ -157,11 +184,12 @@ def test_incorrect_withdrawal_credential_prefix(spec, state):
157184@with_electra_and_later
158185@spec_state_test
159186def test_on_withdrawal_request_initiated_validator (spec , state ):
187+ rng = random .Random (1342 )
160188 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
161189 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
162190
163191 current_epoch = spec .get_current_epoch (state )
164- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
192+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
165193 validator_pubkey = state .validators [validator_index ].pubkey
166194 address = b"\x22 " * 20
167195 set_eth1_withdrawal_credential_with_balance (
@@ -183,8 +211,9 @@ def test_on_withdrawal_request_initiated_validator(spec, state):
183211@with_electra_and_later
184212@spec_state_test
185213def test_activation_epoch_less_than_shard_committee_period (spec , state ):
214+ rng = random .Random (1343 )
186215 current_epoch = spec .get_current_epoch (state )
187- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
216+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
188217 validator_pubkey = state .validators [validator_index ].pubkey
189218 address = b"\x22 " * 20
190219 set_eth1_withdrawal_credential_with_balance (
@@ -212,9 +241,10 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state):
212241@spec_state_test
213242@with_presets ([MINIMAL ])
214243def test_basic_partial_withdrawal_request (spec , state ):
244+ rng = random .Random (1344 )
215245 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
216246 current_epoch = spec .get_current_epoch (state )
217- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
247+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
218248 validator_pubkey = state .validators [validator_index ].pubkey
219249 address = b"\x22 " * 20
220250 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -244,9 +274,10 @@ def test_basic_partial_withdrawal_request(spec, state):
244274@spec_state_test
245275@with_presets ([MINIMAL ])
246276def test_basic_partial_withdrawal_request_higher_excess_balance (spec , state ):
277+ rng = random .Random (1345 )
247278 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
248279 current_epoch = spec .get_current_epoch (state )
249- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
280+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
250281 validator_pubkey = state .validators [validator_index ].pubkey
251282 address = b"\x22 " * 20
252283 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -276,9 +307,10 @@ def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state):
276307@spec_state_test
277308@with_presets ([MINIMAL ])
278309def test_basic_partial_withdrawal_request_lower_than_excess_balance (spec , state ):
310+ rng = random .Random (1346 )
279311 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
280312 current_epoch = spec .get_current_epoch (state )
281- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
313+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
282314 validator_pubkey = state .validators [validator_index ].pubkey
283315 address = b"\x22 " * 20
284316 excess_balance = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -309,9 +341,10 @@ def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state)
309341@spec_state_test
310342@with_presets ([MINIMAL ])
311343def test_partial_withdrawal_request_with_pending_withdrawals (spec , state ):
344+ rng = random .Random (1347 )
312345 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
313346 current_epoch = spec .get_current_epoch (state )
314- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
347+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
315348 validator_pubkey = state .validators [validator_index ].pubkey
316349 address = b"\x22 " * 20
317350 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -350,9 +383,10 @@ def test_partial_withdrawal_request_with_pending_withdrawals(spec, state):
350383def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount (
351384 spec , state
352385):
386+ rng = random .Random (1348 )
353387 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
354388 current_epoch = spec .get_current_epoch (state )
355- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
389+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
356390 validator_pubkey = state .validators [validator_index ].pubkey
357391 address = b"\x22 " * 20
358392 amount = spec .UINT64_MAX
@@ -388,9 +422,10 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
388422@spec_state_test
389423@with_presets ([MINIMAL ])
390424def test_partial_withdrawal_request_with_high_balance (spec , state ):
425+ rng = random .Random (1349 )
391426 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
392427 current_epoch = spec .get_current_epoch (state )
393- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
428+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
394429 validator_pubkey = state .validators [validator_index ].pubkey
395430 address = b"\x22 " * 20
396431 amount = spec .MAX_EFFECTIVE_BALANCE_ELECTRA
@@ -425,9 +460,10 @@ def test_partial_withdrawal_request_with_high_balance(spec, state):
425460@spec_state_test
426461@with_presets ([MINIMAL ])
427462def test_partial_withdrawal_request_with_high_amount (spec , state ):
463+ rng = random .Random (1350 )
428464 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
429465 current_epoch = spec .get_current_epoch (state )
430- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
466+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
431467 validator_pubkey = state .validators [validator_index ].pubkey
432468 address = b"\x22 " * 20
433469 # Set high amount requested to withdraw
@@ -458,9 +494,10 @@ def test_partial_withdrawal_request_with_high_amount(spec, state):
458494@spec_state_test
459495@with_presets ([MINIMAL ])
460496def test_partial_withdrawal_request_with_low_amount (spec , state ):
497+ rng = random .Random (1351 )
461498 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
462499 current_epoch = spec .get_current_epoch (state )
463- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
500+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
464501 validator_pubkey = state .validators [validator_index ].pubkey
465502 address = b"\x22 " * 20
466503 amount = 1
@@ -493,9 +530,10 @@ def test_partial_withdrawal_request_with_low_amount(spec, state):
493530@spec_state_test
494531@with_presets ([MINIMAL ], "need full partial withdrawal queue" )
495532def test_partial_withdrawal_queue_full (spec , state ):
533+ rng = random .Random (1352 )
496534 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
497535 current_epoch = spec .get_current_epoch (state )
498- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
536+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
499537 validator_pubkey = state .validators [validator_index ].pubkey
500538 address = b"\x22 " * 20
501539 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -523,9 +561,10 @@ def test_partial_withdrawal_queue_full(spec, state):
523561@with_electra_and_later
524562@spec_state_test
525563def test_no_compounding_credentials (spec , state ):
564+ rng = random .Random (1353 )
526565 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
527566 current_epoch = spec .get_current_epoch (state )
528- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
567+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
529568 validator_pubkey = state .validators [validator_index ].pubkey
530569 address = b"\x22 " * 20
531570 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -552,9 +591,10 @@ def test_no_compounding_credentials(spec, state):
552591@with_electra_and_later
553592@spec_state_test
554593def test_no_excess_balance (spec , state ):
594+ rng = random .Random (1354 )
555595 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
556596 current_epoch = spec .get_current_epoch (state )
557- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
597+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
558598 validator_pubkey = state .validators [validator_index ].pubkey
559599 address = b"\x22 " * 20
560600 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -574,9 +614,10 @@ def test_no_excess_balance(spec, state):
574614@with_electra_and_later
575615@spec_state_test
576616def test_pending_withdrawals_consume_all_excess_balance (spec , state ):
617+ rng = random .Random (1355 )
577618 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
578619 current_epoch = spec .get_current_epoch (state )
579- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
620+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
580621 validator_pubkey = state .validators [validator_index ].pubkey
581622 address = b"\x22 " * 20
582623 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -604,9 +645,10 @@ def test_pending_withdrawals_consume_all_excess_balance(spec, state):
604645@with_electra_and_later
605646@spec_state_test
606647def test_insufficient_effective_balance (spec , state ):
648+ rng = random .Random (1356 )
607649 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
608650 current_epoch = spec .get_current_epoch (state )
609- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
651+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
610652 validator_pubkey = state .validators [validator_index ].pubkey
611653 address = b"\x22 " * 20
612654 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -633,11 +675,12 @@ def test_insufficient_effective_balance(spec, state):
633675@with_electra_and_later
634676@spec_state_test
635677def test_partial_withdrawal_incorrect_source_address (spec , state ):
678+ rng = random .Random (1357 )
636679 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
637680 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
638681
639682 current_epoch = spec .get_current_epoch (state )
640- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
683+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
641684 validator_pubkey = state .validators [validator_index ].pubkey
642685 address = b"\x22 " * 20
643686 incorrect_address = b"\x33 " * 20
@@ -659,11 +702,12 @@ def test_partial_withdrawal_incorrect_source_address(spec, state):
659702@with_electra_and_later
660703@spec_state_test
661704def test_partial_withdrawal_incorrect_withdrawal_credential_prefix (spec , state ):
705+ rng = random .Random (1358 )
662706 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
663707 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
664708
665709 current_epoch = spec .get_current_epoch (state )
666- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
710+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
667711 validator_pubkey = state .validators [validator_index ].pubkey
668712 address = b"\x22 " * 20
669713 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -688,11 +732,12 @@ def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state):
688732@with_electra_and_later
689733@spec_state_test
690734def test_partial_withdrawal_on_exit_initiated_validator (spec , state ):
735+ rng = random .Random (1359 )
691736 # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
692737 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
693738
694739 current_epoch = spec .get_current_epoch (state )
695- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
740+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
696741 validator_pubkey = state .validators [validator_index ].pubkey
697742 address = b"\x22 " * 20
698743 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -716,8 +761,9 @@ def test_partial_withdrawal_on_exit_initiated_validator(spec, state):
716761def test_partial_withdrawal_activation_epoch_less_than_shard_committee_period (
717762 spec , state
718763):
764+ rng = random .Random (1360 )
719765 current_epoch = spec .get_current_epoch (state )
720- validator_index = random .choice (spec .get_active_validator_indices (state , current_epoch ))
766+ validator_index = rng .choice (spec .get_active_validator_indices (state , current_epoch ))
721767 validator_pubkey = state .validators [validator_index ].pubkey
722768 address = b"\x22 " * 20
723769 amount = spec .EFFECTIVE_BALANCE_INCREMENT
0 commit comments