From b4b4e9571da32e6ff13cd550cb1308cfdf703919 Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 25 Jun 2019 04:45:53 +0200 Subject: [PATCH] test activation queue --- .../test_process_registry_updates.py | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py index d92220910..6c1319a5b 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py @@ -30,18 +30,20 @@ def run_process_registry_updates(spec, state, valid=True): yield 'post', state -@with_all_phases -@spec_state_test -def test_activation(spec, state): - index = 0 +def mock_deposit(spec, state, index): assert spec.is_active_validator(state.validators[index], spec.get_current_epoch(state)) - - # Mock a new deposit state.validators[index].activation_eligibility_epoch = spec.FAR_FUTURE_EPOCH state.validators[index].activation_epoch = spec.FAR_FUTURE_EPOCH state.validators[index].effective_balance = spec.MAX_EFFECTIVE_BALANCE assert not spec.is_active_validator(state.validators[index], spec.get_current_epoch(state)) + +@with_all_phases +@spec_state_test +def test_activation(spec, state): + index = 0 + mock_deposit(spec, state, index) + for _ in range(spec.ACTIVATION_EXIT_DELAY + 1): next_epoch(spec, state) @@ -49,10 +51,39 @@ def test_activation(spec, state): assert state.validators[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH assert state.validators[index].activation_epoch != spec.FAR_FUTURE_EPOCH - assert spec.is_active_validator( - state.validators[index], - spec.get_current_epoch(state), - ) + assert spec.is_active_validator(state.validators[index], spec.get_current_epoch(state)) + + +@with_all_phases +@spec_state_test +def test_activation_queue_sorting(spec, state): + mock_activations = 10 + + epoch = spec.get_current_epoch(state) + for i in range(mock_activations): + mock_deposit(spec, state, i) + state.validators[i].activation_eligibility_epoch = epoch + 1 + + # give the last priority over the others + state.validators[mock_activations - 1].activation_eligibility_epoch = epoch + + # make sure we are hitting the churn + churn_limit = spec.get_churn_limit(state) + assert mock_activations > churn_limit + + yield from run_process_registry_updates(spec, state) + + # the first got in as second + assert state.validators[0].activation_epoch != spec.FAR_FUTURE_EPOCH + # the prioritized got in as first + assert state.validators[mock_activations - 1].activation_epoch != spec.FAR_FUTURE_EPOCH + # the second last is at the end of the queue, and did not make the churn, + # hence is not assigned an activation_epoch yet. + assert state.validators[mock_activations - 2].activation_epoch == spec.FAR_FUTURE_EPOCH + # the one at churn_limit - 1 did not make it, it was out-prioritized + assert state.validators[churn_limit - 1].activation_epoch == spec.FAR_FUTURE_EPOCH + # but the the one in front of the above did + assert state.validators[churn_limit - 2].activation_epoch != spec.FAR_FUTURE_EPOCH @with_all_phases