1+ import random
12from eth2spec .test .context import (
23 spec_state_test ,
34 expect_assertion_error ,
@@ -23,7 +24,7 @@ def test_basic_withdrawal_request(spec, state):
2324 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
2425
2526 current_epoch = spec .get_current_epoch (state )
26- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
27+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
2728 validator_pubkey = state .validators [validator_index ].pubkey
2829 address = b"\x22 " * 20
2930 set_eth1_withdrawal_credential_with_balance (
@@ -47,7 +48,7 @@ def test_basic_withdrawal_request_with_compounding_credentials(spec, state):
4748 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
4849
4950 current_epoch = spec .get_current_epoch (state )
50- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
51+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
5152 validator_pubkey = state .validators [validator_index ].pubkey
5253 address = b"\x22 " * 20
5354 set_compounding_withdrawal_credential (spec , state , validator_index , address = address )
@@ -68,7 +69,7 @@ def test_basic_withdrawal_request_with_compounding_credentials(spec, state):
6869def test_basic_withdrawal_request_with_full_partial_withdrawal_queue (spec , state ):
6970 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
7071 current_epoch = spec .get_current_epoch (state )
71- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
72+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
7273 validator_pubkey = state .validators [validator_index ].pubkey
7374 address = b"\x22 " * 20
7475 set_eth1_withdrawal_credential_with_balance (
@@ -106,7 +107,7 @@ def test_incorrect_source_address(spec, state):
106107 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
107108
108109 current_epoch = spec .get_current_epoch (state )
109- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
110+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
110111 validator_pubkey = state .validators [validator_index ].pubkey
111112 address = b"\x22 " * 20
112113 incorrect_address = b"\x33 " * 20
@@ -131,7 +132,7 @@ def test_incorrect_withdrawal_credential_prefix(spec, state):
131132 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
132133
133134 current_epoch = spec .get_current_epoch (state )
134- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
135+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
135136 validator_pubkey = state .validators [validator_index ].pubkey
136137 address = b"\x22 " * 20
137138 set_eth1_withdrawal_credential_with_balance (
@@ -160,7 +161,7 @@ def test_on_withdrawal_request_initiated_validator(spec, state):
160161 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
161162
162163 current_epoch = spec .get_current_epoch (state )
163- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
164+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
164165 validator_pubkey = state .validators [validator_index ].pubkey
165166 address = b"\x22 " * 20
166167 set_eth1_withdrawal_credential_with_balance (
@@ -183,7 +184,7 @@ def test_on_withdrawal_request_initiated_validator(spec, state):
183184@spec_state_test
184185def test_activation_epoch_less_than_shard_committee_period (spec , state ):
185186 current_epoch = spec .get_current_epoch (state )
186- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
187+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
187188 validator_pubkey = state .validators [validator_index ].pubkey
188189 address = b"\x22 " * 20
189190 set_eth1_withdrawal_credential_with_balance (
@@ -213,7 +214,7 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state):
213214def test_basic_partial_withdrawal_request (spec , state ):
214215 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
215216 current_epoch = spec .get_current_epoch (state )
216- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
217+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
217218 validator_pubkey = state .validators [validator_index ].pubkey
218219 address = b"\x22 " * 20
219220 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -245,7 +246,7 @@ def test_basic_partial_withdrawal_request(spec, state):
245246def test_basic_partial_withdrawal_request_higher_excess_balance (spec , state ):
246247 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
247248 current_epoch = spec .get_current_epoch (state )
248- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
249+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
249250 validator_pubkey = state .validators [validator_index ].pubkey
250251 address = b"\x22 " * 20
251252 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -277,7 +278,7 @@ def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state):
277278def test_basic_partial_withdrawal_request_lower_than_excess_balance (spec , state ):
278279 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
279280 current_epoch = spec .get_current_epoch (state )
280- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
281+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
281282 validator_pubkey = state .validators [validator_index ].pubkey
282283 address = b"\x22 " * 20
283284 excess_balance = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -310,7 +311,7 @@ def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state)
310311def test_partial_withdrawal_request_with_pending_withdrawals (spec , state ):
311312 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
312313 current_epoch = spec .get_current_epoch (state )
313- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
314+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
314315 validator_pubkey = state .validators [validator_index ].pubkey
315316 address = b"\x22 " * 20
316317 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -351,7 +352,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
351352):
352353 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
353354 current_epoch = spec .get_current_epoch (state )
354- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
355+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
355356 validator_pubkey = state .validators [validator_index ].pubkey
356357 address = b"\x22 " * 20
357358 amount = spec .UINT64_MAX
@@ -389,7 +390,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
389390def test_partial_withdrawal_request_with_high_balance (spec , state ):
390391 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
391392 current_epoch = spec .get_current_epoch (state )
392- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
393+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
393394 validator_pubkey = state .validators [validator_index ].pubkey
394395 address = b"\x22 " * 20
395396 amount = spec .MAX_EFFECTIVE_BALANCE_ELECTRA
@@ -426,7 +427,7 @@ def test_partial_withdrawal_request_with_high_balance(spec, state):
426427def test_partial_withdrawal_request_with_high_amount (spec , state ):
427428 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
428429 current_epoch = spec .get_current_epoch (state )
429- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
430+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
430431 validator_pubkey = state .validators [validator_index ].pubkey
431432 address = b"\x22 " * 20
432433 # Set high amount requested to withdraw
@@ -459,7 +460,7 @@ def test_partial_withdrawal_request_with_high_amount(spec, state):
459460def test_partial_withdrawal_request_with_low_amount (spec , state ):
460461 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
461462 current_epoch = spec .get_current_epoch (state )
462- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
463+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
463464 validator_pubkey = state .validators [validator_index ].pubkey
464465 address = b"\x22 " * 20
465466 amount = 1
@@ -494,7 +495,7 @@ def test_partial_withdrawal_request_with_low_amount(spec, state):
494495def test_partial_withdrawal_queue_full (spec , state ):
495496 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
496497 current_epoch = spec .get_current_epoch (state )
497- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
498+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
498499 validator_pubkey = state .validators [validator_index ].pubkey
499500 address = b"\x22 " * 20
500501 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -524,7 +525,7 @@ def test_partial_withdrawal_queue_full(spec, state):
524525def test_no_compounding_credentials (spec , state ):
525526 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
526527 current_epoch = spec .get_current_epoch (state )
527- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
528+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
528529 validator_pubkey = state .validators [validator_index ].pubkey
529530 address = b"\x22 " * 20
530531 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -553,7 +554,7 @@ def test_no_compounding_credentials(spec, state):
553554def test_no_excess_balance (spec , state ):
554555 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
555556 current_epoch = spec .get_current_epoch (state )
556- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
557+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
557558 validator_pubkey = state .validators [validator_index ].pubkey
558559 address = b"\x22 " * 20
559560 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -575,7 +576,7 @@ def test_no_excess_balance(spec, state):
575576def test_pending_withdrawals_consume_all_excess_balance (spec , state ):
576577 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
577578 current_epoch = spec .get_current_epoch (state )
578- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
579+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
579580 validator_pubkey = state .validators [validator_index ].pubkey
580581 address = b"\x22 " * 20
581582 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -605,7 +606,7 @@ def test_pending_withdrawals_consume_all_excess_balance(spec, state):
605606def test_insufficient_effective_balance (spec , state ):
606607 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
607608 current_epoch = spec .get_current_epoch (state )
608- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
609+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
609610 validator_pubkey = state .validators [validator_index ].pubkey
610611 address = b"\x22 " * 20
611612 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -636,7 +637,7 @@ def test_partial_withdrawal_incorrect_source_address(spec, state):
636637 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
637638
638639 current_epoch = spec .get_current_epoch (state )
639- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
640+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
640641 validator_pubkey = state .validators [validator_index ].pubkey
641642 address = b"\x22 " * 20
642643 incorrect_address = b"\x33 " * 20
@@ -662,7 +663,7 @@ def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state):
662663 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
663664
664665 current_epoch = spec .get_current_epoch (state )
665- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
666+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
666667 validator_pubkey = state .validators [validator_index ].pubkey
667668 address = b"\x22 " * 20
668669 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -691,7 +692,7 @@ def test_partial_withdrawal_on_exit_initiated_validator(spec, state):
691692 state .slot += spec .config .SHARD_COMMITTEE_PERIOD * spec .SLOTS_PER_EPOCH
692693
693694 current_epoch = spec .get_current_epoch (state )
694- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
695+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
695696 validator_pubkey = state .validators [validator_index ].pubkey
696697 address = b"\x22 " * 20
697698 amount = spec .EFFECTIVE_BALANCE_INCREMENT
@@ -716,7 +717,7 @@ def test_partial_withdrawal_activation_epoch_less_than_shard_committee_period(
716717 spec , state
717718):
718719 current_epoch = spec .get_current_epoch (state )
719- validator_index = spec .get_active_validator_indices (state , current_epoch )[ 0 ]
720+ validator_index = random . choice ( spec .get_active_validator_indices (state , current_epoch ))
720721 validator_pubkey = state .validators [validator_index ].pubkey
721722 address = b"\x22 " * 20
722723 amount = spec .EFFECTIVE_BALANCE_INCREMENT
0 commit comments