def run_test_full_fraction_incorrect(spec, state, correct_target, correct_head, fraction_incorrect): cached_prepare_state_with_attestations(spec, state) # Make fraction_incorrect of pending attestations have bad target/head as specified num_incorrect = int(fraction_incorrect * len(state.previous_epoch_attestations)) for pending_attestation in state.previous_epoch_attestations[: num_incorrect]: if not correct_target: pending_attestation.data.target.root = b'\x55' * 32 if not correct_head: pending_attestation.data.beacon_block_root = b'\x66' * 32 yield from run_deltas(spec, state)
def run_test_partial(spec, state, fraction_filled): cached_prepare_state_with_attestations(spec, state) # Remove portion of attestations if not is_post_altair(spec): num_attestations = int( len(state.previous_epoch_attestations) * fraction_filled) state.previous_epoch_attestations = state.previous_epoch_attestations[: num_attestations] else: for index in range(int(len(state.validators) * fraction_filled)): state.previous_epoch_participation[ index] = spec.ParticipationFlags(0b0000_0000) yield from run_deltas(spec, state)
def run_test_full_but_partial_participation(spec, state, rng=Random(5522)): cached_prepare_state_with_attestations(spec, state) if not is_post_altair(spec): for a in state.previous_epoch_attestations: a.aggregation_bits = [ rng.choice([True, False]) for _ in a.aggregation_bits ] else: for index in range(len(state.validators)): if rng.choice([True, False]): state.previous_epoch_participation[ index] = spec.ParticipationFlags(0b0000_0000) yield from run_deltas(spec, state)
def run_test_some_very_low_effective_balances_that_did_not_attest(spec, state): cached_prepare_state_with_attestations(spec, state) if not is_post_altair(spec): # Remove attestation attestation = state.previous_epoch_attestations[0] state.previous_epoch_attestations = state.previous_epoch_attestations[1:] # Set removed indices effective balance to very low amount indices = spec.get_unslashed_attesting_indices(state, [attestation]) for i, index in enumerate(indices): state.validators[index].effective_balance = i else: index = 0 state.validators[index].effective_balance = 1 state.previous_epoch_participation[index] = spec.ParticipationFlags(0b0000_0000) yield from run_deltas(spec, state)
def run_test_full_random(spec, state, rng=Random(8020)): set_some_new_deposits(spec, state, rng) exit_random_validators(spec, state, rng) slash_random_validators(spec, state, rng) cached_prepare_state_with_attestations(spec, state) for pending_attestation in state.previous_epoch_attestations: # ~1/3 have bad target if rng.randint(0, 2) == 0: pending_attestation.data.target.root = b'\x55' * 32 # ~1/3 have bad head if rng.randint(0, 2) == 0: pending_attestation.data.beacon_block_root = b'\x66' * 32 # ~50% participation pending_attestation.aggregation_bits = [rng.choice([True, False]) for _ in pending_attestation.aggregation_bits] # Random inclusion delay pending_attestation.inclusion_delay = rng.randint(1, spec.SLOTS_PER_EPOCH) yield from run_deltas(spec, state)
def run_test_full_mixed_delay(spec, state, rng=Random(1234)): cached_prepare_state_with_attestations(spec, state) for a in state.previous_epoch_attestations: a.inclusion_delay = rng.randint(1, spec.SLOTS_PER_EPOCH) yield from run_deltas(spec, state)
def run_test_full_delay_max_slots(spec, state): cached_prepare_state_with_attestations(spec, state) for a in state.previous_epoch_attestations: a.inclusion_delay += spec.SLOTS_PER_EPOCH yield from run_deltas(spec, state)
def run_test_full_delay_one_slot(spec, state): cached_prepare_state_with_attestations(spec, state) for a in state.previous_epoch_attestations: a.inclusion_delay += 1 yield from run_deltas(spec, state)
def run_test_with_exited_validators(spec, state, rng=Random(1337)): exit_random_validators(spec, state, rng) cached_prepare_state_with_attestations(spec, state) yield from run_deltas(spec, state)
def run_test_with_not_yet_activated_validators(spec, state, rng=Random(5555)): set_some_new_deposits(spec, state, rng) cached_prepare_state_with_attestations(spec, state) yield from run_deltas(spec, state)
def run_test_full_all_correct(spec, state): cached_prepare_state_with_attestations(spec, state) yield from run_deltas(spec, state)
def randomize_attestation_participation(spec, state, rng=Random(8020)): cached_prepare_state_with_attestations(spec, state) randomize_epoch_participation(spec, state, spec.get_previous_epoch(state), rng) randomize_epoch_participation(spec, state, spec.get_current_epoch(state), rng)