Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few missing slashing tests #2478

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ def check_proposer_slashing_effect(spec, pre_state, state, slashed_index, block=


def get_valid_proposer_slashing(spec, state, random_root=b'\x99' * 32,
slashed_index=None, signed_1=False, signed_2=False):
slashed_index=None, slot=None, signed_1=False, signed_2=False):
if slashed_index is None:
current_epoch = spec.get_current_epoch(state)
slashed_index = spec.get_active_validator_indices(state, current_epoch)[-1]
privkey = pubkey_to_privkey[state.validators[slashed_index].pubkey]
slot = state.slot
if slot is None:
slot = state.slot

header_1 = spec.BeaconBlockHeader(
slot=slot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
low_balances, misc_balances,
)
from eth2spec.test.helpers.attestations import sign_indexed_attestation
from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing, \
get_indexed_attestation_participants, get_attestation_2_data, get_attestation_1_data
from eth2spec.test.helpers.attester_slashings import (
get_valid_attester_slashing, get_valid_attester_slashing_by_indices,
get_indexed_attestation_participants, get_attestation_2_data, get_attestation_1_data,
)
from eth2spec.test.helpers.proposer_slashings import get_min_slashing_penalty_quotient
from eth2spec.test.helpers.state import (
get_balance,
Expand Down Expand Up @@ -126,6 +128,39 @@ def test_success_already_exited_recent(spec, state):
yield from run_attester_slashing_processing(spec, state, attester_slashing)


@with_all_phases
@spec_state_test
@always_bls
def test_success_proposer_index_slashed(spec, state):
# Transition past genesis slot because generally doesn't have a proposer
next_epoch_via_block(spec, state)

proposer_index = spec.get_beacon_proposer_index(state)
attester_slashing = get_valid_attester_slashing_by_indices(
spec, state,
[proposer_index],
signed_1=True, signed_2=True,
)

yield from run_attester_slashing_processing(spec, state, attester_slashing)


@with_all_phases
@spec_state_test
def test_success_attestation_from_future(spec, state):
# Transition state to future to enable generation of a "future" attestation
future_state = state.copy()
next_epoch_via_block(spec, future_state)
# Generate slashing using the future state
attester_slashing = get_valid_attester_slashing(
spec, future_state,
slot=state.slot + 5, # Slot is in the future wrt `state`
signed_1=True, signed_2=True
)

yield from run_attester_slashing_processing(spec, state, attester_slashing)


@with_all_phases
@with_custom_state(balances_fn=low_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE)
@spec_test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def test_success_slashed_and_proposer_index_the_same(spec, state):
yield from run_proposer_slashing_processing(spec, state, proposer_slashing)


@with_all_phases
@spec_state_test
def test_success_block_header_from_future(spec, state):
proposer_slashing = get_valid_proposer_slashing(spec, state, slot=state.slot + 5, signed_1=True, signed_2=True)

yield from run_proposer_slashing_processing(spec, state, proposer_slashing)


@with_all_phases
@spec_state_test
@always_bls
Expand Down