From cbba5426fea2fe3b0532e71339044981d2cfe6ab Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 14 Oct 2021 20:07:07 +0800 Subject: [PATCH] PR feedback --- ...ation.py => test_activations_and_exits.py} | 25 ++++++++++++------- .../test/altair/transition/test_slashing.py | 9 +++++-- .../test/helpers/inactivity_scores.py | 4 +-- .../pyspec/eth2spec/test/helpers/random.py | 3 ++- 4 files changed, 27 insertions(+), 14 deletions(-) rename tests/core/pyspec/eth2spec/test/altair/transition/{test_activation.py => test_activations_and_exits.py} (88%) diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_activation.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py similarity index 88% rename from tests/core/pyspec/eth2spec/test/altair/transition/test_activation.py rename to tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py index df8ac6934..50e97d24e 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_activation.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py @@ -11,9 +11,6 @@ from eth2spec.test.helpers.fork_transition import ( transition_to_next_epoch_and_append_blocks, ) from eth2spec.test.helpers.random import set_some_new_deposits -from eth2spec.test.helpers.state import ( - transition_to, -) from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits @@ -22,8 +19,12 @@ from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits # @fork_transition_test(PHASE0, ALTAIR, fork_epoch=2) -def test_transition_with_one_fourth_exiting_validators_exit_post_fork( - state, fork_epoch, spec, post_spec, pre_tag, post_tag): +def test_transition_with_one_fourth_exiting_validators_exit_post_fork(state, + fork_epoch, + spec, + post_spec, + pre_tag, + post_tag): """ 1/4 exiting but still active validators at the fork transition. """ @@ -51,6 +52,7 @@ def test_transition_with_one_fourth_exiting_validators_exit_post_fork( # ensure that some of the current sync committee members are exiting exited_pubkeys = [state.validators[index].pubkey for index in exited_indices] assert any(set(exited_pubkeys).intersection(list(state.current_sync_committee.pubkeys))) + assert any(set(exited_pubkeys).difference(list(state.current_sync_committee.pubkeys))) # continue regular state transition with new spec into next epoch transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks) @@ -67,8 +69,12 @@ def test_transition_with_one_fourth_exiting_validators_exit_post_fork( @fork_transition_test(PHASE0, ALTAIR, fork_epoch=2) -def test_transition_with_one_fourth_exiting_validators_exit_at_fork( - state, fork_epoch, spec, post_spec, pre_tag, post_tag): +def test_transition_with_one_fourth_exiting_validators_exit_at_fork(state, + fork_epoch, + spec, + post_spec, + pre_tag, + post_tag): """ 1/4 exiting but still active validators at the fork transition. """ @@ -117,7 +123,8 @@ def test_transition_with_voluntary_exit_at_fork(state, fork_epoch, spec, post_sp Create an attester slashing at the transition. fork_epoch=260 because mainnet `SHARD_COMMITTEE_PERIOD` is 256 epochs. """ - transition_to(spec, state, spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH) + # Fast forward to the future epoch so that validator can do voluntary exit + state.slot = spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH transition_until_fork(spec, state, fork_epoch) yield "pre", state @@ -209,7 +216,7 @@ def test_transition_with_deposit_at_fork(state, fork_epoch, spec, post_spec, pre fill_cur_epoch=True, fill_prev_epoch=True, ) - blocks.extend([pre_tag(block) for block in blocks_in_epoch]) + blocks.extend([post_tag(block) for block in blocks_in_epoch]) assert state.finalized_checkpoint.epoch == state.validators[validator_index].activation_eligibility_epoch # continue regular state transition with new spec into next epoch diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py index cc22f5c22..86b78bd3e 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py @@ -22,8 +22,12 @@ from eth2spec.test.helpers.inactivity_scores import ( @fork_transition_test(PHASE0, ALTAIR, fork_epoch=1) -def test_transition_with_one_fourth_slashed_active_validators_pre_fork( - state, fork_epoch, spec, post_spec, pre_tag, post_tag): +def test_transition_with_one_fourth_slashed_active_validators_pre_fork(state, + fork_epoch, + spec, + post_spec, + pre_tag, + post_tag): """ 1/4 validators are slashed but still active at the fork transition. """ @@ -53,6 +57,7 @@ def test_transition_with_one_fourth_slashed_active_validators_pre_fork( # ensure that some of the current sync committee members are the slashed slashed_pubkeys = [state.validators[index].pubkey for index in slashed_indices] assert any(set(slashed_pubkeys).intersection(list(state.current_sync_committee.pubkeys))) + assert any(set(slashed_pubkeys).difference(list(state.current_sync_committee.pubkeys))) # continue regular state transition with new spec into next epoch to_slot = post_spec.SLOTS_PER_EPOCH + state.slot diff --git a/tests/core/pyspec/eth2spec/test/helpers/inactivity_scores.py b/tests/core/pyspec/eth2spec/test/helpers/inactivity_scores.py index ff744c4ed..02aec7105 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/inactivity_scores.py +++ b/tests/core/pyspec/eth2spec/test/helpers/inactivity_scores.py @@ -16,8 +16,8 @@ def zero_inactivity_scores(spec, state, rng=None): def slash_some_validators_for_inactivity_scores_test(spec, state, rng=Random(40404040), fraction=0.25): """ ``run_inactivity_scores_test`` runs at the next epoch from `state`. - # We retrieve the proposer of this future state to avoid - # accidentally slashing that validator + We retrieve the proposer of this future state to avoid + accidentally slashing that validator """ future_state = state.copy() next_epoch_via_block(spec, future_state) diff --git a/tests/core/pyspec/eth2spec/test/helpers/random.py b/tests/core/pyspec/eth2spec/test/helpers/random.py index e8b233e1e..cd662d09d 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/random.py +++ b/tests/core/pyspec/eth2spec/test/helpers/random.py @@ -7,7 +7,8 @@ from eth2spec.test.helpers.state import next_epoch def set_some_new_deposits(spec, state, rng): - eligible_indices = queuing_indices = [] + eligible_indices = [] + queuing_indices = [] num_validators = len(state.validators) # Set ~1/10 to just recently deposited for index in range(num_validators):