From 3189cf00797e5e9b76024428b32996fe5bc237b9 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sat, 11 May 2019 17:01:12 +0200 Subject: [PATCH] new proposer slashing tests Co-Authored-By: jannikluhn --- .../test_process_proposer_slashing.py | 22 ++++++++++++++++++- test_libs/pyspec/eth2spec/test/context.py | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py index 3bfb17062..609c97ce6 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py @@ -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) diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index d402714a1..408b7f867 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -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