diff --git a/Makefile b/Makefile index 6586646fd..d00817daf 100644 --- a/Makefile +++ b/Makefile @@ -34,10 +34,10 @@ install_test: cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt; test: $(PY_SPEC_ALL_TARGETS) - cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest -m minimal_config . + cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest . 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 -m minimal_config . + cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml . # "make pyspec" to create the pyspec for all phases. pyspec: $(PY_SPEC_ALL_TARGETS) diff --git a/test_libs/pyspec/README.md b/test_libs/pyspec/README.md index b9bf86220..df1834210 100644 --- a/test_libs/pyspec/README.md +++ b/test_libs/pyspec/README.md @@ -38,7 +38,7 @@ Install dependencies: ```bash python3 -m venv venv . venv/bin/activate -pip3 install -r requirements.txt +pip3 install -r requirements-testing.txt ``` Note: make sure to run `make -B pyspec` from the root of the specs repository, to build the parts of the pyspec module derived from the markdown specs. @@ -46,7 +46,7 @@ The `-B` flag may be helpful to force-overwrite the `pyspec` output after you ma Run the tests: ``` -pytest -m minimal_config . +pytest --config=minimal ``` diff --git a/test_libs/pyspec/requirements-testing.txt b/test_libs/pyspec/requirements-testing.txt new file mode 100644 index 000000000..388a878a9 --- /dev/null +++ b/test_libs/pyspec/requirements-testing.txt @@ -0,0 +1,3 @@ +-r requirements.txt +pytest>=3.6,<3.7 +../config_helpers diff --git a/test_libs/pyspec/requirements.txt b/test_libs/pyspec/requirements.txt index 3296ef807..78d41708d 100644 --- a/test_libs/pyspec/requirements.txt +++ b/test_libs/pyspec/requirements.txt @@ -2,4 +2,3 @@ eth-utils>=1.3.0,<2 eth-typing>=2.1.0,<3.0.0 pycryptodome==3.7.3 py_ecc>=1.6.0 -pytest>=3.6,<3.7 diff --git a/test_libs/pyspec/tests/README.md b/test_libs/pyspec/tests/README.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/test_libs/pyspec/tests/conftest.py b/test_libs/pyspec/tests/conftest.py index bf9b1009b..f6c70d280 100644 --- a/test_libs/pyspec/tests/conftest.py +++ b/test_libs/pyspec/tests/conftest.py @@ -1,58 +1,24 @@ import pytest from eth2spec.phase0 import spec +from preset_loader import loader from .helpers import ( create_genesis_state, ) -DEFAULT_CONFIG = {} # no change - -MINIMAL_CONFIG = { - "SHARD_COUNT": 8, - "MIN_ATTESTATION_INCLUSION_DELAY": 2, - "TARGET_COMMITTEE_SIZE": 4, - "SLOTS_PER_EPOCH": 8, - "SLOTS_PER_HISTORICAL_ROOT": 64, - "LATEST_RANDAO_MIXES_LENGTH": 64, - "LATEST_ACTIVE_INDEX_ROOTS_LENGTH": 64, - "LATEST_SLASHED_EXIT_LENGTH": 64, -} - - -def overwrite_spec_config(config): - for field in config: - setattr(spec, field, config[field]) - if field == "LATEST_RANDAO_MIXES_LENGTH": - spec.BeaconState.fields['latest_randao_mixes'][1] = config[field] - elif field == "SHARD_COUNT": - spec.BeaconState.fields['current_crosslinks'][1] = config[field] - spec.BeaconState.fields['previous_crosslinks'][1] = config[field] - elif field == "SLOTS_PER_HISTORICAL_ROOT": - spec.BeaconState.fields['latest_block_roots'][1] = config[field] - spec.BeaconState.fields['latest_state_roots'][1] = config[field] - spec.HistoricalBatch.fields['block_roots'][1] = config[field] - spec.HistoricalBatch.fields['state_roots'][1] = config[field] - elif field == "LATEST_ACTIVE_INDEX_ROOTS_LENGTH": - spec.BeaconState.fields['latest_active_index_roots'][1] = config[field] - elif field == "LATEST_SLASHED_EXIT_LENGTH": - spec.BeaconState.fields['latest_slashed_balances'][1] = config[field] - - -@pytest.fixture( - params=[ - pytest.param(MINIMAL_CONFIG, marks=pytest.mark.minimal_config), - DEFAULT_CONFIG, - ] -) -def config(request): - return request.param +def pytest_addoption(parser): + parser.addoption( + "--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration" + ) @pytest.fixture(autouse=True) -def overwrite_config(config): - overwrite_spec_config(config) +def config(request): + config_name = request.config.getoption("--config") + presets = loader.load_presets('../../configs/', config_name) + spec.apply_constants_preset(presets) @pytest.fixture diff --git a/test_libs/pyspec/tests/helpers.py b/test_libs/pyspec/tests/helpers.py index d181dadfe..a728a6acc 100644 --- a/test_libs/pyspec/tests/helpers.py +++ b/test_libs/pyspec/tests/helpers.py @@ -118,6 +118,7 @@ def create_genesis_state(num_validators, deposit_data_leaves=None): def build_empty_block_for_next_slot(state): empty_block = BeaconBlock() empty_block.slot = state.slot + 1 + empty_block.body.eth1_data.deposit_count = state.deposit_index previous_block_header = deepcopy(state.latest_block_header) if previous_block_header.state_root == spec.ZERO_HASH: previous_block_header.state_root = state.hash_tree_root()