Skip to content

Commit

Permalink
Merge pull request #1052 from ethereum/spectest-deco
Browse files Browse the repository at this point in the history
Spectest decorator
  • Loading branch information
djrtwo committed May 12, 2019
2 parents 4e179fb + 680017f commit ca22c19
Show file tree
Hide file tree
Showing 31 changed files with 1,363 additions and 1,337 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install_test:
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt;

test: $(PY_SPEC_ALL_TARGETS)
cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest .
cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest eth2spec

citest: $(PY_SPEC_ALL_TARGETS)
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml .
Expand Down
180 changes: 0 additions & 180 deletions test_generators/operations/deposits.py

This file was deleted.

44 changes: 0 additions & 44 deletions test_generators/operations/genesis.py

This file was deleted.

7 changes: 0 additions & 7 deletions test_generators/operations/keys.py

This file was deleted.

28 changes: 25 additions & 3 deletions test_generators/operations/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
from eth2spec.test.block_processing import (
test_process_attestation,
test_process_attester_slashing,
test_process_block_header,
test_process_deposit,
test_process_proposer_slashing,
test_process_transfer,
test_process_voluntary_exit
)

from gen_base import gen_runner

from deposits import mini_deposits_suite, full_deposits_suite
from suite_creator import generate_from_tests, create_suite

if __name__ == "__main__":
gen_runner.run_generator("operations", [
mini_deposits_suite,
full_deposits_suite
create_suite('attestation', 'minimal', lambda: generate_from_tests(test_process_attestation)),
create_suite('attestation', 'mainnet', lambda: generate_from_tests(test_process_attestation)),
create_suite('attester_slashing', 'minimal', lambda: generate_from_tests(test_process_attester_slashing)),
create_suite('attester_slashing', 'mainnet', lambda: generate_from_tests(test_process_attester_slashing)),
create_suite('block_header', 'minimal', lambda: generate_from_tests(test_process_block_header)),
create_suite('block_header', 'mainnet', lambda: generate_from_tests(test_process_block_header)),
create_suite('deposit', 'minimal', lambda: generate_from_tests(test_process_deposit)),
create_suite('deposit', 'mainnet', lambda: generate_from_tests(test_process_deposit)),
create_suite('proposer_slashing', 'minimal', lambda: generate_from_tests(test_process_proposer_slashing)),
create_suite('proposer_slashing', 'mainnet', lambda: generate_from_tests(test_process_proposer_slashing)),
create_suite('transfer', 'minimal', lambda: generate_from_tests(test_process_transfer)),
create_suite('transfer', 'mainnet', lambda: generate_from_tests(test_process_transfer)),
create_suite('voluntary_exit', 'minimal', lambda: generate_from_tests(test_process_voluntary_exit)),
create_suite('voluntary_exit', 'mainnet', lambda: generate_from_tests(test_process_voluntary_exit)),
])
3 changes: 1 addition & 2 deletions test_generators/operations/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
eth-utils==1.4.1
../../test_libs/gen_helpers
../../test_libs/config_helpers
../../test_libs/pyspec
py_ecc
../../test_libs/pyspec
39 changes: 39 additions & 0 deletions test_generators/operations/suite_creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import Callable, Iterable
from inspect import getmembers, isfunction
from gen_base import gen_suite, gen_typing
from preset_loader import loader
from eth2spec.phase0 import spec


def generate_from_tests(pkg):
fn_names = [
name for (name, _) in getmembers(pkg, isfunction)
if name.startswith('test_')
]
out = []
print("generating test vectors from tests package: %s" % pkg.__name__)
for name in fn_names:
tfn = getattr(pkg, name)
try:
out.append(tfn(generator_mode=True))
except AssertionError:
print("ERROR: failed to generate vector from test: %s (pkg: %s)" % (name, pkg.__name__))
return out


def create_suite(operation_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" % (operation_name, config_name), operation_name, gen_suite.render_suite(
title="%s operation" % operation_name,
summary="Test suite for %s type operation processing" % operation_name,
forks_timeline="testing",
forks=["phase0"],
config=config_name,
runner="operations",
handler=config_name,
test_cases=get_cases()))
return suite_definition
3 changes: 2 additions & 1 deletion test_libs/pyspec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ The `-B` flag may be helpful to force-overwrite the `pyspec` output after you ma

Run the tests:
```
pytest --config=minimal
pytest --config=minimal eth2spec
```
Note the package-name, this is to locate the tests.


## Contributing
Expand Down
File renamed without changes.
Empty file.
Loading

0 comments on commit ca22c19

Please sign in to comment.