Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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),
    )
Ejemplo n.º 5
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]