2019-03-18 16:18:57 +00:00
|
|
|
SPEC_DIR = ./specs
|
2020-01-10 18:42:55 +00:00
|
|
|
SSZ_DIR = ./ssz
|
2019-03-18 16:18:57 +00:00
|
|
|
SCRIPT_DIR = ./scripts
|
2020-01-10 18:42:55 +00:00
|
|
|
TEST_LIBS_DIR = ./tests/core
|
2019-03-27 16:35:46 +00:00
|
|
|
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
2019-07-30 10:49:18 +00:00
|
|
|
TEST_VECTOR_DIR = ./eth2.0-spec-tests/tests
|
2020-01-10 18:42:55 +00:00
|
|
|
GENERATOR_DIR = ./tests/generators
|
2019-05-27 07:57:55 +00:00
|
|
|
DEPOSIT_CONTRACT_DIR = ./deposit_contract
|
2019-04-11 09:25:00 +00:00
|
|
|
CONFIGS_DIR = ./configs
|
2019-03-18 16:18:57 +00:00
|
|
|
|
2019-03-27 16:35:46 +00:00
|
|
|
# Collect a list of generator names
|
2019-07-30 10:49:18 +00:00
|
|
|
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/.)))
|
|
|
|
# Map this list of generator paths to "gen_{generator name}" entries
|
|
|
|
GENERATOR_TARGETS = $(patsubst $(GENERATOR_DIR)/%/, gen_%, $(GENERATORS))
|
2019-03-28 16:16:18 +00:00
|
|
|
GENERATOR_VENVS = $(patsubst $(GENERATOR_DIR)/%, $(GENERATOR_DIR)/%venv, $(GENERATORS))
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-07-30 10:49:18 +00:00
|
|
|
# To check generator matching:
|
|
|
|
#$(info $$GENERATOR_TARGETS is [${GENERATOR_TARGETS}])
|
|
|
|
|
2020-01-10 18:42:55 +00:00
|
|
|
PHASE0_SPEC_DIR = $(SPEC_DIR)/phase0
|
2019-04-03 03:18:17 +00:00
|
|
|
PY_SPEC_PHASE_0_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase0/spec.py
|
2020-01-10 18:42:55 +00:00
|
|
|
PY_SPEC_PHASE_0_DEPS = $(wildcard $(SPEC_DIR)/phase0/*.md)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2020-01-10 18:42:55 +00:00
|
|
|
PHASE1_SPEC_DIR = $(SPEC_DIR)/phase1
|
2019-05-08 22:41:44 +00:00
|
|
|
PY_SPEC_PHASE_1_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase1/spec.py
|
2020-01-10 18:42:55 +00:00
|
|
|
PY_SPEC_PHASE_1_DEPS = $(wildcard $(SPEC_DIR)/phase1/*.md)
|
2019-12-10 16:07:30 +00:00
|
|
|
|
|
|
|
PY_SPEC_ALL_DEPS = $(PY_SPEC_PHASE_0_DEPS) $(PY_SPEC_PHASE_1_DEPS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-05-08 23:42:59 +00:00
|
|
|
PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGETS) $(PY_SPEC_PHASE_1_TARGETS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2020-01-10 18:42:55 +00:00
|
|
|
MARKDOWN_FILES = $(PY_SPEC_ALL_DEPS) $(wildcard $(SPEC_DIR)/*.md) $(wildcard $(SSZ_DIR)/*.md) $(wildcard $(SPEC_DIR)/networking/*.md) $(wildcard $(SPEC_DIR)/validator/*.md)
|
2019-12-10 16:07:30 +00:00
|
|
|
|
2019-06-14 23:13:29 +00:00
|
|
|
COV_HTML_OUT=.htmlcov
|
|
|
|
COV_INDEX_FILE=$(PY_SPEC_DIR)/$(COV_HTML_OUT)/index.html
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-07-30 10:49:18 +00:00
|
|
|
.PHONY: clean partial_clean all test citest lint generate_tests pyspec phase0 phase1 install_test open_cov \
|
2019-12-10 16:07:30 +00:00
|
|
|
install_deposit_contract_test test_deposit_contract compile_deposit_contract check_toc
|
2019-03-27 16:35:46 +00:00
|
|
|
|
2019-07-30 10:49:18 +00:00
|
|
|
all: $(PY_SPEC_ALL_TARGETS)
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-06-30 15:53:21 +00:00
|
|
|
# deletes everything except the venvs
|
2019-06-30 08:58:04 +00:00
|
|
|
partial_clean:
|
2019-07-30 10:49:18 +00:00
|
|
|
rm -rf $(TEST_VECTOR_DIR)
|
2019-03-28 16:05:40 +00:00
|
|
|
rm -rf $(GENERATOR_VENVS)
|
2019-06-30 08:58:04 +00:00
|
|
|
rm -rf $(PY_SPEC_DIR)/.pytest_cache
|
2019-03-27 16:35:46 +00:00
|
|
|
rm -rf $(PY_SPEC_ALL_TARGETS)
|
2019-06-30 08:58:04 +00:00
|
|
|
rm -rf $(DEPOSIT_CONTRACT_DIR)/.pytest_cache
|
2019-06-14 23:13:29 +00: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 22:20:24 +00:00
|
|
|
|
2019-06-30 09:18:36 +00:00
|
|
|
clean: partial_clean
|
2019-06-30 08:58:04 +00:00
|
|
|
rm -rf $(PY_SPEC_DIR)/venv
|
|
|
|
rm -rf $(DEPOSIT_CONTRACT_DIR)/venv
|
|
|
|
|
2019-07-30 10:49:18 +00:00
|
|
|
# "make generate_tests" to run all generators
|
|
|
|
generate_tests: $(PY_SPEC_ALL_TARGETS) $(GENERATOR_TARGETS)
|
2019-04-20 01:33:15 +00:00
|
|
|
|
|
|
|
# installs the packages to run pyspec tests
|
|
|
|
install_test:
|
2019-04-24 17:59:13 +00:00
|
|
|
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt;
|
2019-03-18 22:20:24 +00:00
|
|
|
|
2019-03-28 16:16:18 +00:00
|
|
|
test: $(PY_SPEC_ALL_TARGETS)
|
2019-06-14 21:12:04 +00:00
|
|
|
cd $(PY_SPEC_DIR); . venv/bin/activate; export PYTHONPATH="./"; \
|
2019-06-21 20:18:28 +00:00
|
|
|
python -m pytest -n 4 --cov=eth2spec.phase0.spec --cov=eth2spec.phase1.spec --cov-report="html:$(COV_HTML_OUT)" --cov-branch eth2spec
|
2019-04-20 01:33:15 +00:00
|
|
|
|
|
|
|
citest: $(PY_SPEC_ALL_TARGETS)
|
2019-06-14 21:12:04 +00:00
|
|
|
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; \
|
2019-06-21 20:18:28 +00:00
|
|
|
python -m pytest -n 4 --junitxml=test-reports/eth2spec/test_results.xml eth2spec
|
2019-06-14 21:12:04 +00:00
|
|
|
|
|
|
|
open_cov:
|
|
|
|
((open "$(COV_INDEX_FILE)" || xdg-open "$(COV_INDEX_FILE)") &> /dev/null) &
|
2019-05-09 05:11:07 +00:00
|
|
|
|
2019-12-10 16:07:30 +00:00
|
|
|
check_toc: $(MARKDOWN_FILES:=.toc)
|
|
|
|
|
|
|
|
%.toc:
|
|
|
|
cp $* $*.tmp && \
|
|
|
|
doctoc $* && \
|
|
|
|
diff -q $* $*.tmp && \
|
|
|
|
rm $*.tmp
|
|
|
|
|
2019-12-16 11:55:18 +00:00
|
|
|
codespell:
|
2019-12-16 13:11:05 +00:00
|
|
|
codespell . --skip ./.git -I .codespell-whitelist
|
2019-12-16 11:55:18 +00:00
|
|
|
|
2019-05-16 08:34:07 +00:00
|
|
|
lint: $(PY_SPEC_ALL_TARGETS)
|
2019-05-09 05:11:07 +00:00
|
|
|
cd $(PY_SPEC_DIR); . venv/bin/activate; \
|
2019-06-22 04:11:58 +00:00
|
|
|
flake8 --ignore=E252,W504,W503 --max-line-length=120 ./eth2spec \
|
|
|
|
&& cd ./eth2spec && 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 05:11:07 +00:00
|
|
|
|
2019-06-08 03:00:28 +00:00
|
|
|
install_deposit_contract_test: $(PY_SPEC_ALL_TARGETS)
|
2019-06-08 02:19:11 +00:00
|
|
|
cd $(DEPOSIT_CONTRACT_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt
|
|
|
|
|
2019-05-30 05:26:36 +00:00
|
|
|
compile_deposit_contract:
|
2019-06-08 02:19:11 +00:00
|
|
|
cd $(DEPOSIT_CONTRACT_DIR); . venv/bin/activate; \
|
2020-01-07 09:20:17 +00:00
|
|
|
python tool/compile_deposit_contract.py contracts/validator_registration.vy;
|
2019-05-30 05:26:36 +00:00
|
|
|
|
2019-06-08 03:00:28 +00:00
|
|
|
test_deposit_contract:
|
2019-06-08 02:19:11 +00:00
|
|
|
cd $(DEPOSIT_CONTRACT_DIR); . venv/bin/activate; \
|
2019-05-27 10:48:40 +00:00
|
|
|
python -m pytest .
|
2019-05-27 07:57:55 +00:00
|
|
|
|
2019-03-27 16:35:46 +00:00
|
|
|
# "make pyspec" to create the pyspec for all phases.
|
2019-03-28 16:16:18 +00:00
|
|
|
pyspec: $(PY_SPEC_ALL_TARGETS)
|
2019-03-18 22:30:16 +00:00
|
|
|
|
2019-05-16 14:36:35 +00:00
|
|
|
$(PY_SPEC_PHASE_0_TARGETS): $(PY_SPEC_PHASE_0_DEPS)
|
2020-01-10 18:42:55 +00:00
|
|
|
python3 $(SCRIPT_DIR)/build_spec.py -p0 $(PHASE0_SPEC_DIR)/beacon-chain.md $(PHASE0_SPEC_DIR)/fork-choice.md $(PHASE0_SPEC_DIR)/validator.md $@
|
2019-03-27 16:35:46 +00:00
|
|
|
|
2019-05-08 22:41:44 +00:00
|
|
|
$(PY_SPEC_DIR)/eth2spec/phase1/spec.py: $(PY_SPEC_PHASE_1_DEPS)
|
2020-01-10 18:42:55 +00:00
|
|
|
python3 $(SCRIPT_DIR)/build_spec.py -p1 $(PHASE0_SPEC_DIR)/beacon-chain.md $(PHASE0_SPEC_DIR)/fork-choice.md $(SSZ_DIR)/merkle-proofs.md $(PHASE1_SPEC_DIR)/custody-game.md $(PHASE1_SPEC_DIR)/shard-data-chains.md $(PHASE1_SPEC_DIR)/beacon-chain-misc.md $@
|
2019-03-27 16:35:46 +00:00
|
|
|
|
2019-03-28 16:05:40 +00:00
|
|
|
CURRENT_DIR = ${CURDIR}
|
2019-03-27 16:35:46 +00:00
|
|
|
|
2019-07-30 10:49:18 +00:00
|
|
|
# Runs a generator, identified by param 1
|
|
|
|
define run_generator
|
2019-04-20 02:23:10 +00: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.
|
2019-07-30 20:17:44 +00:00
|
|
|
# `-l minimal general` can be added to the generator call to filter to smaller configs, when testing.
|
2019-04-20 02:23:10 +00:00
|
|
|
echo "generator $(1) started"; \
|
2019-07-30 10:49:18 +00:00
|
|
|
mkdir -p $(TEST_VECTOR_DIR); \
|
|
|
|
cd $(GENERATOR_DIR)/$(1); \
|
2019-04-22 16:56:21 +00:00
|
|
|
if ! test -d venv; then python3 -m venv venv; fi; \
|
2019-04-20 02:23:10 +00:00
|
|
|
. venv/bin/activate; \
|
|
|
|
pip3 install -r requirements.txt; \
|
2019-07-30 10:49:18 +00:00
|
|
|
python3 main.py -o $(CURRENT_DIR)/$(TEST_VECTOR_DIR) -c $(CURRENT_DIR)/$(CONFIGS_DIR); \
|
2019-04-20 02:23:10 +00:00
|
|
|
echo "generator $(1) finished"
|
2019-03-27 16:35:46 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary)
|
2019-07-30 10:49:18 +00:00
|
|
|
$(TEST_VECTOR_DIR):
|
|
|
|
$(info creating test output directory, for generators: ${GENERATOR_TARGETS})
|
2019-03-27 16:35:46 +00:00
|
|
|
mkdir -p $@
|
2019-07-30 10:49:18 +00:00
|
|
|
$(TEST_VECTOR_DIR)/:
|
|
|
|
$(info ignoring duplicate tests dir)
|
2019-03-27 16:35:46 +00:00
|
|
|
|
2019-07-30 10:49:18 +00:00
|
|
|
# For any generator, build it using the run_generator function.
|
2019-03-28 16:24:18 +00:00
|
|
|
# (creation of output dir is a dependency)
|
2019-07-30 10:49:18 +00:00
|
|
|
gen_%: $(PY_SPEC_ALL_TARGETS) $(TEST_VECTOR_DIR)
|
|
|
|
$(call run_generator,$*)
|