2019-03-18 10:18:57 -06:00
|
|
|
SPEC_DIR = ./specs
|
|
|
|
SCRIPT_DIR = ./scripts
|
2019-03-28 00:35:46 +08:00
|
|
|
TEST_LIBS_DIR = ./test_libs
|
|
|
|
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
2019-04-20 12:28:50 +10:00
|
|
|
YAML_TEST_DIR = ./eth2.0-spec-tests/tests
|
2019-03-28 00:35:46 +08:00
|
|
|
GENERATOR_DIR = ./test_generators
|
2019-05-27 15:57:55 +08:00
|
|
|
DEPOSIT_CONTRACT_DIR = ./deposit_contract
|
2019-04-11 19:25:00 +10:00
|
|
|
CONFIGS_DIR = ./configs
|
2019-03-18 10:18:57 -06:00
|
|
|
|
2019-03-28 00:35:46 +08:00
|
|
|
# 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))
|
2019-03-29 00:16:18 +08:00
|
|
|
GENERATOR_VENVS = $(patsubst $(GENERATOR_DIR)/%, $(GENERATOR_DIR)/%venv, $(GENERATORS))
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-04-03 14:18:17 +11:00
|
|
|
PY_SPEC_PHASE_0_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase0/spec.py
|
2019-05-08 23:30:08 +01:00
|
|
|
PY_SPEC_PHASE_0_DEPS = $(SPEC_DIR)/core/0_*.md
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-05-08 23:41:44 +01:00
|
|
|
PY_SPEC_PHASE_1_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase1/spec.py
|
2019-05-08 23:30:08 +01:00
|
|
|
PY_SPEC_PHASE_1_DEPS = $(SPEC_DIR)/core/1_*.md
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-05-09 00:42:59 +01:00
|
|
|
PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGETS) $(PY_SPEC_PHASE_1_TARGETS)
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-06-15 01:13:29 +02:00
|
|
|
COV_HTML_OUT=.htmlcov
|
|
|
|
COV_INDEX_FILE=$(PY_SPEC_DIR)/$(COV_HTML_OUT)/index.html
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-06-14 23:12:04 +02:00
|
|
|
.PHONY: clean all test citest lint gen_yaml_tests pyspec phase0 phase1 install_test open_cov \
|
|
|
|
install_deposit_contract_test test_deposit_contract compile_deposit_contract
|
2019-03-28 00:35:46 +08:00
|
|
|
|
2019-03-30 00:24:04 +08:00
|
|
|
all: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR) $(YAML_TEST_TARGETS)
|
2019-03-18 16:20:24 -06:00
|
|
|
|
|
|
|
clean:
|
2019-03-28 00:35:46 +08:00
|
|
|
rm -rf $(YAML_TEST_DIR)
|
2019-03-29 00:05:40 +08:00
|
|
|
rm -rf $(GENERATOR_VENVS)
|
2019-04-24 11:59:13 -06:00
|
|
|
rm -rf $(PY_SPEC_DIR)/venv $(PY_SPEC_DIR)/.pytest_cache
|
2019-03-28 00:35:46 +08:00
|
|
|
rm -rf $(PY_SPEC_ALL_TARGETS)
|
2019-06-07 22:19:11 -04:00
|
|
|
rm -rf $(DEPOSIT_CONTRACT_DIR)/venv $(DEPOSIT_CONTRACT_DIR)/.pytest_cache
|
2019-06-15 01:13:29 +02:00
|
|
|
rm -rf $(PY_SPEC_DIR)/$(COV_HTML_OUT)
|
|
|
|
rm -rf $(PY_SPEC_DIR)/.coverage
|
|
|
|
rm -rf $(PY_SPEC_DIR)/test-reports
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-03-29 00:05:40 +08:00
|
|
|
# "make gen_yaml_tests" to run generators
|
2019-04-22 10:56:21 -06:00
|
|
|
gen_yaml_tests: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_TARGETS)
|
2019-04-20 11:33:15 +10:00
|
|
|
|
|
|
|
# installs the packages to run pyspec tests
|
|
|
|
install_test:
|
2019-04-24 11:59:13 -06:00
|
|
|
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt;
|
2019-03-18 16:20:24 -06:00
|
|
|
|
2019-03-29 00:16:18 +08:00
|
|
|
test: $(PY_SPEC_ALL_TARGETS)
|
2019-06-14 23:12:04 +02:00
|
|
|
cd $(PY_SPEC_DIR); . venv/bin/activate; export PYTHONPATH="./"; \
|
2019-06-16 17:38:48 -06:00
|
|
|
python -m pytest --cov=eth2spec.phase0.spec --cov=eth2spec.phase1.spec --cov-report="html:$(COV_HTML_OUT)" --cov-branch eth2spec
|
2019-04-20 11:33:15 +10:00
|
|
|
|
|
|
|
citest: $(PY_SPEC_ALL_TARGETS)
|
2019-06-14 23:12:04 +02:00
|
|
|
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; \
|
|
|
|
python -m pytest --junitxml=test-reports/eth2spec/test_results.xml eth2spec
|
|
|
|
|
|
|
|
open_cov:
|
|
|
|
((open "$(COV_INDEX_FILE)" || xdg-open "$(COV_INDEX_FILE)") &> /dev/null) &
|
2019-05-09 13:11:07 +08:00
|
|
|
|
2019-05-16 16:34:07 +08:00
|
|
|
lint: $(PY_SPEC_ALL_TARGETS)
|
2019-05-09 13:11:07 +08:00
|
|
|
cd $(PY_SPEC_DIR); . venv/bin/activate; \
|
2019-06-11 00:40:25 -04:00
|
|
|
flake8 --ignore=E252,W504,W503 --max-line-length=120 ./eth2spec; \
|
|
|
|
cd ./eth2spec; \
|
2019-06-12 20:10:24 -04:00
|
|
|
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs -p phase0; \
|
|
|
|
mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs -p phase1
|
2019-05-09 13:11:07 +08:00
|
|
|
|
2019-06-07 23:00:28 -04:00
|
|
|
install_deposit_contract_test: $(PY_SPEC_ALL_TARGETS)
|
2019-06-07 22:19:11 -04:00
|
|
|
cd $(DEPOSIT_CONTRACT_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt
|
|
|
|
|
2019-05-30 13:26:36 +08:00
|
|
|
compile_deposit_contract:
|
2019-06-07 22:19:11 -04:00
|
|
|
cd $(DEPOSIT_CONTRACT_DIR); . venv/bin/activate; \
|
2019-05-30 13:26:36 +08:00
|
|
|
python tool/compile_deposit_contract.py contracts/validator_registration.v.py;
|
|
|
|
|
2019-06-07 23:00:28 -04:00
|
|
|
test_deposit_contract:
|
2019-06-07 22:19:11 -04:00
|
|
|
cd $(DEPOSIT_CONTRACT_DIR); . venv/bin/activate; \
|
2019-05-27 18:48:40 +08:00
|
|
|
python -m pytest .
|
2019-05-27 15:57:55 +08:00
|
|
|
|
2019-03-28 00:35:46 +08:00
|
|
|
# "make pyspec" to create the pyspec for all phases.
|
2019-03-29 00:16:18 +08:00
|
|
|
pyspec: $(PY_SPEC_ALL_TARGETS)
|
2019-03-18 16:30:16 -06:00
|
|
|
|
2019-05-16 16:36:35 +02:00
|
|
|
$(PY_SPEC_PHASE_0_TARGETS): $(PY_SPEC_PHASE_0_DEPS)
|
2019-06-15 18:42:03 -04:00
|
|
|
python3 $(SCRIPT_DIR)/build_spec.py -p0 $(SPEC_DIR)/core/0_beacon-chain.md $(SPEC_DIR)/core/0_fork-choice.md $@
|
2019-03-28 00:35:46 +08:00
|
|
|
|
2019-05-08 23:41:44 +01:00
|
|
|
$(PY_SPEC_DIR)/eth2spec/phase1/spec.py: $(PY_SPEC_PHASE_1_DEPS)
|
2019-06-15 18:42:03 -04:00
|
|
|
python3 $(SCRIPT_DIR)/build_spec.py -p1 $(SPEC_DIR)/core/0_beacon-chain.md $(SPEC_DIR)/core/1_custody-game.md $(SPEC_DIR)/core/1_shard-data-chains.md $(SPEC_DIR)/core/0_fork-choice.md $@
|
2019-03-28 00:35:46 +08:00
|
|
|
|
2019-03-29 00:05:40 +08:00
|
|
|
CURRENT_DIR = ${CURDIR}
|
2019-03-28 00:35:46 +08:00
|
|
|
|
|
|
|
# The function that builds a set of suite files, by calling a generator for the given type (param 1)
|
|
|
|
define build_yaml_tests
|
2019-04-20 12:23:10 +10:00
|
|
|
# Started!
|
|
|
|
# Create output directory
|
|
|
|
# Navigate to the generator
|
|
|
|
# Create a virtual environment, if it does not exist already
|
|
|
|
# Activate the venv, this is where dependencies are installed for the generator
|
|
|
|
# Install all the necessary requirements
|
|
|
|
# Run the generator. The generator is assumed to have an "main.py" file.
|
|
|
|
# We output to the tests dir (generator program should accept a "-o <filepath>" argument.
|
|
|
|
echo "generator $(1) started"; \
|
|
|
|
mkdir -p $(YAML_TEST_DIR)$(1); \
|
|
|
|
cd $(GENERATOR_DIR)$(1); \
|
2019-04-22 10:56:21 -06:00
|
|
|
if ! test -d venv; then python3 -m venv venv; fi; \
|
2019-04-20 12:23:10 +10:00
|
|
|
. venv/bin/activate; \
|
|
|
|
pip3 install -r requirements.txt; \
|
|
|
|
python3 main.py -o $(CURRENT_DIR)/$(YAML_TEST_DIR)$(1) -c $(CURRENT_DIR)/$(CONFIGS_DIR); \
|
|
|
|
echo "generator $(1) finished"
|
2019-03-28 00:35:46 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary)
|
|
|
|
$(YAML_TEST_DIR):
|
2019-03-29 00:05:40 +08:00
|
|
|
$(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS})
|
2019-03-28 00:35:46 +08:00
|
|
|
mkdir -p $@
|
2019-04-20 12:23:10 +10:00
|
|
|
$(YAML_TEST_DIR)/:
|
|
|
|
$(info ignoring duplicate yaml tests dir)
|
2019-03-28 00:35:46 +08:00
|
|
|
|
|
|
|
# For any target within the tests dir, build it using the build_yaml_tests function.
|
2019-03-29 00:24:18 +08:00
|
|
|
# (creation of output dir is a dependency)
|
2019-04-20 11:33:15 +10:00
|
|
|
$(YAML_TEST_DIR)%: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR)
|
2019-03-28 00:35:46 +08:00
|
|
|
$(call build_yaml_tests,$*)
|