def test_proposer_slashing(spec, state): # copy for later balance lookups. pre_state = state.copy() proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=True, signed_2=True) slashed_index = proposer_slashing.signed_header_1.message.proposer_index assert not state.validators[slashed_index].slashed yield 'pre', state # # Add to state via block transition # block = build_empty_block_for_next_slot(spec, state) block.body.proposer_slashings.append(proposer_slashing) signed_block = state_transition_and_sign_block(spec, state, block) yield 'blocks', [signed_block] yield 'post', state check_proposer_slashing_effect(spec, pre_state, state, slashed_index, block)
def test_multiple_different_proposer_slashings_same_block(spec, state): pre_state = state.copy() num_slashings = 3 proposer_slashings = [] for i in range(num_slashings): slashed_index = spec.get_active_validator_indices( state, spec.get_current_epoch(state))[i] assert not state.validators[slashed_index].slashed proposer_slashing = get_valid_proposer_slashing( spec, state, slashed_index=slashed_index, signed_1=True, signed_2=True) proposer_slashings.append(proposer_slashing) yield 'pre', state # # Add to state via block transition # block = build_empty_block_for_next_slot(spec, state) block.body.proposer_slashings = proposer_slashings signed_block = state_transition_and_sign_block(spec, state, block) yield 'blocks', [signed_block] yield 'post', state for proposer_slashing in proposer_slashings: slashed_index = proposer_slashing.signed_header_1.message.proposer_index check_proposer_slashing_effect(spec, pre_state, state, slashed_index, block)
def run_proposer_slashing_processing(spec, state, proposer_slashing, valid=True): """ Run ``process_proposer_slashing``, yielding: - pre-state ('pre') - proposer_slashing ('proposer_slashing') - post-state ('post'). If ``valid == False``, run expecting ``AssertionError`` """ pre_state = state.copy() yield 'pre', state yield 'proposer_slashing', proposer_slashing if not valid: expect_assertion_error( lambda: spec.process_proposer_slashing(state, proposer_slashing)) yield 'post', None return spec.process_proposer_slashing(state, proposer_slashing) yield 'post', state slashed_proposer_index = proposer_slashing.signed_header_1.message.proposer_index check_proposer_slashing_effect(spec, pre_state, state, slashed_proposer_index)