Updated tests

1. No Validator.initiated_exit field. Fix the related tests.
2. Update state_transition flow - rename `process_ejections` to
`process_balance_driven_status_transitions` and remove `process_exit_queue`
3. Linter, formatting
This commit is contained in:
Hsiao-Wei Wang 2019-04-07 02:09:07 +11:00
parent ebba3f5891
commit 00872e0e92
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
8 changed files with 13 additions and 58 deletions

View File

@ -7,7 +7,6 @@ from build.phase0.state_transition import (
state_transition, state_transition,
) )
from build.phase0.spec import ( from build.phase0.spec import (
ZERO_HASH,
get_current_epoch, get_current_epoch,
process_attestation, process_attestation,
slot_to_epoch, slot_to_epoch,

View File

@ -31,7 +31,6 @@ def run_attester_slashing_processing(state, attester_slashing, valid=True):
slashed_index = attester_slashing.attestation_1.custody_bit_0_indices[0] slashed_index = attester_slashing.attestation_1.custody_bit_0_indices[0]
slashed_validator = post_state.validator_registry[slashed_index] slashed_validator = post_state.validator_registry[slashed_index]
assert not slashed_validator.initiated_exit
assert slashed_validator.slashed assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH

View File

@ -30,7 +30,6 @@ def run_proposer_slashing_processing(state, proposer_slashing, valid=True):
process_proposer_slashing(post_state, proposer_slashing) process_proposer_slashing(post_state, proposer_slashing)
slashed_validator = post_state.validator_registry[proposer_slashing.proposer_index] slashed_validator = post_state.validator_registry[proposer_slashing.proposer_index]
assert not slashed_validator.initiated_exit
assert slashed_validator.slashed assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH

View File

@ -47,8 +47,8 @@ def test_success(state):
# #
process_voluntary_exit(post_state, voluntary_exit) process_voluntary_exit(post_state, voluntary_exit)
assert not pre_state.validator_registry[validator_index].initiated_exit assert pre_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH
assert post_state.validator_registry[validator_index].initiated_exit assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
return pre_state, voluntary_exit, post_state return pre_state, voluntary_exit, post_state
@ -111,37 +111,6 @@ def test_validator_already_exited(state):
return pre_state, voluntary_exit, None return pre_state, voluntary_exit, None
def test_validator_already_initiated_exit(state):
pre_state = deepcopy(state)
#
# setup pre_state
#
# move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow validator able to exit
pre_state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = get_current_epoch(pre_state)
validator_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0]
privkey = pubkey_to_privkey[pre_state.validator_registry[validator_index].pubkey]
# but validator already has initiated exit
pre_state.validator_registry[validator_index].initiated_exit = True
#
# build voluntary exit
#
voluntary_exit = build_voluntary_exit(
pre_state,
current_epoch,
validator_index,
privkey,
)
with pytest.raises(AssertionError):
process_voluntary_exit(pre_state, voluntary_exit)
return pre_state, voluntary_exit, None
def test_validator_not_active_long_enough(state): def test_validator_not_active_long_enough(state):
pre_state = deepcopy(state) pre_state = deepcopy(state)
# #
@ -151,9 +120,6 @@ def test_validator_not_active_long_enough(state):
validator_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0] validator_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0]
privkey = pubkey_to_privkey[pre_state.validator_registry[validator_index].pubkey] privkey = pubkey_to_privkey[pre_state.validator_registry[validator_index].pubkey]
# but validator already has initiated exit
pre_state.validator_registry[validator_index].initiated_exit = True
# #
# build voluntary exit # build voluntary exit
# #

View File

