From ec4d41e15da01e4da6626d41e11fe034a8f87476 Mon Sep 17 00:00:00 2001 From: protolambda Date: Thu, 28 Mar 2019 02:30:47 +0800 Subject: [PATCH] fix config, work on py_tests --- .gitignore | 1 + Makefile | 2 +- py_tests/README.md | 23 +++++++++++++++++++ .../test_process_attestation.py | 9 ++++---- .../test_process_block_header.py | 4 ++-- .../block_processing/test_process_deposit.py | 6 ++--- .../test_process_proposer_slashing.py | 6 ++--- .../block_processing/test_voluntary_exit.py | 6 ++--- py_tests/phase0/conftest.py | 4 ++-- py_tests/phase0/helpers.py | 8 +++---- py_tests/phase0/test_sanity.py | 12 +++++----- py_tests/requirements.txt | 1 + test_generators/README.md | 2 +- 13 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 py_tests/README.md diff --git a/.gitignore b/.gitignore index 816ecfa26..16576a634 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ build/ output/ yaml_tests/ +.pytest_cache diff --git a/Makefile b/Makefile index 3812a8255..84dbd0c26 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ define build_yaml_tests # Activate the venv, this is where dependencies are installed for the generator . $(GENERATOR_VENVS_DIR)$(1)bin/activate # Install all the necessary requirements - pip3 install -r $(GENERATOR_DIR)$(1)requirements.txt --user + pip3 install -r $(GENERATOR_DIR)$(1)requirements.txt # Run the generator. The generator is assumed to have an "main.py" file. # We output to the tests dir (generator program should accept a "-p " argument. diff --git a/py_tests/README.md b/py_tests/README.md new file mode 100644 index 000000000..659e737f1 --- /dev/null +++ b/py_tests/README.md @@ -0,0 +1,23 @@ +# ETH 2.0 py-tests + +These tests are not intended for client-consumption. +These tests are sanity tests, to verify if the spec itself is consistent. + +There are ideas to port these tests to the YAML test suite, + but we are still looking for inputs on how this should work. + +## How to run tests + +From within the py_tests folder: + +Install dependencies: +```bash +python3 -m venv venv +. py_tests/venv/bin/activate +pip3 install -r requirements.txt +``` + +Run the tests: +``` +pytest -m minimal_config . +``` diff --git a/py_tests/phase0/block_processing/test_process_attestation.py b/py_tests/phase0/block_processing/test_process_attestation.py index 08cab11ff..f76ca77d8 100644 --- a/py_tests/phase0/block_processing/test_process_attestation.py +++ b/py_tests/phase0/block_processing/test_process_attestation.py @@ -1,18 +1,17 @@ from copy import deepcopy import pytest -import build.phase0.spec as spec +import eth2.phase0.spec as spec -from build.phase0.state_transition import ( +from eth2.phase0.state_transition import ( state_transition, ) -from build.phase0.spec import ( - ZERO_HASH, +from eth2.phase0.spec import ( get_current_epoch, process_attestation, slot_to_epoch, ) -from tests.phase0.helpers import ( +from ..helpers import ( build_empty_block_for_next_slot, get_valid_attestation, ) diff --git a/py_tests/phase0/block_processing/test_process_block_header.py b/py_tests/phase0/block_processing/test_process_block_header.py index 4981b656c..ef902bb72 100644 --- a/py_tests/phase0/block_processing/test_process_block_header.py +++ b/py_tests/phase0/block_processing/test_process_block_header.py @@ -2,13 +2,13 @@ from copy import deepcopy import pytest -from build.phase0.spec import ( +from eth2.phase0.spec import ( get_beacon_proposer_index, cache_state, advance_slot, process_block_header, ) -from tests.phase0.helpers import ( +from ..helpers import ( build_empty_block_for_next_slot, ) diff --git a/py_tests/phase0/block_processing/test_process_deposit.py b/py_tests/phase0/block_processing/test_process_deposit.py index 0726dddef..19467984e 100644 --- a/py_tests/phase0/block_processing/test_process_deposit.py +++ b/py_tests/phase0/block_processing/test_process_deposit.py @@ -1,14 +1,14 @@ from copy import deepcopy import pytest -import build.phase0.spec as spec +import eth2.phase0.spec as spec -from build.phase0.spec import ( +from eth2.phase0.spec import ( get_balance, ZERO_HASH, process_deposit, ) -from tests.phase0.helpers import ( +from ..helpers import ( build_deposit, privkeys, pubkeys, diff --git a/py_tests/phase0/block_processing/test_process_proposer_slashing.py b/py_tests/phase0/block_processing/test_process_proposer_slashing.py index 467d2164b..761624c25 100644 --- a/py_tests/phase0/block_processing/test_process_proposer_slashing.py +++ b/py_tests/phase0/block_processing/test_process_proposer_slashing.py @@ -1,13 +1,13 @@ from copy import deepcopy import pytest -import build.phase0.spec as spec -from build.phase0.spec import ( +import eth2.phase0.spec as spec +from eth2.phase0.spec import ( get_balance, get_current_epoch, process_proposer_slashing, ) -from tests.phase0.helpers import ( +from ..helpers import ( get_valid_proposer_slashing, ) diff --git a/py_tests/phase0/block_processing/test_voluntary_exit.py b/py_tests/phase0/block_processing/test_voluntary_exit.py index 6adc81464..45a8af1bb 100644 --- a/py_tests/phase0/block_processing/test_voluntary_exit.py +++ b/py_tests/phase0/block_processing/test_voluntary_exit.py @@ -1,14 +1,14 @@ from copy import deepcopy import pytest -import build.phase0.spec as spec +import eth2.phase0.spec as spec -from build.phase0.spec import ( +from eth2.phase0.spec import ( get_active_validator_indices, get_current_epoch, process_voluntary_exit, ) -from tests.phase0.helpers import ( +from ..helpers import ( build_voluntary_exit, pubkey_to_privkey, ) diff --git a/py_tests/phase0/conftest.py b/py_tests/phase0/conftest.py index 36a087941..0def66ad6 100644 --- a/py_tests/phase0/conftest.py +++ b/py_tests/phase0/conftest.py @@ -1,8 +1,8 @@ import pytest -from build.phase0 import spec +from eth2.phase0 import spec -from tests.phase0.helpers import ( +from .helpers import ( create_genesis_state, ) diff --git a/py_tests/phase0/helpers.py b/py_tests/phase0/helpers.py index d7f4ae6e8..3be231ee2 100644 --- a/py_tests/phase0/helpers.py +++ b/py_tests/phase0/helpers.py @@ -2,9 +2,9 @@ from copy import deepcopy from py_ecc import bls -import build.phase0.spec as spec -from build.phase0.utils.minimal_ssz import signed_root -from build.phase0.spec import ( +import eth2.phase0.spec as spec +from eth2.utils.minimal_ssz import signed_root +from eth2.phase0.spec import ( # constants EMPTY_SIGNATURE, ZERO_HASH, @@ -31,7 +31,7 @@ from build.phase0.spec import ( verify_merkle_branch, hash, ) -from build.phase0.utils.merkle_minimal import ( +from eth2.utils.merkle_minimal import ( calc_merkle_tree_from_leaves, get_merkle_proof, get_merkle_root, diff --git a/py_tests/phase0/test_sanity.py b/py_tests/phase0/test_sanity.py index 3b4497ca5..0af65ad51 100644 --- a/py_tests/phase0/test_sanity.py +++ b/py_tests/phase0/test_sanity.py @@ -3,10 +3,10 @@ from copy import deepcopy import pytest from py_ecc import bls -import build.phase0.spec as spec +import eth2.phase0.spec as spec -from build.phase0.utils.minimal_ssz import signed_root -from build.phase0.spec import ( +from eth2.utils.minimal_ssz import signed_root +from eth2.phase0.spec import ( # constants EMPTY_SIGNATURE, ZERO_HASH, @@ -27,15 +27,15 @@ from build.phase0.spec import ( verify_merkle_branch, hash, ) -from build.phase0.state_transition import ( +from eth2.phase0.state_transition import ( state_transition, ) -from build.phase0.utils.merkle_minimal import ( +from eth2.utils.merkle_minimal import ( calc_merkle_tree_from_leaves, get_merkle_proof, get_merkle_root, ) -from tests.phase0.helpers import ( +from .helpers import ( build_deposit_data, build_empty_block_for_next_slot, force_registry_change_at_next_epoch, diff --git a/py_tests/requirements.txt b/py_tests/requirements.txt index 9145e951e..d18b29127 100644 --- a/py_tests/requirements.txt +++ b/py_tests/requirements.txt @@ -4,3 +4,4 @@ oyaml==0.7 pycryptodome==3.7.3 py_ecc>=1.6.0 pytest>=3.6,<3.7 +../pyspec diff --git a/test_generators/README.md b/test_generators/README.md index 2d6160c03..61dc96063 100644 --- a/test_generators/README.md +++ b/test_generators/README.md @@ -62,7 +62,7 @@ eth-utils==1.4.1 Install all the necessary requirements (re-run when you add more): ```bash -pip3 install -r requirements.txt --user +pip3 install -r requirements.txt ``` And write your initial test generator, extending the base generator: