new proposer slashing tests

Co-Authored-By: jannikluhn <jannik@brainbot.com>
This commit is contained in:
protolambda 2019-05-11 17:01:12 +02:00
parent 8570584a95
commit 3189cf0079
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
2 changed files with 24 additions and 1 deletions

View File

@ -19,7 +19,6 @@ def run_proposer_slashing_processing(state, proposer_slashing, valid=True):
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
"""
pre_proposer_balance = get_balance(state, proposer_slashing.proposer_index)
yield 'pre', state
yield 'proposer_slashing', proposer_slashing
@ -29,6 +28,8 @@ def run_proposer_slashing_processing(state, proposer_slashing, valid=True):
yield 'post', None
return
pre_proposer_balance = get_balance(state, proposer_slashing.proposer_index)
process_proposer_slashing(state, proposer_slashing)
yield 'post', state
@ -52,6 +53,15 @@ def test_success(state):
yield from run_proposer_slashing_processing(state, proposer_slashing)
@spec_state_test
def test_invalid_proposer_index(state):
proposer_slashing = get_valid_proposer_slashing(state)
# Index just too high (by 1)
proposer_slashing.proposer_index = len(state.validator_registry)
yield from run_proposer_slashing_processing(state, proposer_slashing, False)
@spec_state_test
def test_epochs_are_different(state):
proposer_slashing = get_valid_proposer_slashing(state)
@ -72,6 +82,16 @@ def test_headers_are_same(state):
yield from run_proposer_slashing_processing(state, proposer_slashing, False)
@spec_state_test
def test_proposer_is_not_activated(state):
proposer_slashing = get_valid_proposer_slashing(state)
# set proposer to be not active yet
state.validator_registry[proposer_slashing.proposer_index].activation_epoch = get_current_epoch(state) + 1
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)

View File

@ -19,3 +19,6 @@ def expect_assertion_error(fn):
raise AssertionError('expected an assertion error, but got none.')
except AssertionError:
pass
except IndexError:
# Index errors are special; the spec is not explicit on bound checking, an IndexError is like a failed assert.
pass