-
Notifications
You must be signed in to change notification settings - Fork 997
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 #851 from protolambda/proto-merge-test-gen
Combine specs and test-generators
- Loading branch information
Showing
79 changed files
with
1,874 additions
and
186 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# Python CircleCI 2.0 configuration file | ||
version: 2 | ||
version: 2.1 | ||
jobs: | ||
build: | ||
docker: | ||
|
@@ -8,34 +7,83 @@ jobs: | |
|
||
steps: | ||
- checkout | ||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "requirements.txt" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: | ||
name: install dependencies | ||
command: | | ||
python3 -m venv venv | ||
. venv/bin/activate | ||
pip install -r requirements.txt | ||
- run: | ||
name: build phase0 spec | ||
command: make build/phase0 | ||
name: Build pyspec | ||
command: make pyspec | ||
|
||
- save_cache: | ||
paths: | ||
- ./venv | ||
key: v1-dependencies-{{ checksum "requirements.txt" }} | ||
- run: | ||
name: Run py-tests | ||
command: make test | ||
|
||
- run: | ||
name: run tests | ||
command: | | ||
. venv/bin/activate | ||
pytest tests | ||
name: Generate YAML tests | ||
command: make gen_yaml_tests | ||
|
||
- store_artifacts: | ||
path: test-reports | ||
destination: test-reports | ||
# TODO in future PR (after #851): decide on CI triggering of yaml tests building, | ||
# and destination of output (new yaml tests LFS-configured repository) | ||
# | ||
# - store_artifacts: | ||
# path: test-reports | ||
# destination: test-reports | ||
# | ||
# - run: | ||
# name: Save YAML tests for deployment | ||
# command: | | ||
# mkdir /tmp/workspace | ||
# cp -r yaml_tests /tmp/workspace/ | ||
# git log -1 >> /tmp/workspace/latest_commit_message | ||
# - persist_to_workspace: | ||
# root: /tmp/workspace | ||
# paths: | ||
# - yaml_tests | ||
# - latest_commit_message | ||
# commit: | ||
# docker: | ||
# - image: circleci/python:3.6 | ||
# steps: | ||
# - attach_workspace: | ||
# at: /tmp/workspace | ||
# - add_ssh_keys: | ||
# fingerprints: | ||
# - "01:85:b6:36:96:a6:84:72:e4:9b:4e:38:ee:21:97:fa" | ||
# - run: | ||
# name: Checkout test repository | ||
# command: | | ||
# ssh-keyscan -H github.com >> ~/.ssh/known_hosts | ||
# git clone [email protected]:ethereum/eth2.0-tests.git | ||
# - run: | ||
# name: Commit and push generated YAML tests | ||
# command: | | ||
# cd eth2.0-tests | ||
# git config user.name 'eth2TestGenBot' | ||
# git config user.email '[email protected]' | ||
# for filename in /tmp/workspace/yaml_tests/*; do | ||
# rm -rf $(basename $filename) | ||
# cp -r $filename . | ||
# done | ||
# git add . | ||
# if git diff --cached --exit-code >& /dev/null; then | ||
# echo "No changes to commit" | ||
# else | ||
# echo -e "Update generated tests\n\nLatest commit message from eth2.0-specs:\n" > commit_message | ||
# cat /tmp/workspace/latest_commit_message >> commit_message | ||
# git commit -F commit_message | ||
# git push origin master | ||
# fi | ||
#workflows: | ||
# version: 2.1 | ||
# | ||
# build_and_commit: | ||
# jobs: | ||
# - build: | ||
# filters: | ||
# tags: | ||
# only: /.*/ | ||
# - commit: | ||
# requires: | ||
# - build | ||
# filters: | ||
# tags: | ||
# only: /.*/ | ||
# branches: | ||
# ignore: /.*/ |
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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
*.pyc | ||
/__pycache__ | ||
/venv | ||
venv | ||
.venvs | ||
.venv | ||
/.pytest_cache | ||
|
||
build/ | ||
output/ | ||
|
||
yaml_tests/ | ||
.pytest_cache | ||
|
||
# Dynamically built from Markdown spec | ||
test_libs/pyspec/eth2spec/phase0/spec.py |
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 |
---|---|---|
@@ -1,29 +1,74 @@ | ||
SPEC_DIR = ./specs | ||
SCRIPT_DIR = ./scripts | ||
BUILD_DIR = ./build | ||
UTILS_DIR = ./utils | ||
TEST_LIBS_DIR = ./test_libs | ||
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec | ||
PY_TEST_DIR = ./py_tests | ||
YAML_TEST_DIR = ./yaml_tests | ||
GENERATOR_DIR = ./test_generators | ||
CONFIGS_DIR = ./configs | ||
|
||
# Collect a list of generator names | ||
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/))) | ||
# Map this list of generator paths to a list of test output paths | ||
YAML_TEST_TARGETS = $(patsubst $(GENERATOR_DIR)/%, $(YAML_TEST_DIR)/%, $(GENERATORS)) | ||
GENERATOR_VENVS = $(patsubst $(GENERATOR_DIR)/%, $(GENERATOR_DIR)/%venv, $(GENERATORS)) | ||
|
||
.PHONY: clean all test | ||
PY_SPEC_PHASE_0_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase0/spec.py | ||
PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGETS) | ||
|
||
|
||
all: $(BUILD_DIR)/phase0 | ||
.PHONY: clean all test gen_yaml_tests pyspec phase0 | ||
|
||
all: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR) $(YAML_TEST_TARGETS) | ||
|
||
clean: | ||
rm -rf $(BUILD_DIR) | ||
rm -rf $(YAML_TEST_DIR) | ||
rm -rf $(GENERATOR_VENVS) | ||
rm -rf $(PY_TEST_DIR)/venv $(PY_TEST_DIR)/.pytest_cache | ||
rm -rf $(PY_SPEC_ALL_TARGETS) | ||
|
||
# "make gen_yaml_tests" to run generators | ||
gen_yaml_tests: $(YAML_TEST_DIR) $(YAML_TEST_TARGETS) | ||
|
||
# runs a limited set of tests against a minimal config | ||
# run pytest with `-m` option to full suite | ||
test: all | ||
pytest -m minimal_config tests/ | ||
test: $(PY_SPEC_ALL_TARGETS) | ||
cd $(PY_TEST_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt; pytest -m minimal_config . | ||
|
||
# "make pyspec" to create the pyspec for all phases. | ||
pyspec: $(PY_SPEC_ALL_TARGETS) | ||
|
||
$(BUILD_DIR)/phase0: $(SPEC_DIR)/core/0_beacon-chain.md $(SCRIPT_DIR)/phase0/*.py $(UTILS_DIR)/phase0/*.py | ||
# "make phase0" to create pyspec for phase0 | ||
phase0: $(PY_SPEC_PHASE_0_TARGETS) | ||
|
||
|
||
$(PY_SPEC_DIR)/eth2spec/phase0/spec.py: | ||
python3 $(SCRIPT_DIR)/phase0/build_spec.py $(SPEC_DIR)/core/0_beacon-chain.md $@ | ||
|
||
|
||
CURRENT_DIR = ${CURDIR} | ||
|
||
# The function that builds a set of suite files, by calling a generator for the given type (param 1) | ||
define build_yaml_tests | ||
$(info running generator $(1)) | ||
# Create the output | ||
mkdir -p $(YAML_TEST_DIR)$(1) | ||
|
||
# 1) Create a virtual environment | ||
# 2) Activate the venv, this is where dependencies are installed for the generator | ||
# 3) Install all the necessary requirements | ||
# 4) Run the generator. The generator is assumed to have an "main.py" file. | ||
# 5) We output to the tests dir (generator program should accept a "-o <filepath>" argument. | ||
cd $(GENERATOR_DIR)$(1); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt; python3 main.py -o $(CURRENT_DIR)/$(YAML_TEST_DIR)$(1) -c $(CURRENT_DIR)/$(CONFIGS_DIR) | ||
|
||
$(info generator $(1) finished) | ||
endef | ||
|
||
# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary) | ||
$(YAML_TEST_DIR): | ||
$(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS}) | ||
mkdir -p $@ | ||
python3 $(SCRIPT_DIR)/phase0/build_spec.py $(SPEC_DIR)/core/0_beacon-chain.md $@/spec.py | ||
mkdir -p $@/utils | ||
cp $(UTILS_DIR)/phase0/* $@/utils | ||
cp $(UTILS_DIR)/phase0/state_transition.py $@ | ||
touch $@/__init__.py $@/utils/__init__.py | ||
|
||
# For any target within the tests dir, build it using the build_yaml_tests function. | ||
# (creation of output dir is a dependency) | ||
$(YAML_TEST_DIR)%: $(YAML_TEST_DIR) | ||
$(call build_yaml_tests,$*) |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Testing fork timeline | ||
|
||
# Equal to GENESIS_EPOCH | ||
phase0: 536870912 | ||
|
||
# No other forks considered in testing yet (to be implemented) |
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,30 @@ | ||
# 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 | ||
|
||
### Automated | ||
|
||
Run `make test` from the root of the spec repository. | ||
|
||
### Manual | ||
|
||
From within the py_tests folder: | ||
|
||
Install dependencies: | ||
```bash | ||
python3 -m venv venv | ||
. venv/bin/activate | ||
pip3 install -r requirements.txt | ||
``` | ||
Note: make sure to run `make pyspec` from the root of the specs repository, to build the pyspec requirement. | ||
|
||
Run the tests: | ||
``` | ||
pytest -m minimal_config . | ||
``` |
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
...ck_processing/test_process_attestation.py → ...ck_processing/test_process_attestation.py
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
6 changes: 3 additions & 3 deletions
6
...cessing/test_process_attester_slashing.py → ...cessing/test_process_attester_slashing.py
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
Oops, something went wrong.