update epoch processing tests to conform to processing pattern, add docs for epoch sub-transition testing
This commit is contained in:
parent
21c48b574f
commit
f98a8d534e
|
@ -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.
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue