-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1114 from ethereum/finish-state-tests-intro
Finish state tests intro
- Loading branch information
Showing
30 changed files
with
421 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Sanity tests | ||
|
||
The aim of the sanity tests is to set a base-line on what really needs to pass, i.e. the essentials. | ||
|
||
There are two handlers, documented individually: | ||
- [`slots`](./slots.md): transitions of one or more slots (and epoch transitions within) | ||
- [`blocks`](./blocks.md): transitions triggered by one or more blocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Sanity blocks testing | ||
|
||
Sanity tests to cover a series of one or more blocks being processed, aiming to cover common changes. | ||
|
||
## 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 through the transitions triggered by the blocks. | ||
blocks: [BeaconBlock] -- blocks to process, in given order, following the main transition function (i.e. process slot and epoch transitions in between blocks as normal) | ||
post: BeaconState -- state after applying all the transitions triggered by the blocks. | ||
``` | ||
## Condition | ||
The resulting state should match the expected `post` state, or if the `post` state is left blank, | ||
the handler should reject the series of blocks as invalid. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Sanity slots testing | ||
|
||
Sanity tests to cover a series of one or more empty-slot transitions being processed, aiming to cover common changes. | ||
|
||
## 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 through the transitions. | ||
slots: N -- amount of slots to process, N being a positive numer. | ||
post: BeaconState -- state after applying all the transitions. | ||
``` | ||
The transition with pure time, no blocks, is known as `state_transition_to(state, slot)` in the spec. | ||
This runs state-caching (pure slot transition) and epoch processing (every E slots). | ||
|
||
To process the data, call `state_transition_to(pre, pre.slot + N)`. And see if `pre` mutated into the equivalent of `post`. | ||
|
||
|
||
## Condition | ||
|
||
The resulting state should match the expected `post` state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Epoch processing | ||
|
||
Epoch processing covers the sub-transitions during an epoch change. | ||
|
||
An epoch-processing test-runner can consume these sub-transition test-suites, | ||
and handle different kinds of epoch sub-transitions by processing the cases using the specified test handler. | ||
|
||
Information on the format of the tests can be found in the [epoch-processing test formats documentation](../../specs/test_formats/epoch_processing/README.md). | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Callable, Iterable | ||
|
||
from eth2spec.phase0 import spec | ||
from eth2spec.test.epoch_processing import ( | ||
test_process_crosslinks, | ||
test_process_registry_updates | ||
) | ||
from gen_base import gen_runner, gen_suite, gen_typing | ||
from gen_from_tests.gen import generate_from_tests | ||
from preset_loader import loader | ||
|
||
|
||
def create_suite(transition_name: str, config_name: str, get_cases: Callable[[], Iterable[gen_typing.TestCase]]) \ | ||
-> Callable[[str], gen_typing.TestSuiteOutput]: | ||
def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput: | ||
presets = loader.load_presets(configs_path, config_name) | ||
spec.apply_constants_preset(presets) | ||
|
||
return ("%s_%s" % (transition_name, config_name), transition_name, gen_suite.render_suite( | ||
title="%s epoch processing" % transition_name, | ||
summary="Test suite for %s type epoch processing" % transition_name, | ||
forks_timeline="testing", | ||
forks=["phase0"], | ||
config=config_name, | ||
runner="epoch_processing", | ||
handler=transition_name, | ||
test_cases=get_cases())) | ||
|
||
return suite_definition | ||
|
||
|
||
if __name__ == "__main__": | ||
gen_runner.run_generator("epoch_processing", [ | ||
create_suite('crosslinks', 'minimal', lambda: generate_from_tests(test_process_crosslinks)), | ||
create_suite('crosslinks', 'mainnet', lambda: generate_from_tests(test_process_crosslinks)), | ||
create_suite('registry_updates', 'minimal', lambda: generate_from_tests(test_process_registry_updates)), | ||
create_suite('registry_updates', 'mainnet', lambda: generate_from_tests(test_process_registry_updates)), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eth-utils==1.6.0 | ||
../../test_libs/gen_helpers | ||
../../test_libs/config_helpers | ||
../../test_libs/pyspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Sanity tests | ||
|
||
Sanity tests cover regular state-transitions in a common block-list format, to ensure the basics work. | ||
|
||
Information on the format of the tests can be found in the [sanity test formats documentation](../../specs/test_formats/sanity/README.md). | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Callable, Iterable | ||
|
||
from eth2spec.test.sanity import test_blocks, test_slots | ||
|
||
from gen_base import gen_runner, gen_suite, gen_typing | ||
from gen_from_tests.gen import generate_from_tests | ||
from preset_loader import loader | ||
from eth2spec.phase0 import spec | ||
|
||
|
||
def create_suite(handler_name: str, config_name: str, get_cases: Callable[[], Iterable[gen_typing.TestCase]]) \ | ||
-> Callable[[str], gen_typing.TestSuiteOutput]: | ||
def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput: | ||
presets = loader.load_presets(configs_path, config_name) | ||
spec.apply_constants_preset(presets) | ||
|
||
return ("%sanity_s_%s" % (handler_name, config_name), handler_name, gen_suite.render_suite( | ||
title="sanity testing", | ||
summary="Sanity test suite, %s type, generated from pytests" % handler_name, | ||
forks_timeline="testing", | ||
forks=["phase0"], | ||
config=config_name, | ||
runner="sanity", | ||
handler=handler_name, | ||
test_cases=get_cases())) | ||
return suite_definition | ||
|
||
|
||
if __name__ == "__main__": | ||
gen_runner.run_generator("sanity", [ | ||
create_suite('blocks', 'minimal', lambda: generate_from_tests(test_blocks)), | ||
create_suite('blocks', 'mainnet', lambda: generate_from_tests(test_blocks)), | ||
create_suite('slots', 'minimal', lambda: generate_from_tests(test_slots)), | ||
create_suite('slots', 'mainnet', lambda: generate_from_tests(test_slots)), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eth-utils==1.6.0 | ||
../../test_libs/gen_helpers | ||
../../test_libs/config_helpers | ||
../../test_libs/pyspec |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from inspect import getmembers, isfunction | ||
|
||
def generate_from_tests(src, bls_active=True): | ||
""" | ||
Generate a list of test cases by running tests from the given src in generator-mode. | ||
:param src: to retrieve tests from (discovered using inspect.getmembers) | ||
:param bls_active: optional, to override BLS switch preference. Defaults to True. | ||
:return: the list of test cases. | ||
""" | ||
fn_names = [ | ||
name for (name, _) in getmembers(src, isfunction) | ||
if name.startswith('test_') | ||
] | ||
out = [] | ||
print("generating test vectors from tests source: %s" % src.__name__) | ||
for name in fn_names: | ||
tfn = getattr(src, name) | ||
try: | ||
test_case = tfn(generator_mode=True, bls_active=bls_active) | ||
# If no test case data is returned, the test is ignored. | ||
if test_case is not None: | ||
out.append(test_case) | ||
except AssertionError: | ||
print("ERROR: failed to generate vector from test: %s (src: %s)" % (name, src.__name__)) | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.