From 636a45a415073c650543aa353f0d297726c0be25 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sat, 11 May 2019 18:31:05 +0200 Subject: [PATCH] voluntary exit test case: invalid index --- .../test_process_voluntary_exit.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py index 1efc950e0..6b0f79288 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_voluntary_exit.py @@ -23,7 +23,6 @@ def run_voluntary_exit_processing(state, voluntary_exit, valid=True): If ``valid == False``, run expecting ``AssertionError`` """ validator_index = voluntary_exit.validator_index - pre_exit_epoch = state.validator_registry[validator_index].exit_epoch yield 'pre', state yield 'voluntary_exit', voluntary_exit @@ -33,6 +32,8 @@ def run_voluntary_exit_processing(state, voluntary_exit, valid=True): yield 'post', None return + pre_exit_epoch = state.validator_registry[validator_index].exit_epoch + process_voluntary_exit(state, voluntary_exit) yield 'post', state @@ -107,6 +108,26 @@ def test_success_exit_queue(state): ) +@spec_state_test +def test_validator_invalid_validator_index(state): + # move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + current_epoch = get_current_epoch(state) + validator_index = get_active_validator_indices(state, current_epoch)[0] + privkey = pubkey_to_privkey[state.validator_registry[validator_index].pubkey] + + voluntary_exit = build_voluntary_exit( + state, + current_epoch, + validator_index, + privkey, + ) + voluntary_exit.validator_index = len(state.validator_registry) + + yield from run_voluntary_exit_processing(state, voluntary_exit, False) + + @spec_state_test def test_validator_not_active(state): current_epoch = get_current_epoch(state)