From 0c57cfcaa7b62191ad327121a440c288ad930668 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Fri, 31 May 2019 11:33:47 +0200 Subject: [PATCH] state builds from spec version --- .../test_process_proposer_slashing.py | 4 +- test_libs/pyspec/eth2spec/test/context.py | 5 +- ...est_process_early_derived_secret_reveal.py | 116 ------------------ 3 files changed, 6 insertions(+), 119 deletions(-) delete mode 100644 test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py 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 47f9ed1de..b35241859 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 @@ -40,17 +40,17 @@ def run_proposer_slashing_processing(spec, state, proposer_slashing, valid=True) ) -@spec_state_test @with_all_phases +@spec_state_test def test_success(spec, state): proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=True, signed_2=True) yield from run_proposer_slashing_processing(spec, state, proposer_slashing) +@with_all_phases @always_bls @spec_state_test -@with_all_phases def test_invalid_sig_1(spec, state): proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=False, signed_2=True) yield from run_proposer_slashing_processing(spec, state, proposer_slashing, False) diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index dcdd8140b..d0869ba68 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -9,7 +9,10 @@ from .utils import spectest, with_tags def with_state(fn): def entry(*args, **kw): - kw['state'] = create_genesis_state(spec=spec_phase0, num_validators=spec_phase0.SLOTS_PER_EPOCH * 8) + try: + kw['state'] = create_genesis_state(spec=kw['spec'], num_validators=spec_phase0.SLOTS_PER_EPOCH * 8) + except KeyError: + raise TypeError('Spec decorator must come before state decorator to inject spec into state.') return fn(*args, **kw) return entry diff --git a/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py b/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py deleted file mode 100644 index ad436ff29..000000000 --- a/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py +++ /dev/null @@ -1,116 +0,0 @@ -from copy import deepcopy -import pytest - -# mark entire file as 'randao_key_reveals' -pytestmark = pytest.mark.randao_key_reveals - - -def run_early_derived_secret_reveal_processing(state, randao_key_reveal, valid=True): - """ - Run ``process_randao_key_reveal`` returning the pre and post state. - If ``valid == False``, run expecting ``AssertionError`` - """ - post_state = deepcopy(state) - - if not valid: - with pytest.raises(AssertionError): - spec.process_early_derived_secret_reveal(post_state, randao_key_reveal) - return state, None - - spec.process_early_derived_secret_reveal(post_state, randao_key_reveal) - - slashed_validator = post_state.validator_registry[randao_key_reveal.revealed_index] - - if randao_key_reveal.epoch >= spec.get_current_epoch(state) + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING: - 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 - # FIXME: Currently broken because get_base_reward in genesis epoch is 0 - assert ( - post_state.balances[randao_key_reveal.revealed_index] < - state.balances[randao_key_reveal.revealed_index] - ) - - return state, post_state - - -def test_success(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal(state) - - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal) - - return pre_state, randao_key_reveal, post_state - - -def test_reveal_from_current_epoch(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal(state, spec.get_current_epoch(state)) - - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, False) - - return pre_state, randao_key_reveal, post_state - - -@pytest.mark.skip(reason="Not currently possible as we are testing at epoch 0") -def test_reveal_from_past_epoch(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal(state, spec.get_current_epoch(state) - 1) - - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, False) - - return pre_state, randao_key_reveal, post_state - - -def test_reveal_with_custody_padding(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal( - state, - spec.get_current_epoch(state) + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING, - ) - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, True) - - return pre_state, randao_key_reveal, post_state - - -def test_reveal_with_custody_padding_minus_one(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal( - state, - spec.get_current_epoch(state) + spec.CUSTODY_PERIOD_TO_RANDAO_PADDING - 1, - ) - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, True) - - return pre_state, randao_key_reveal, post_state - - -def test_double_reveal(state): - randao_key_reveal1 = helpers.get_valid_early_derived_secret_reveal( - state, - spec.get_current_epoch(state) + spec.RANDAO_PENALTY_EPOCHS + 1, - ) - pre_state, intermediate_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal1) - - randao_key_reveal2 = helpers.get_valid_early_derived_secret_reveal( - intermediate_state, - spec.get_current_epoch(pre_state) + spec.RANDAO_PENALTY_EPOCHS + 1, - ) - _, post_state = run_early_derived_secret_reveal_processing(intermediate_state, randao_key_reveal2, False) - - return pre_state, [randao_key_reveal1, randao_key_reveal2], post_state - - -def test_revealer_is_slashed(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal(state, spec.get_current_epoch(state)) - state.validator_registry[randao_key_reveal.revealed_index].slashed = True - - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, False) - - return pre_state, randao_key_reveal, post_state - - -def test_far_future_epoch(state): - randao_key_reveal = helpers.get_valid_early_derived_secret_reveal( - state, - spec.get_current_epoch(state) + spec.EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS, - ) - - pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, False) - - return pre_state, randao_key_reveal, post_state