add multiple exits block sanity test

This commit is contained in:
Danny Ryan 2020-05-07 12:23:37 -06:00
parent ee7d11d18f
commit 4ad3d65d10
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
2 changed files with 34 additions and 2 deletions

View File

@ -19,14 +19,14 @@ def check_proposer_slashing_effect(spec, pre_state, state, slashed_index):
== get_balance(pre_state, slashed_index) - slash_penalty == get_balance(pre_state, slashed_index) - slash_penalty
) )
# block proposer gained whistleblower reward # block proposer gained whistleblower reward
# >= becase proposer could have reported multiple # >= because proposer could have reported multiple
assert ( assert (
get_balance(state, proposer_index) get_balance(state, proposer_index)
>= get_balance(pre_state, proposer_index) + whistleblower_reward >= get_balance(pre_state, proposer_index) + whistleblower_reward
) )
else: else:
# proposer reported themself so get penalty and reward # proposer reported themself so get penalty and reward
# >= becase proposer could have reported multiple # >= because proposer could have reported multiple
assert ( assert (
get_balance(state, slashed_index) get_balance(state, slashed_index)
>= get_balance(pre_state, slashed_index) - slash_penalty + whistleblower_reward >= get_balance(pre_state, slashed_index) - slash_penalty + whistleblower_reward

View File

@ -582,6 +582,38 @@ def test_double_validator_exit_same_block(spec, state):
yield 'post', None 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 @with_all_phases
@spec_state_test @spec_state_test
def test_balance_driven_status_transitions(spec, state): def test_balance_driven_status_transitions(spec, state):