forked from ethereum/consensus-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
367 lines (333 loc) · 13.5 KB
/
Makefile
File metadata and controls
367 lines (333 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
all: help
# A list of executable specifications.
# These must pass a strict linter.
ALL_EXECUTABLE_SPEC_NAMES = \
phase0 \
altair \
bellatrix \
capella \
deneb \
electra \
fulu \
gloas \
eip6800 \
eip7441 \
eip7805 \
eip7928
# A list of fake targets.
.PHONY: \
_sync \
clean \
coverage \
help \
lint \
reftests \
serve_docs \
test
###############################################################################
# Help
###############################################################################
BOLD = $(shell tput bold)
NORM = $(shell tput sgr0)
# Print help.
help:
ifeq ($(verbose),true)
@$(MAKE) -s help-verbose
else
@$(MAKE) -s help-nonverbose
endif
# Print basic help output.
help-nonverbose:
@echo "make $(BOLD)clean$(NORM) -- delete all untracked files"
@echo "make $(BOLD)comptests$(NORM) -- generate compliance tests"
@echo "make $(BOLD)coverage$(NORM) -- run pyspec tests with coverage"
@echo "make $(BOLD)lint$(NORM) -- run the linters"
@echo "make $(BOLD)reftests$(NORM) -- generate reference tests"
@echo "make $(BOLD)serve_docs$(NORM) -- start a local docs web server"
@echo "make $(BOLD)test$(NORM) -- run pyspec tests"
@echo ""
@echo "Run 'make $(BOLD)help verbose=true$(NORM)' to print detailed usage/examples."
@echo ""
# Print verbose help output.
help-verbose:
@echo ""
@echo "$(BOLD)TESTING$(NORM)"
@echo "$(BOLD)--------------------------------------------------------------------------------$(NORM)"
@echo ""
@echo "$(BOLD)make test$(NORM)"
@echo ""
@echo " Runs pyspec tests with various configuration options. Tests run in parallel"
@echo " by default using pytest with the minimal preset and fastest BLS library."
@echo ""
@echo " Parameters:"
@echo " k=<test> Run specific test by name"
@echo " fork=<fork> Test specific fork (phase0, altair, bellatrix, capella, etc.)"
@echo " preset=<preset> Use specific preset (mainnet or minimal; default: minimal)"
@echo " bls=<type> BLS library type (py_ecc, milagro, arkworks, fastest; default: fastest)"
@echo " component=<value> Test component: (all, pyspec, fw; default: all)"
@echo ""
@echo " Examples:"
@echo " make test"
@echo " make test k=test_verify_kzg_proof"
@echo " make test fork=deneb"
@echo " make test preset=mainnet"
@echo " make test preset=mainnet fork=deneb k=test_verify_kzg_proof"
@echo " make test bls=arkworks"
@echo " make test component=fw"
@echo ""
@echo "$(BOLD)make coverage$(NORM)"
@echo ""
@echo " Runs tests with code coverage tracking and generates an HTML report."
@echo " Automatically opens the coverage report in your browser after completion."
@echo ""
@echo " Parameters:"
@echo " k=<test> Run specific test by name"
@echo " fork=<fork> Test specific fork"
@echo ""
@echo " Examples:"
@echo " make coverage"
@echo " make coverage k=test_process_attestation"
@echo " make coverage fork=electra"
@echo ""
@echo "$(BOLD)CODE QUALITY$(NORM)"
@echo "$(BOLD)--------------------------------------------------------------------------------$(NORM)"
@echo ""
@echo "$(BOLD)make lint$(NORM)"
@echo ""
@echo " Runs all linters and formatters to check code quality:"
@echo " - mdformat: Formats markdown files"
@echo " - codespell: Checks for spelling mistakes"
@echo " - ruff: Python linter and formatter"
@echo " - mypy: Static type checker for Python"
@echo ""
@echo " Example: make lint"
@echo ""
@echo "$(BOLD)TEST GENERATION$(NORM)"
@echo "$(BOLD)--------------------------------------------------------------------------------$(NORM)"
@echo ""
@echo "$(BOLD)make reftests$(NORM)"
@echo ""
@echo " Generates reference test vectors for consensus spec tests. These tests are"
@echo " used by client implementations to verify correctness. This command will write"
@echo " reference tests to the ../consensus-spec-tests/ directory."
@echo ""
@echo " Parameters:"
@echo " runner=<runner> Generate tests for specific runner (bls, operations, etc.)"
@echo " k=<test> Generate specific test cases (comma-separated)"
@echo " fork=<fork> Generate for specific fork (comma-separated)"
@echo " preset=<preset> Generate for specific preset (comma-separated)"
@echo " threads=N Number of threads to use (default: auto)"
@echo " verbose=true Enable verbose output"
@echo ""
@echo " Examples:"
@echo " make reftests"
@echo " make reftests runner=bls"
@echo " make reftests runner=operations k=invalid_committee_index"
@echo " make reftests runner=operations fork=fulu"
@echo " make reftests runner=operations preset=mainnet"
@echo " make reftests runner=operations k=invalid_committee_index,invalid_too_many_committee_bits"
@echo " make reftests runner=operations preset=mainnet fork=fulu k=invalid_committee_index"
@echo " make reftests runner=bls threads=1 verbose=true"
@echo ""
@echo " Tip:"
@echo " Use the following command to list available runners:"
@echo " ls -1 tests/generators/runners | grep -v '/$$' | sed 's/\.py$$//'"
@echo ""
@echo "$(BOLD)make comptests$(NORM)"
@echo ""
@echo " Generates compliance tests for fork choice. These tests verify that"
@echo " implementations correctly handle fork choice scenarios."
@echo ""
@echo " Parameters:"
@echo " fc_gen_config=<config> Configuration size (tiny, small, standard; default: tiny)"
@echo " fork=<fork> Generate for specific fork (comma-separated)"
@echo " preset=<preset> Generate for specific preset (comma-separated)"
@echo " threads=N Number of threads to use"
@echo " seed=N Override test seeds (fuzzing mode)"
@echo ""
@echo " Examples:"
@echo " make comptests"
@echo " make comptests fc_gen_config=standard"
@echo " make comptests fc_gen_config=standard fork=deneb preset=mainnet threads=8"
@echo ""
@echo "$(BOLD)DOCUMENTATION$(NORM)"
@echo "$(BOLD)--------------------------------------------------------------------------------$(NORM)"
@echo ""
@echo "$(BOLD)make serve_docs$(NORM)"
@echo ""
@echo " Builds and serves the documentation locally using MkDocs. Copies spec files,"
@echo " removes deprecated content, and starts a local web server for viewing docs."
@echo ""
@echo " Example: make serve_docs"
@echo " Then open: http://127.0.0.1:8000"
@echo ""
@echo "$(BOLD)MAINTENANCE$(NORM)"
@echo "$(BOLD)--------------------------------------------------------------------------------$(NORM)"
@echo ""
@echo "$(BOLD)make clean$(NORM)"
@echo ""
@echo " Removes all untracked files. This includes:"
@echo " - Virtual environment (.venv/)"
@echo " - Build artifacts"
@echo " - Cache files"
@echo ""
@echo " $(BOLD)WARNING:$(NORM) This will delete ALL untracked files. Make sure to commit or"
@echo " stash any important changes first."
@echo ""
@echo " Example: make clean"
@echo ""
###############################################################################
# Virtual Environment
###############################################################################
VENV = .venv
# Use editable installs for all non-generation targets, but use non-editable
# installs for generators. More details: ethereum/consensus-specs#4633.
UV_RUN = uv run
UV_RUN_NE = uv run --no-editable --reinstall-package=eth2spec
# Sync dependencies using uv.
_sync: MAYBE_VERBOSE := $(if $(filter true,$(verbose)),--verbose)
_sync: pyproject.toml
@command -v uv >/dev/null 2>&1 || { \
echo "Error: uv is required but not installed."; \
echo "Install with: curl -LsSf https://astral.sh/uv/install.sh | sh"; \
exit 1; \
}
@uv sync --all-extras $(MAYBE_VERBOSE)
###############################################################################
# Specification
###############################################################################
TEST_LIBS_DIR = $(CURDIR)/tests/core
PYSPEC_DIR = $(TEST_LIBS_DIR)/pyspec
# Create the pyspec for all phases.
_pyspec: MAYBE_VERBOSE := $(if $(filter true,$(verbose)),--verbose)
_pyspec: _sync
@$(UV_RUN) python -m pysetup.generate_specs --all-forks $(MAYBE_VERBOSE)
###############################################################################
# Testing
###############################################################################
TEST_REPORT_DIR = $(PYSPEC_DIR)/test-reports
# Run pyspec tests.
test: MAYBE_TEST := $(if $(k),-k=$(k))
# Disable parallelism when running a specific test.
# Parallelism makes debugging difficult (print doesn't work).
test: MAYBE_PARALLEL := $(if $(k),,-n auto)
test: MAYBE_FORK := $(if $(fork),--fork=$(fork))
test: PRESET := $(if $(filter fw,$(component)),,--preset=$(if $(preset),$(preset),minimal))
test: BLS := $(if $(filter fw,$(component)),,--bls-type=$(if $(bls),$(bls),fastest))
test: MAYBE_ETH2SPEC := $(if $(filter fw,$(component)),,$(PYSPEC_DIR)/eth2spec)
test: MAYBE_INFRA := $(if $(filter pyspec,$(component)),,$(CURDIR)/tests/infra)
test: _pyspec
@mkdir -p $(TEST_REPORT_DIR)
@$(UV_RUN) pytest \
$(MAYBE_PARALLEL) \
--capture=no \
$(MAYBE_TEST) \
$(MAYBE_FORK) \
$(PRESET) \
$(BLS) \
--junitxml=$(TEST_REPORT_DIR)/test_results.xml \
--html=$(TEST_REPORT_DIR)/test_results.html \
--self-contained-html \
$(MAYBE_INFRA) \
$(MAYBE_ETH2SPEC)
###############################################################################
# Coverage
###############################################################################
TEST_PRESET_TYPE ?= minimal
COV_HTML_OUT=$(PYSPEC_DIR)/.htmlcov
COV_INDEX_FILE=$(COV_HTML_OUT)/index.html
COVERAGE_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), --cov=eth2spec.$S.$(TEST_PRESET_TYPE))
# Run pytest with coverage tracking
_test_with_coverage: MAYBE_TEST := $(if $(k),-k=$(k))
_test_with_coverage: MAYBE_FORK := $(if $(fork),--fork=$(fork))
_test_with_coverage: _pyspec
@$(UV_RUN) pytest \
-n auto \
$(MAYBE_TEST) \
$(MAYBE_FORK) \
--disable-bls \
$(COVERAGE_SCOPE) \
--cov-report="html:$(COV_HTML_OUT)" \
--cov-branch \
$(PYSPEC_DIR)/eth2spec
# Run tests with coverage then open the coverage report.
# See `make test` for a list of options.
coverage: _test_with_coverage
@echo "Opening result: $(COV_INDEX_FILE)"
@((open "$(COV_INDEX_FILE)" || xdg-open "$(COV_INDEX_FILE)") &> /dev/null) &
###############################################################################
# Documentation
###############################################################################
DOCS_DIR = ./docs
FORK_CHOICE_DIR = ./fork_choice
SPEC_DIR = ./specs
SSZ_DIR = ./ssz
SYNC_DIR = ./sync
# Copy files to the docs directory.
_copy_docs:
@cp -r $(SPEC_DIR) $(DOCS_DIR)
@rm -rf $(DOCS_DIR)/specs/_deprecated
@cp -r $(SYNC_DIR) $(DOCS_DIR)
@cp -r $(SSZ_DIR) $(DOCS_DIR)
@cp -r $(FORK_CHOICE_DIR) $(DOCS_DIR)
@cp $(CURDIR)/README.md $(DOCS_DIR)/README.md
# Start a local documentation server.
serve_docs: _pyspec _copy_docs
@$(UV_RUN) mkdocs build
@$(UV_RUN) mkdocs serve
###############################################################################
# Checks
###############################################################################
MARKDOWN_FILES := $(shell find $(CURDIR) -name '*.md')
MYPY_PACKAGE_BASE := $(subst /,.,$(PYSPEC_DIR:$(CURDIR)/%=%))
MYPY_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), -p $(MYPY_PACKAGE_BASE).eth2spec.$S)
# Check for mistakes.
lint: _pyspec
@uv --quiet lock --check
@$(UV_RUN) mdformat --number --wrap=80 $(MARKDOWN_FILES)
@$(UV_RUN) codespell
@$(UV_RUN) ruff check --fix --quiet $(CURDIR)/tests $(CURDIR)/pysetup $(CURDIR)/setup.py
@$(UV_RUN) ruff format --quiet $(CURDIR)/tests $(CURDIR)/pysetup $(CURDIR)/setup.py
@$(UV_RUN) mypy $(MYPY_SCOPE)
###############################################################################
# Generators
###############################################################################
COMMA:= ,
TEST_VECTOR_DIR = $(CURDIR)/../consensus-spec-tests/tests
COMP_TEST_VECTOR_DIR = $(CURDIR)/../compliance-spec-tests/tests
# Generate reference tests.
reftests: MAYBE_VERBOSE := $(if $(filter true,$(verbose)),--verbose)
reftests: MAYBE_THREADS := $(if $(threads),--threads=$(threads))
reftests: MAYBE_RUNNERS := $(if $(runner),--runners $(subst ${COMMA}, ,$(runner)))
reftests: MAYBE_TESTS := $(if $(k),--cases $(subst ${COMMA}, ,$(k)))
reftests: MAYBE_FORKS := $(if $(fork),--forks $(subst ${COMMA}, ,$(fork)))
reftests: MAYBE_PRESETS := $(if $(preset),--presets $(subst ${COMMA}, ,$(preset)))
reftests: _pyspec
@$(UV_RUN_NE) python -m tests.generators.main \
--output $(TEST_VECTOR_DIR) \
$(MAYBE_VERBOSE) \
$(MAYBE_THREADS) \
$(MAYBE_RUNNERS) \
$(MAYBE_TESTS) \
$(MAYBE_FORKS) \
$(MAYBE_PRESETS)
# Generate compliance tests (fork choice).
comptests: FC_GEN_CONFIG := $(if $(fc_gen_config),$(fc_gen_config),tiny)
comptests: MAYBE_THREADS := $(if $(threads),--threads=$(threads),--fc-gen-multi-processing)
comptests: MAYBE_FORKS := $(if $(fork),--forks $(subst ${COMMA}, ,$(fork)))
comptests: MAYBE_PRESETS := $(if $(preset),--presets $(subst ${COMMA}, ,$(preset)))
comptests: MAYBE_SEED := $(if $(seed),--fc-gen-seed $(seed))
comptests: _pyspec
@$(UV_RUN_NE) python -m tests.generators.compliance_runners.fork_choice.test_gen \
--output $(COMP_TEST_VECTOR_DIR) \
--fc-gen-config $(FC_GEN_CONFIG) \
$(MAYBE_THREADS) \
$(MAYBE_FORKS) \
$(MAYBE_PRESETS) \
$(MAYBE_SEED)
###############################################################################
# Cleaning
###############################################################################
# Delete all untracked files.
clean:
@git clean -fdx