diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py index 2ac8bfb48..32861b866 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py @@ -281,7 +281,7 @@ def test_transition_with_random_three_quarters_participation(state, fork_epoch, assert committee_len >= 4 filter_len = committee_len // 4 participant_count = committee_len - filter_len - return rng.sample(indices, participant_count) + return rng.sample(sorted(indices), participant_count) yield from _run_transition_test_with_attestations( state, @@ -304,7 +304,7 @@ def test_transition_with_random_half_participation(state, fork_epoch, spec, post assert committee_len >= 2 filter_len = committee_len // 2 participant_count = committee_len - filter_len - return rng.sample(indices, participant_count) + return rng.sample(sorted(indices), participant_count) yield from _run_transition_test_with_attestations( state, diff --git a/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py b/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py index dd9214040..1efeca547 100644 --- a/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py +++ b/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py @@ -59,7 +59,7 @@ def test_is_assigned_to_sync_committee(spec, state): if disqualified_pubkeys: sample_size = 3 assert validator_count >= sample_size - some_pubkeys = rng.sample(disqualified_pubkeys, sample_size) + some_pubkeys = rng.sample(sorted(disqualified_pubkeys), sample_size) for pubkey in some_pubkeys: validator_index = active_pubkeys.index(pubkey) is_current = spec.is_assigned_to_sync_committee( diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py index 7ff4e83d3..2bb297498 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_rewards_and_penalties.py @@ -200,7 +200,10 @@ def run_with_participation(spec, state, participation_fn): @spec_state_test def test_almost_empty_attestations(spec, state): rng = Random(1234) - yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, 1)) + + def participation_fn(slot, comm_index, comm): + return rng.sample(sorted(comm), 1) + yield from run_with_participation(spec, state, participation_fn) @with_all_phases @@ -208,14 +211,20 @@ def test_almost_empty_attestations(spec, state): @leaking() def test_almost_empty_attestations_with_leak(spec, state): rng = Random(1234) - yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, 1)) + + def participation_fn(slot, comm_index, comm): + return rng.sample(sorted(comm), 1) + yield from run_with_participation(spec, state, participation_fn) @with_all_phases @spec_state_test def test_random_fill_attestations(spec, state): rng = Random(4567) - yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) // 3)) + + def participation_fn(slot, comm_index, comm): + return rng.sample(sorted(comm), len(comm) // 3) + yield from run_with_participation(spec, state, participation_fn) @with_all_phases @@ -223,14 +232,20 @@ def test_random_fill_attestations(spec, state): @leaking() def test_random_fill_attestations_with_leak(spec, state): rng = Random(4567) - yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) // 3)) + + def participation_fn(slot, comm_index, comm): + return rng.sample(sorted(comm), len(comm) // 3) + yield from run_with_participation(spec, state, participation_fn) @with_all_phases @spec_state_test def test_almost_full_attestations(spec, state): rng = Random(8901) - yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) - 1)) + + def participation_fn(slot, comm_index, comm): + return rng.sample(sorted(comm), len(comm) - 1) + yield from run_with_participation(spec, state, participation_fn) @with_all_phases @@ -238,7 +253,10 @@ def test_almost_full_attestations(spec, state): @leaking() def test_almost_full_attestations_with_leak(spec, state): rng = Random(8901) - yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) - 1)) + + def participation_fn(slot, comm_index, comm): + return rng.sample(sorted(comm), len(comm) - 1) + yield from run_with_participation(spec, state, participation_fn) @with_all_phases diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py index f57522ad7..eede24630 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py @@ -38,7 +38,7 @@ def _drop_random_one_third(_slot, _index, indices): assert committee_len >= 3 filter_len = committee_len // 3 participant_count = committee_len - filter_len - return rng.sample(indices, participant_count) + return rng.sample(sorted(indices), participant_count) @with_all_phases