From 4ad3d65d100e7118250ea04a7ea0d066c2410ed5 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 7 May 2020 12:23:37 -0600 Subject: [PATCH] add multiple exits block sanity test --- .../test/helpers/proposer_slashings.py | 4 +-- .../eth2spec/test/sanity/test_blocks.py | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py b/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py index 8b4b04879..87b4f5ca0 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py +++ b/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py @@ -19,14 +19,14 @@ def check_proposer_slashing_effect(spec, pre_state, state, slashed_index): == get_balance(pre_state, slashed_index) - slash_penalty ) # block proposer gained whistleblower reward - # >= becase proposer could have reported multiple + # >= because proposer could have reported multiple assert ( get_balance(state, proposer_index) >= get_balance(pre_state, proposer_index) + whistleblower_reward ) else: # proposer reported themself so get penalty and reward - # >= becase proposer could have reported multiple + # >= because proposer could have reported multiple assert ( get_balance(state, slashed_index) >= get_balance(pre_state, slashed_index) - slash_penalty + whistleblower_reward diff --git a/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py index ddb884ae7..9faeb1f98 100644 --- a/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py @@ -582,6 +582,38 @@ def test_double_validator_exit_same_block(spec, state): yield 'post', None +@with_phases(['phase0']) +@spec_state_test +def test_multiple_different_validator_exits_same_block(spec, state): + validator_indices = [ + spec.get_active_validator_indices(state, spec.get_current_epoch(state))[i] + for i in range(3) + ] + # move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + signed_exits = prepare_signed_exits(spec, state, validator_indices) + yield 'pre', state + + # Add to state via block transition + initiate_exit_block = build_empty_block_for_next_slot(spec, state) + initiate_exit_block.body.voluntary_exits = signed_exits + signed_initiate_exit_block = state_transition_and_sign_block(spec, state, initiate_exit_block) + + for index in validator_indices: + assert state.validators[index].exit_epoch < spec.FAR_FUTURE_EPOCH + + # Process within epoch transition + exit_block = build_empty_block(spec, state, state.slot + spec.SLOTS_PER_EPOCH) + signed_exit_block = state_transition_and_sign_block(spec, state, exit_block) + + yield 'blocks', [signed_initiate_exit_block, signed_exit_block] + yield 'post', state + + for index in validator_indices: + assert state.validators[index].exit_epoch < spec.FAR_FUTURE_EPOCH + + @with_all_phases @spec_state_test def test_balance_driven_status_transitions(spec, state):