Convert sets to sorted lists prior to sampling

This is because sampling of sets has been deprecated in Python 3.9. I used
sorted() instead of list() so that things are deterministic.
This commit is contained in:
Justin Traglia 2022-05-09 14:09:27 -05:00
parent c1d0836936
commit a7bda480fe
4 changed files with 10 additions and 10 deletions

View File

@ -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,

View File

@ -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(

View File

@ -200,7 +200,7 @@ 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))
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(sorted(comm), 1))
@with_all_phases
@ -208,14 +208,14 @@ 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))
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(sorted(comm), 1))
@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))
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(sorted(comm), len(comm) // 3))
@with_all_phases
@ -223,14 +223,14 @@ 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))
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(sorted(comm), len(comm) // 3))
@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))
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(sorted(comm), len(comm) - 1))
@with_all_phases
@ -238,7 +238,7 @@ 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))
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(sorted(comm), len(comm) - 1))
@with_all_phases

View File

@ -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