@ -25,7 +25,6 @@ from build.phase0.spec import (
get_attestation_participants, get_attestation_participants,
get_block_root, get_block_root,
get_crosslink_committee_for_attestation, get_crosslink_committee_for_attestation,
get_crosslink_committees_at_slot,
get_current_epoch, get_current_epoch,
get_domain, get_domain,
get_empty_block, get_empty_block,

View File

@ -128,11 +128,9 @@ def test_proposer_slashing(state):
block.body.proposer_slashings.append(proposer_slashing) block.body.proposer_slashings.append(proposer_slashing)
state_transition(test_state, block) state_transition(test_state, block)
assert not state.validator_registry[validator_index].initiated_exit
assert not state.validator_registry[validator_index].slashed assert not state.validator_registry[validator_index].slashed
slashed_validator = test_state.validator_registry[validator_index] slashed_validator = test_state.validator_registry[validator_index]
assert not slashed_validator.initiated_exit
assert slashed_validator.slashed assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH
@ -154,11 +152,9 @@ def test_attester_slashing(state):
block.body.attester_slashings.append(attester_slashing) block.body.attester_slashings.append(attester_slashing)
state_transition(test_state, block) state_transition(test_state, block)
assert not state.validator_registry[validator_index].initiated_exit
assert not state.validator_registry[validator_index].slashed assert not state.validator_registry[validator_index].slashed
slashed_validator = test_state.validator_registry[validator_index] slashed_validator = test_state.validator_registry[validator_index]
assert not slashed_validator.initiated_exit
assert slashed_validator.slashed assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH
@ -316,9 +312,7 @@ def test_voluntary_exit(state):
initiate_exit_block.body.voluntary_exits.append(voluntary_exit) initiate_exit_block.body.voluntary_exits.append(voluntary_exit)
state_transition(post_state, initiate_exit_block) state_transition(post_state, initiate_exit_block)
assert not pre_state.validator_registry[validator_index].initiated_exit assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
assert post_state.validator_registry[validator_index].initiated_exit
assert post_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH
# #
# Process within epoch transition # Process within epoch transition
@ -350,8 +344,6 @@ def test_no_exit_churn_too_long_since_change(state):
pre_state.validator_registry_update_epoch = ( pre_state.validator_registry_update_epoch = (
get_current_epoch(pre_state) - spec.LATEST_SLASHED_EXIT_LENGTH get_current_epoch(pre_state) - spec.LATEST_SLASHED_EXIT_LENGTH
) )
# set validator to have previously initiated exit
pre_state.validator_registry[validator_index].initiated_exit = True
post_state = deepcopy(pre_state) post_state = deepcopy(pre_state)
@ -362,8 +354,10 @@ def test_no_exit_churn_too_long_since_change(state):
block.slot += spec.SLOTS_PER_EPOCH block.slot += spec.SLOTS_PER_EPOCH
state_transition(post_state, block) state_transition(post_state, block)
assert post_state.validator_registry_update_epoch == get_current_epoch(post_state) - 1 assert post_state.validator_registry[validator_index].activation_eligibility_epoch == spec.FAR_FUTURE_EPOCH
assert post_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH assert post_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH
assert post_state.exit_queue_filled == pre_state.exit_queue_filled
assert post_state.exit_epoch == pre_state.exit_epoch
return pre_state, [block], post_state return pre_state, [block], post_state
@ -419,7 +413,7 @@ def test_transfer(state):
return pre_state, [block], post_state return pre_state, [block], post_state
def test_ejection(state): def test_balance_driven_status_transitions(state):
pre_state = deepcopy(state) pre_state = deepcopy(state)
current_epoch = get_current_epoch(pre_state) current_epoch = get_current_epoch(pre_state)
@ -438,7 +432,7 @@ def test_ejection(state):
block.slot += spec.SLOTS_PER_EPOCH block.slot += spec.SLOTS_PER_EPOCH
state_transition(post_state, block) state_transition(post_state, block)
assert post_state.validator_registry[validator_index].initiated_exit == True assert post_state.validator_registry[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
return pre_state, [block], post_state return pre_state, [block], post_state

View File

@ -94,10 +94,9 @@ def process_epoch_transition(state: BeaconState) -> None:
spec.process_crosslinks(state) spec.process_crosslinks(state)
spec.maybe_reset_eth1_period(state) spec.maybe_reset_eth1_period(state)
spec.apply_rewards(state) spec.apply_rewards(state)
spec.process_ejections(state) spec.process_balance_driven_status_transitions(state)
spec.update_registry(state) spec.update_registry(state)
spec.process_slashings(state) spec.process_slashings(state)
spec.process_exit_queue(state)
spec.finish_epoch_update(state) spec.finish_epoch_update(state)