diff --git a/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py b/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py index a783d2517..ac0a1cce2 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py +++ b/tests/core/pyspec/eth2spec/test/helpers/proposer_slashings.py @@ -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, diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py index 940bc47fb..b620a7342 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_attester_slashing.py @@ -6,8 +6,10 @@ from eth2spec.test.context import ( 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, @@ -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 diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_proposer_slashing.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_proposer_slashing.py index 48bc5ba3d..6ca87adae 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_proposer_slashing.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_proposer_slashing.py @@ -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