def test_full_random_without_leak_and_current_exit_0(spec, state): """ This test specifically ensures a validator exits in the current epoch to ensure rewards are handled properly in this case. """ rng = Random(1011) randomize_state(spec, state, rng) assert spec.is_in_inactivity_leak(state) patch_state_to_non_leaking(spec, state) assert not spec.is_in_inactivity_leak(state) target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 # move forward some epochs to process attestations added # by ``randomize_state`` before we exit validators in # what will be the current epoch for _ in range(2): next_epoch(spec, state) current_epoch = spec.get_current_epoch(state) for index in target_validators: # patch exited validators to exit in the current epoch validator = state.validators[index] validator.exit_epoch = current_epoch validator.withdrawable_epoch = current_epoch + spec.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY # re-randomize attestation participation for the current epoch randomize_attestation_participation(spec, state, rng) assert has_active_balance_differential(spec, state) yield from rewards_helpers.run_deltas(spec, state)
def test_full_random_without_leak_0(spec, state): rng = Random(1010) randomize_state(spec, state, rng) assert spec.is_in_inactivity_leak(state) patch_state_to_non_leaking(spec, state) assert not spec.is_in_inactivity_leak(state) target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 assert has_active_balance_differential(spec, state) yield from rewards_helpers.run_deltas(spec, state)
def test_full_random_4(spec, state): """ Ensure a rewards test with some exited (but not slashed) validators. """ rng = Random(5050) randomize_state(spec, state, rng) assert spec.is_in_inactivity_leak(state) target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 assert has_active_balance_differential(spec, state) yield from rewards_helpers.run_deltas(spec, state)
def test_random_with_exits_without_duplicates(spec, state): rng = random.Random(1502) randomize_state(spec, state, rng=rng, exit_fraction=0.1, slash_fraction=0.0) target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 assert has_active_balance_differential(spec, state) yield from _test_harness_for_randomized_test_case( spec, state, participation_fn=lambda comm: rng.sample(comm, len(comm) // 2), )
def test_altair_fork_random_mismatched_attestations(spec, phases, state): # Create a random state randomize_state(spec, state, rng=Random(2222)) # Now make two copies state_0 = state.copy() state_1 = state.copy() # Randomize attestation participation of both randomize_attestation_participation(spec, state_0, rng=Random(3333)) randomize_attestation_participation(spec, state_1, rng=Random(4444)) # Note: `run_fork_test` empties `current_epoch_attestations` # Use pending attestations from both random states in a single state for testing state_0.previous_epoch_attestations = state_0.previous_epoch_attestations + state_1.previous_epoch_attestations yield from run_fork_test(phases[ALTAIR], state_0)
def test_slashings_with_random_state(spec, state): rng = Random(9998) randomize_state(spec, state, rng) pre_balances = state.balances.copy() target_validators = get_unslashed_exited_validators(spec, state) assert len(target_validators) != 0 assert has_active_balance_differential(spec, state) slashed_indices = _setup_process_slashings_test( spec, state, not_slashable_set=target_validators) # ensure no accidental slashings of protected set... current_target_validators = get_unslashed_exited_validators(spec, state) assert len(current_target_validators) != 0 assert current_target_validators == target_validators yield from run_process_slashings(spec, state) for i in slashed_indices: assert state.balances[i] < pre_balances[i]
def test_merge_fork_random_large_validator_set(spec, phases, state): randomize_state(spec, state, rng=Random(7070)) yield from run_fork_test(phases[MERGE], state)
def test_merge_fork_random_misc_balances(spec, phases, state): randomize_state(spec, state, rng=Random(6060)) yield from run_fork_test(phases[MERGE], state)
def test_merge_fork_random_3(spec, phases, state): randomize_state(spec, state, rng=Random(4040)) yield from run_fork_test(phases[MERGE], state)
def run_test_full_random(spec, state, rng=Random(8020)): randomize_state(spec, state, rng) yield from run_deltas(spec, state)
def test_bellatrix_fork_random_large_validator_set(spec, phases, state): randomize_state(spec, state, rng=Random(7070)) yield from run_fork_test(phases[BELLATRIX], state)
def test_bellatrix_fork_random_misc_balances(spec, phases, state): randomize_state(spec, state, rng=Random(6060)) yield from run_fork_test(phases[BELLATRIX], state)
def test_bellatrix_fork_random_3(spec, phases, state): randomize_state(spec, state, rng=Random(4040)) yield from run_fork_test(phases[BELLATRIX], state)
def test_altair_fork_random_misc_balances(spec, phases, state): randomize_state(spec, state, rng=Random(6060)) yield from run_fork_test(phases[ALTAIR], state)
def test_altair_fork_random_duplicate_attestations(spec, phases, state): randomize_state(spec, state, rng=Random(1111)) # Note: `run_fork_test` empties `current_epoch_attestations` state.previous_epoch_attestations = state.previous_epoch_attestations + state.previous_epoch_attestations yield from run_fork_test(phases[ALTAIR], state)
def test_altair_fork_random_3(spec, phases, state): randomize_state(spec, state, rng=Random(4040)) yield from run_fork_test(phases[ALTAIR], state)
def test_altair_fork_random_large_validator_set(spec, phases, state): randomize_state(spec, state, rng=Random(7070)) yield from run_fork_test(phases[ALTAIR], state)