diff --git a/test_libs/pyspec/tests/block_processing/test_process_deposit.py b/test_libs/pyspec/tests/block_processing/test_process_deposit.py index aee9789cd..c45191020 100644 --- a/test_libs/pyspec/tests/block_processing/test_process_deposit.py +++ b/test_libs/pyspec/tests/block_processing/test_process_deposit.py @@ -1,4 +1,3 @@ -from copy import deepcopy import pytest import eth2spec.phase0.spec as spec diff --git a/test_libs/pyspec/tests/block_processing/test_process_proposer_slashing.py b/test_libs/pyspec/tests/block_processing/test_process_proposer_slashing.py index 475221036..fbf4a1959 100644 --- a/test_libs/pyspec/tests/block_processing/test_process_proposer_slashing.py +++ b/test_libs/pyspec/tests/block_processing/test_process_proposer_slashing.py @@ -1,4 +1,3 @@ -from copy import deepcopy import pytest import eth2spec.phase0.spec as spec @@ -11,78 +10,82 @@ from tests.helpers import ( get_valid_proposer_slashing, ) -# mark entire file as 'proposer_slashings' -pytestmark = pytest.mark.proposer_slashings +from .block_test_helpers import spec_state_test def run_proposer_slashing_processing(state, proposer_slashing, valid=True): """ - Run ``process_proposer_slashing`` returning the pre and post state. + Run ``process_proposer_slashing``, yielding: + - pre-state ('pre') + - proposer_slashing ('proposer_slashing') + - post-state ('post'). If ``valid == False``, run expecting ``AssertionError`` """ - post_state = deepcopy(state) + pre_proposer_balance = get_balance(state, proposer_slashing.proposer_index) + + yield 'pre', state + yield 'proposer_slashing', proposer_slashing if not valid: with pytest.raises(AssertionError): - process_proposer_slashing(post_state, proposer_slashing) - return state, None + process_proposer_slashing(state, proposer_slashing) + yield 'post', None + return - process_proposer_slashing(post_state, proposer_slashing) + process_proposer_slashing(state, proposer_slashing) + yield 'post', state - slashed_validator = post_state.validator_registry[proposer_slashing.proposer_index] + # check if slashed + slashed_validator = state.validator_registry[proposer_slashing.proposer_index] assert slashed_validator.slashed assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH + # lost whistleblower reward assert ( - get_balance(post_state, proposer_slashing.proposer_index) < - get_balance(state, proposer_slashing.proposer_index) + get_balance(state, proposer_slashing.proposer_index) < + pre_proposer_balance ) - return state, post_state - +@spec_state_test def test_success(state): proposer_slashing = get_valid_proposer_slashing(state) - pre_state, post_state = run_proposer_slashing_processing(state, proposer_slashing) - - return pre_state, proposer_slashing, post_state + yield from run_proposer_slashing_processing(state, proposer_slashing) +@spec_state_test def test_epochs_are_different(state): proposer_slashing = get_valid_proposer_slashing(state) # set slots to be in different epochs proposer_slashing.header_2.slot += spec.SLOTS_PER_EPOCH - pre_state, post_state = run_proposer_slashing_processing(state, proposer_slashing, False) - - return pre_state, proposer_slashing, post_state + yield from run_proposer_slashing_processing(state, proposer_slashing, False) +@spec_state_test def test_headers_are_same(state): proposer_slashing = get_valid_proposer_slashing(state) # set headers to be the same proposer_slashing.header_2 = proposer_slashing.header_1 - pre_state, post_state = run_proposer_slashing_processing(state, proposer_slashing, False) - - return pre_state, proposer_slashing, post_state + yield from run_proposer_slashing_processing(state, proposer_slashing, False) +@spec_state_test def test_proposer_is_slashed(state): proposer_slashing = get_valid_proposer_slashing(state) # set proposer to slashed state.validator_registry[proposer_slashing.proposer_index].slashed = True - pre_state, post_state = run_proposer_slashing_processing(state, proposer_slashing, False) - - return pre_state, proposer_slashing, post_state + yield from run_proposer_slashing_processing(state, proposer_slashing, False) +@spec_state_test def test_proposer_is_withdrawn(state): proposer_slashing = get_valid_proposer_slashing(state) @@ -91,6 +94,4 @@ def test_proposer_is_withdrawn(state): proposer_index = proposer_slashing.proposer_index state.validator_registry[proposer_index].withdrawable_epoch = current_epoch - 1 - pre_state, post_state = run_proposer_slashing_processing(state, proposer_slashing, False) - - return pre_state, proposer_slashing, post_state + yield from run_proposer_slashing_processing(state, proposer_slashing, False)