From a4e5d50660f5af57e9c8b75987f7478f04e76098 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 15 Oct 2021 11:57:10 +0800 Subject: [PATCH] Fix/ignore mainnet preset cases --- .../transition/test_activations_and_exits.py | 7 ++++++- .../test/altair/transition/test_slashing.py | 3 +++ .../eth2spec/test/helpers/fork_transition.py | 15 ++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py index 86742042f..7ef11f629 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_activations_and_exits.py @@ -1,5 +1,9 @@ import random -from eth2spec.test.context import fork_transition_test +from eth2spec.test.context import ( + MINIMAL, + fork_transition_test, + with_presets, +) from eth2spec.test.helpers.constants import PHASE0, ALTAIR from eth2spec.test.helpers.fork_transition import ( do_altair_fork, @@ -17,6 +21,7 @@ from eth2spec.test.helpers.random import ( # @fork_transition_test(PHASE0, ALTAIR, fork_epoch=2) +@with_presets([MINIMAL], reason="only test with non-full committee") def test_transition_with_one_fourth_exiting_validators_exit_post_fork(state, fork_epoch, spec, 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 0a5c7abeb..20ab89c1a 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_slashing.py @@ -1,6 +1,8 @@ import random from eth2spec.test.context import ( + MINIMAL, fork_transition_test, + with_presets, ) from eth2spec.test.helpers.constants import PHASE0, ALTAIR from eth2spec.test.helpers.fork_transition import ( @@ -14,6 +16,7 @@ from eth2spec.test.helpers.random import ( @fork_transition_test(PHASE0, ALTAIR, fork_epoch=1) +@with_presets([MINIMAL], reason="only test with non-full committee") def test_transition_with_one_fourth_slashed_active_validators_pre_fork(state, fork_epoch, spec, diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_transition.py b/tests/core/pyspec/eth2spec/test/helpers/fork_transition.py index 47e0c803a..63a92fce2 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_transition.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_transition.py @@ -198,18 +198,21 @@ def run_transition_with_operation(state, is_right_before_fork = operation_at_slot == fork_epoch * spec.SLOTS_PER_EPOCH - 1 assert is_at_fork or is_right_before_fork - blocks = [] - if is_at_fork: transition_until_fork(spec, state, fork_epoch) - - if is_right_before_fork: + elif is_right_before_fork: _transition_until_fork_minus_one(spec, state, fork_epoch) # prepare operation selected_validator_index = None if operation_type == OperetionType.PROPOSER_SLASHING: - proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=True, signed_2=True) + # avoid slashing the next proposer + future_state = state.copy() + next_slot(spec, future_state) + proposer_index = spec.get_beacon_proposer_index(future_state) + selected_validator_index = (proposer_index + 1) % len(state.validators) + proposer_slashing = get_valid_proposer_slashing( + spec, state, slashed_index=selected_validator_index, signed_1=True, signed_2=True) operation_dict = {'proposer_slashings': [proposer_slashing]} elif operation_type == OperetionType.ATTESTER_SLASHING: attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True) @@ -225,6 +228,8 @@ def run_transition_with_operation(state, signed_exits = prepare_signed_exits(spec, state, [selected_validator_index]) operation_dict = {'voluntary_exits': signed_exits} + blocks = [] + if is_right_before_fork: # add a block with operation. block = build_empty_block_for_next_slot(spec, state)