From f98a8d534e02e20ea5cff5d57441f60575f1ef87 Mon Sep 17 00:00:00 2001 From: protolambda Date: Thu, 23 May 2019 23:50:58 +0200 Subject: [PATCH] update epoch processing tests to conform to processing pattern, add docs for epoch sub-transition testing --- specs/test_formats/epoch_processing/README.md | 34 +++++++++++++++++++ .../test_process_registry_updates.py | 12 +++---- 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 specs/test_formats/epoch_processing/README.md diff --git a/specs/test_formats/epoch_processing/README.md b/specs/test_formats/epoch_processing/README.md new file mode 100644 index 000000000..041cb2fed --- /dev/null +++ b/specs/test_formats/epoch_processing/README.md @@ -0,0 +1,34 @@ +# Epoch processing tests + +The different epoch sub-transitions are tested individually with test handlers. +The format is similar to block-processing state-transition tests. +There is no "change" factor however, the transitions are a pure functions with just the pre-state as input. +Hence, the format is shared between each test-handler. (See test condition documentation on how to run the tests.) + +## Test case format + +```yaml +description: string -- description of test case, purely for debugging purposes +bls_required: bool -- optional, true if the test validity is strictly dependent on BLS being ON. False otherwise. +bls_ignored: bool -- optional, true if the test validity is strictly dependent on BLS being OFF. False otherwise. +pre: BeaconState -- state before running the sub-transition +post: BeaconState -- state after applying the epoch sub-transition. +``` + +Note: if both `bls_required` and `bls_ignored` are false (or simply not included), + then the test consumer can freely choose to run with BLS ON or OFF. +One may choose for OFF for performance reasons during repeated testing. Otherwise it is recommended to run with BLS ON. + +## Condition + +A handler of the `epoch_processing` test-runner should process these cases, + calling the corresponding processing implementation. + +Sub-transitions: + +| *`sub-transition-name`* | *`processing call`* | +|-------------------------|-----------------------------------| +| `crosslinks` | `process_crosslinks(state)` | +| `registry_updates` | `process_registry_updates(state)` | + +The resulting state should match the expected `post` state. diff --git a/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py index e11a5be2d..05f40218e 100644 --- a/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py +++ b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py @@ -3,8 +3,8 @@ import eth2spec.phase0.spec as spec from eth2spec.phase0.spec import ( get_current_epoch, is_active_validator, + process_registry_updates ) -from eth2spec.test.helpers.block import apply_empty_block from eth2spec.test.helpers.state import next_epoch from eth2spec.test.context import spec_state_test @@ -20,13 +20,12 @@ def test_activation(state): state.validator_registry[index].effective_balance = spec.MAX_EFFECTIVE_BALANCE assert not is_active_validator(state.validator_registry[index], get_current_epoch(state)) - for _ in range(spec.ACTIVATION_EXIT_DELAY): + for _ in range(spec.ACTIVATION_EXIT_DELAY + 1): next_epoch(state) yield 'pre', state - next_epoch(state) - yield 'trigger_block', apply_empty_block(state) + process_registry_updates(state) yield 'post', state @@ -47,13 +46,12 @@ def test_ejection(state): # Mock an ejection state.validator_registry[index].effective_balance = spec.EJECTION_BALANCE - for _ in range(spec.ACTIVATION_EXIT_DELAY): + for _ in range(spec.ACTIVATION_EXIT_DELAY + 1): next_epoch(state) yield 'pre', state - next_epoch(state) - yield 'trigger_block', apply_empty_block(state) + process_registry_updates(state) yield 'post', state