def test_process_slashings(
    genesis_state,
    config,
    current_epoch,
    slashings,
    slots_per_epoch,
    epochs_per_slashings_vector,
    expected_penalty,
):
    state = genesis_state.mset(
        "slot",
        compute_start_slot_at_epoch(current_epoch, slots_per_epoch),
        "slashings",
        slashings,
    )
    slashing_validator_index = 0
    validator = state.validators[slashing_validator_index].mset(
        "slashed",
        True,
        "withdrawable_epoch",
        current_epoch + epochs_per_slashings_vector // 2,
    )
    state = state.transform(["validators", slashing_validator_index],
                            validator)

    result_state = process_slashings(state, config)
    penalty = (state.balances[slashing_validator_index] -
               result_state.balances[slashing_validator_index])
    assert penalty == expected_penalty
Пример #2
0
def test_process_slashings(
    genesis_state,
    config,
    current_epoch,
    slashings,
    slots_per_epoch,
    epochs_per_slashings_vector,
    expected_penalty,
):
    state = genesis_state.copy(
        slot=compute_start_slot_at_epoch(current_epoch, slots_per_epoch),
        slashings=slashings,
    )
    slashing_validator_index = 0
    validator = state.validators[slashing_validator_index].copy(
        slashed=True,
        withdrawable_epoch=current_epoch + epochs_per_slashings_vector // 2,
    )
    state = state.update_validator(slashing_validator_index, validator)

    result_state = process_slashings(state, config)
    penalty = (
        state.balances[slashing_validator_index]
        - result_state.balances[slashing_validator_index]
    )
    assert penalty == expected_penalty
def test_process_slashings(genesis_state,
                           config,
                           current_epoch,
                           latest_slashed_balances,
                           slots_per_epoch,
                           latest_slashed_exit_length,
                           expected_penalty):
    state = genesis_state.copy(
        slot=get_epoch_start_slot(current_epoch, slots_per_epoch),
        latest_slashed_balances=latest_slashed_balances,
    )
    slashing_validator_index = 0
    validator = state.validator_registry[slashing_validator_index].copy(
        slashed=True,
        withdrawable_epoch=current_epoch + latest_slashed_exit_length // 2
    )
    state = state.update_validator_registry(slashing_validator_index, validator)

    result_state = process_slashings(state, config)
    penalty = (
        state.validator_balances[slashing_validator_index] -
        result_state.validator_balances[slashing_validator_index]
    )
    assert penalty == expected_penalty