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:
parent
ebba3f5891
commit
00872e0e92
|
@ -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,
|
||||||
|
@ -102,7 +101,7 @@ def test_bad_source_root(state):
|
||||||
attestation = get_valid_attestation(state)
|
attestation = get_valid_attestation(state)
|
||||||
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
|
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
|
||||||
|
|
||||||
attestation.data.source_root = b'\x42'*32
|
attestation.data.source_root = b'\x42' * 32
|
||||||
|
|
||||||
pre_state, post_state = run_attestation_processing(state, attestation, False)
|
pre_state, post_state = run_attestation_processing(state, attestation, False)
|
||||||
|
|
||||||
|
@ -113,7 +112,7 @@ def test_non_zero_crosslink_data_root(state):
|
||||||
attestation = get_valid_attestation(state)
|
attestation = get_valid_attestation(state)
|
||||||
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
|
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
|
||||||
|
|
||||||
attestation.data.crosslink_data_root = b'\x42'*32
|
attestation.data.crosslink_data_root = b'\x42' * 32
|
||||||
|
|
||||||
pre_state, post_state = run_attestation_processing(state, attestation, False)
|
pre_state, post_state = run_attestation_processing(state, attestation, False)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -54,7 +54,7 @@ def test_invalid_slot(state):
|
||||||
|
|
||||||
def test_invalid_previous_block_root(state):
|
def test_invalid_previous_block_root(state):
|
||||||
block = build_empty_block_for_next_slot(state)
|
block = build_empty_block_for_next_slot(state)
|
||||||
block.previous_block_root = b'\12'*32 # invalid prev root
|
block.previous_block_root = b'\12' * 32 # invalid prev root
|
||||||
|
|
||||||
pre_state, post_state = run_block_header_processing(state, block, valid=False)
|
pre_state, post_state = run_block_header_processing(state, block, valid=False)
|
||||||
return pre_state, block, None
|
return pre_state, block, None
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
#
|
#
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -249,7 +248,7 @@ def get_valid_proposer_slashing(state):
|
||||||
def get_valid_attester_slashing(state):
|
def get_valid_attester_slashing(state):
|
||||||
attestation_1 = get_valid_attestation(state)
|
attestation_1 = get_valid_attestation(state)
|
||||||
attestation_2 = deepcopy(attestation_1)
|
attestation_2 = deepcopy(attestation_1)
|
||||||
attestation_2.data.target_root = b'\x01'*32
|
attestation_2.data.target_root = b'\x01' * 32
|
||||||
|
|
||||||
return AttesterSlashing(
|
return AttesterSlashing(
|
||||||
attestation_1=convert_to_indexed(state, attestation_1),
|
attestation_1=convert_to_indexed(state, attestation_1),
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue