def run_test_with_slashed_validators(spec, state, rng=Random(3322)): exit_random_validators(spec, state, rng) slash_random_validators(spec, state, rng) cached_prepare_state_with_attestations(spec, state) yield from run_deltas(spec, state)
def test_transition_with_one_fourth_exiting_validators_exit_at_fork( state, fork_epoch, spec, post_spec, pre_tag, post_tag): """ 1/4 validators initiated voluntary exit before the fork, and being exited and inactive *right after* the fork transition. """ exited_indices = exit_random_validators( spec, state, rng=random.Random(5566), fraction=0.25, exit_epoch=fork_epoch, from_epoch=spec.get_current_epoch(state), ) transition_until_fork(spec, state, fork_epoch) # check pre state assert len(exited_indices) > 0 for index in exited_indices: validator = state.validators[index] assert not validator.slashed assert fork_epoch == validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert spec.is_active_validator(validator, spec.get_current_epoch(state)) assert not spec.is_in_inactivity_leak(state) assert spec.get_current_epoch(state) < fork_epoch yield "pre", state # irregular state transition to handle fork: blocks = [] state, block = do_altair_fork(state, spec, post_spec, fork_epoch) blocks.append(post_tag(block)) # check post transition state for index in exited_indices: validator = state.validators[index] assert not validator.slashed assert not post_spec.is_active_validator( validator, post_spec.get_current_epoch(state)) assert not post_spec.is_in_inactivity_leak(state) # ensure that none of the current sync committee members are exited validators exited_pubkeys = [ state.validators[index].pubkey for index in exited_indices ] assert not any( set(exited_pubkeys).intersection( 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, only_last_block=True) yield "blocks", blocks yield "post", state