From 81a83898cf29e25ce536f2fadcf19c0362ab893e Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 15 Apr 2021 12:19:51 -0500 Subject: [PATCH 1/3] add committee progress tests for non genesis case --- .../test_process_sync_committee_updates.py | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py index 7ba2645a2..c5bd9443e 100644 --- a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py +++ b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py @@ -1,7 +1,11 @@ from eth2spec.test.context import ( spec_state_test, + spec_test, with_all_phases_except, with_configs, + with_custom_state, + single_phase, + misc_balances, ) from eth2spec.test.helpers.constants import ( PHASE0, @@ -13,20 +17,12 @@ from eth2spec.test.helpers.epoch_processing import ( ) -@with_all_phases_except([PHASE0]) -@spec_state_test -@with_configs([MINIMAL], reason="too slow") -def test_sync_committees_progress(spec, state): - current_epoch = spec.get_current_epoch(state) - # NOTE: if not in the genesis epoch, period math below needs to be - # adjusted relative to the current epoch - assert current_epoch == 0 - +def run_sync_committees_progress_test(spec, state): first_sync_committee = state.current_sync_committee second_sync_committee = state.next_sync_committee - slot_at_end_of_current_period = spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - 1 - transition_to(spec, state, slot_at_end_of_current_period) + end_slot_of_current_period = state.slot + spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - 1 + transition_to(spec, state, end_slot_of_current_period) # Ensure assignments have not changed: assert state.current_sync_committee == first_sync_committee @@ -36,7 +32,39 @@ def test_sync_committees_progress(spec, state): # Can compute the third committee having computed final balances in the last epoch # of this `EPOCHS_PER_SYNC_COMMITTEE_PERIOD` - third_sync_committee = spec.get_sync_committee(state, 2 * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD) + current_epoch = spec.get_current_epoch(state) + third_sync_committee = spec.get_sync_committee(state, current_epoch + 2 * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD) assert state.current_sync_committee == second_sync_committee assert state.next_sync_committee == third_sync_committee + + +@with_all_phases_except([PHASE0]) +@spec_state_test +@with_configs([MINIMAL], reason="too slow") +def test_sync_committees_progress_genesis(spec, state): + # Genesis epoch period has an exceptional case + spec.get_current_epoch(state) + assert spec.get_current_epoch(state) == spec.GENESIS_EPOCH + + yield from run_sync_committees_progress_test(spec, state) + + +@with_all_phases_except([PHASE0]) +@spec_state_test +@with_configs([MINIMAL], reason="too slow") +def test_sync_committees_progress_not_genesis(spec, state): + # Transition out of the genesis epoch period to test non-exceptional case + start_slot_of_next_period = state.slot + spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + transition_to(spec, state, start_slot_of_next_period) + + yield from run_sync_committees_progress_test(spec, state) + + +@with_all_phases_except([PHASE0]) +@with_custom_state(balances_fn=misc_balances, threshold_fn=lambda spec: spec.EJECTION_BALANCE) +@spec_test +@single_phase +@with_configs([MINIMAL], reason="too slow") +def test_sync_committees_progress_misc_balances(spec, state): + yield from run_sync_committees_progress_test(spec, state) From 7167c5a9d9b05ed1b57e356206930a15bce9c5e7 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 16 Apr 2021 11:32:27 -0500 Subject: [PATCH 2/3] generate sync committee update tests with always_bls --- .../test_process_sync_committee_updates.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py index c5bd9443e..e88d3ef1a 100644 --- a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py +++ b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py @@ -1,4 +1,5 @@ from eth2spec.test.context import ( + always_bls, spec_state_test, spec_test, with_all_phases_except, @@ -17,6 +18,11 @@ from eth2spec.test.helpers.epoch_processing import ( ) +# +# Note: +# Calculating sync committees requires pubkey aggregation, thus all tests are generated with `always_bls` +# + def run_sync_committees_progress_test(spec, state): first_sync_committee = state.current_sync_committee second_sync_committee = state.next_sync_committee @@ -41,6 +47,7 @@ def run_sync_committees_progress_test(spec, state): @with_all_phases_except([PHASE0]) @spec_state_test +@always_bls @with_configs([MINIMAL], reason="too slow") def test_sync_committees_progress_genesis(spec, state): # Genesis epoch period has an exceptional case @@ -52,6 +59,7 @@ def test_sync_committees_progress_genesis(spec, state): @with_all_phases_except([PHASE0]) @spec_state_test +@always_bls @with_configs([MINIMAL], reason="too slow") def test_sync_committees_progress_not_genesis(spec, state): # Transition out of the genesis epoch period to test non-exceptional case @@ -65,6 +73,7 @@ def test_sync_committees_progress_not_genesis(spec, state): @with_custom_state(balances_fn=misc_balances, threshold_fn=lambda spec: spec.EJECTION_BALANCE) @spec_test @single_phase +@always_bls @with_configs([MINIMAL], reason="too slow") def test_sync_committees_progress_misc_balances(spec, state): yield from run_sync_committees_progress_test(spec, state) From 55f2cc6e414f9ea26bfe5856f329d84b522dbb39 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 16 Apr 2021 11:42:26 -0500 Subject: [PATCH 3/3] address @ralexstokes PR comments --- .../test_process_sync_committee_updates.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py index e88d3ef1a..8ffc51507 100644 --- a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py +++ b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py @@ -27,7 +27,11 @@ def run_sync_committees_progress_test(spec, state): first_sync_committee = state.current_sync_committee second_sync_committee = state.next_sync_committee - end_slot_of_current_period = state.slot + spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - 1 + current_period = spec.get_current_epoch(state) // spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD + next_period = current_period + 1 + next_period_start_epoch = next_period * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD + next_period_start_slot = next_period_start_epoch * spec.SLOTS_PER_EPOCH + end_slot_of_current_period = next_period_start_slot - 1 transition_to(spec, state, end_slot_of_current_period) # Ensure assignments have not changed: @@ -51,7 +55,6 @@ def run_sync_committees_progress_test(spec, state): @with_configs([MINIMAL], reason="too slow") def test_sync_committees_progress_genesis(spec, state): # Genesis epoch period has an exceptional case - spec.get_current_epoch(state) assert spec.get_current_epoch(state) == spec.GENESIS_EPOCH yield from run_sync_committees_progress_test(spec, state) @@ -63,8 +66,9 @@ def test_sync_committees_progress_genesis(spec, state): @with_configs([MINIMAL], reason="too slow") def test_sync_committees_progress_not_genesis(spec, state): # Transition out of the genesis epoch period to test non-exceptional case - start_slot_of_next_period = state.slot + spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - transition_to(spec, state, start_slot_of_next_period) + assert spec.get_current_epoch(state) == spec.GENESIS_EPOCH + slot_in_next_period = state.slot + spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + transition_to(spec, state, slot_in_next_period) yield from run_sync_committees_progress_test(spec, state)