add scaled churn limit tests for voluntary exits

This commit is contained in:
Danny Ryan 2021-09-07 20:49:54 -06:00
parent 43e79a7ee0
commit 6784025d64
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
2 changed files with 29 additions and 9 deletions

View File

@ -1,4 +1,9 @@
from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls, with_all_phases
from eth2spec.test.context import (
spec_state_test, expect_assertion_error,
always_bls, with_all_phases,
spec_test, single_phase,
with_custom_state, scaled_churn_balances,
)
from eth2spec.test.helpers.keys import pubkey_to_privkey
from eth2spec.test.helpers.voluntary_exits import sign_voluntary_exit
@ -68,9 +73,7 @@ def test_invalid_signature(spec, state):
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, False)
@with_all_phases
@spec_state_test
def test_success_exit_queue(spec, state):
def run_test_success_exit_queue(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -106,10 +109,27 @@ def test_success_exit_queue(spec, state):
# when processing an additional exit, it results in an exit in a later epoch
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit)
assert (
state.validators[validator_index].exit_epoch ==
state.validators[initial_indices[0]].exit_epoch + 1
)
for index in initial_indices:
assert (
state.validators[validator_index].exit_epoch ==
state.validators[index].exit_epoch + 1
)
@with_all_phases
@spec_state_test
def test_success_exit_queue__min_churn(spec, state):
yield from run_test_success_exit_queue(spec, state)
@with_all_phases
@spec_test
@with_custom_state(balances_fn=scaled_churn_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE)
@single_phase
def test_success_exit_queue__scaled_churn(spec, state):
churn_limit = spec.get_validator_churn_limit(state)
assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT
yield from run_test_success_exit_queue(spec, state)
@with_all_phases

View File

@ -302,7 +302,7 @@ def test_activation_queue_activation_and_ejection__1(spec, state):
@with_all_phases
@spec_state_test
def test_activation_queue_activation_and_ejection__churn_limit(spec, state):
num_validators_per_status= spec.get_validator_churn_limit(state)
num_validators_per_status = spec.get_validator_churn_limit(state)
yield from run_test_activation_queue_activation_and_ejection(spec, state, num_validators_per_status)