This commit is contained in:
Danny Ryan
2019-04-14 17:52:50 +10:00
parent 7705ecf89c
commit da4a1430ea
3 changed files with 20 additions and 19 deletions

View File

@@ -5,6 +5,7 @@ import build.phase0.spec as spec
from build.phase0.spec import (
get_active_validator_indices,
get_churn_limit,
get_current_epoch,
process_voluntary_exit,
)
@@ -44,7 +45,7 @@ def test_success(state):
state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = get_current_epoch(state)
validator_index = get_active_validator_indices(state.validator_registry, current_epoch)[0]
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(
@@ -65,7 +66,7 @@ def test_success_exit_queue(state):
current_epoch = get_current_epoch(state)
# exit `MAX_EXITS_PER_EPOCH`
initial_indices = get_active_validator_indices(state.validator_registry,current_epoch)[:spec.MAX_EXITS_PER_EPOCH]
initial_indices = get_active_validator_indices(state, current_epoch)[:get_churn_limit(state)]
post_state = state
for index in initial_indices:
privkey = pubkey_to_privkey[state.validator_registry[index].pubkey]
@@ -77,13 +78,13 @@ def test_success_exit_queue(state):
)
pre_state, post_state = run_voluntary_exit_processing(post_state, voluntary_exit)
assert post_state.exit_queue_filled > pre_state.exit_queue_filled
assert post_state.exit_epoch >= pre_state.exit_epoch
assert post_state.exit_queue_churn > pre_state.exit_queue_churn
assert post_state.exit_queue_epoch >= pre_state.exit_queue_epoch
assert post_state.exit_epoch == pre_state.exit_epoch
assert post_state.exit_queue_epoch == pre_state.exit_queue_epoch
# exit an additional validator
validator_index = get_active_validator_indices(state.validator_registry,current_epoch)[-1]
validator_index = get_active_validator_indices(state, current_epoch)[-1]
privkey = pubkey_to_privkey[state.validator_registry[validator_index].pubkey]
voluntary_exit = build_voluntary_exit(
state,
@@ -98,8 +99,8 @@ def test_success_exit_queue(state):
post_state.validator_registry[validator_index].exit_epoch ==
post_state.validator_registry[initial_indices[0]].exit_epoch + 1
)
assert post_state.exit_queue_filled == 1
assert post_state.exit_epoch == pre_state.exit_epoch + 1
assert post_state.exit_queue_churn == 0
assert post_state.exit_queue_epoch == pre_state.exit_queue_epoch + 1
return pre_state, voluntary_exit, post_state
@@ -107,7 +108,7 @@ def test_success_exit_queue(state):
def test_validator_not_active(state):
current_epoch = get_current_epoch(state)
validator_index = get_active_validator_indices(state.validator_registry, current_epoch)[0]
validator_index = get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validator_registry[validator_index].pubkey]
state.validator_registry[validator_index].activation_epoch = spec.FAR_FUTURE_EPOCH
@@ -131,7 +132,7 @@ def test_validator_already_exited(state):
state.slot += spec.PERSISTENT_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = get_current_epoch(state)
validator_index = get_active_validator_indices(state.validator_registry, current_epoch)[0]
validator_index = get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validator_registry[validator_index].pubkey]
# but validator already has exited
@@ -150,7 +151,7 @@ def test_validator_already_exited(state):
def test_validator_not_active_long_enough(state):
current_epoch = get_current_epoch(state)
validator_index = get_active_validator_indices(state.validator_registry, current_epoch)[0]
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(