state builds from spec version

This commit is contained in:
Carl Beekhuizen 2019-05-31 11:33:47 +02:00
parent ec9f8f15ed
commit 0c57cfcaa7
No known key found for this signature in database
GPG Key ID: D05CA176D0020646
3 changed files with 6 additions and 119 deletions

View File

@ -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)

View File

@ -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

View File

@ -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