This commit is contained in:
Danny Ryan 2019-04-14 17:52:50 +10:00
parent 7705ecf89c
commit da4a1430ea
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
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(

View File

@ -199,7 +199,7 @@ def build_deposit(state,
def get_valid_proposer_slashing(state):
current_epoch = get_current_epoch(state)
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]
slot = state.slot

View File

@ -278,7 +278,7 @@ def test_attestation(state):
def test_voluntary_exit(state):
pre_state = deepcopy(state)
validator_index = get_active_validator_indices(
pre_state.validator_registry,
pre_state,
get_current_epoch(pre_state)
)[-1]
@ -326,7 +326,7 @@ def test_voluntary_exit(state):
def test_no_exit_churn_too_long_since_change(state):
pre_state = deepcopy(state)
validator_index = get_active_validator_indices(
pre_state.validator_registry,
pre_state,
get_current_epoch(pre_state)
)[-1]
@ -346,8 +346,8 @@ def test_no_exit_churn_too_long_since_change(state):
state_transition(post_state, block)
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
assert post_state.exit_queue_churn == pre_state.exit_queue_churn
assert post_state.exit_queue_epoch == pre_state.exit_queue_epoch
return pre_state, [block], post_state
@ -355,8 +355,8 @@ def test_no_exit_churn_too_long_since_change(state):
def test_transfer(state):
pre_state = deepcopy(state)
current_epoch = get_current_epoch(pre_state)
sender_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[-1]
recipient_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[0]
sender_index = get_active_validator_indices(pre_state, current_epoch)[-1]
recipient_index = get_active_validator_indices(pre_state, current_epoch)[0]
transfer_pubkey = pubkeys[-1]
transfer_privkey = privkeys[-1]
amount = get_balance(pre_state, sender_index)
@ -407,7 +407,7 @@ def test_balance_driven_status_transitions(state):
pre_state = deepcopy(state)
current_epoch = get_current_epoch(pre_state)
validator_index = get_active_validator_indices(pre_state.validator_registry, current_epoch)[-1]
validator_index = get_active_validator_indices(pre_state, current_epoch)[-1]
assert pre_state.validator_registry[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH