@@ -17,89 +17,80 @@ subspecifications that the Lean Ethereum protocol relies on.
1717
1818### Running Tests
1919``` bash
20- # Sync all dependencies and install packages
21- uv sync --all-extras
22-
23- # Run all tests
24- uv run pytest
25-
26- # Run tests with coverage
27- uv run pytest --cov=src/lean_spec --cov-report=html
20+ uv sync --all-extras # Install dependencies
21+ uv run pytest # Run unit tests
22+ uv run fill --fork=devnet --clean # Generate test vectors
2823```
2924
30- ### Code Quality Checks
25+ ### Code Quality
3126``` bash
32- # Format code
33- uv run ruff format src tests
34-
35- # Check linting
36- uv run ruff check src tests
37-
38- # Fix fixable linting errors
39- uv run ruff check --fix src tests
40-
41- # Type checking
42- uv run mypy src tests
43-
44- # Run all quality checks (lint, typecheck, spellcheck)
45- uv run tox -e all-checks
46-
47- # Run everything (all checks + tests + docs)
48- uv run tox
27+ uv run ruff format src tests # Format code
28+ uv run ruff check --fix src tests # Lint and fix
29+ uv run mypy src tests # Type check
30+ uv run tox -e all-checks # All checks
31+ uv run tox # Everything (checks + tests + docs)
4932```
5033
5134### Common Tasks
35+ - ** Main specs** : ` src/lean_spec/ `
36+ - ** Subspecs** : ` src/lean_spec/subspecs/{subspec}/ `
37+ - ** Unit tests** : ` tests/lean_spec/ ` (mirrors source structure)
38+ - ** Spec tests** : ` tests/spec_tests/devnet/ ` (generates test vectors)
5239
53- 1 . ** Adding to main specs ** : Located in ` src/lean_spec/ `
54- 2 . ** Adding to subspecs ** : Located in ` src/lean_spec/subspecs/ `
55- - Create a new subdirectory for each subspec (e.g., ` src/lean_spec/subspecs/poseidon2/ ` )
56- - Tests for subspecs should be in ` tests/subspecs/{subspec}/ ` , mirroring the source structure
40+ ## Code Style
41+ - Line length: 100 characters, type hints everywhere
42+ - Google docstring style (no docstrings for ` __init__ ` )
43+ - Test files/functions must start with ` test_ `
5744
58- ## Important Patterns
45+ ## Test Framework Structure
5946
60- ### Test Patterns
61- - Tests should be placed in ` tests/ ` and follow the same structure as the source code.
62- - Use ` pytest.fixture ` , in ` conftest.py ` or test files, for reusable test setup.
63- - Use ` pytest.mark.parametrize ` to parametrize tests with multiple inputs
64- - Use ` pytest.raises(...) ` with specific exceptions to test error cases
65- - Use ` @pytest.mark.slow ` for long-running tests
47+ ** Two types of tests:**
6648
67- ## Code Style
49+ 1 . ** Unit tests** (` tests/lean_spec/ ` ) - Standard pytest tests for implementation
50+ 2 . ** Spec tests** (` tests/spec_tests/ ` ) - Generate JSON test vectors via fillers
51+
52+ ** Test Filling Framework:**
53+ - Pytest plugin in ` packages/tests/src/lean_spec_tests/pytest_plugins/filler.py `
54+ - Write spec tests using ` state_transition_test ` or ` fork_choice_test ` fixtures
55+ - These fixtures are type aliases that create test vectors when called
56+ - Run ` uv run fill --fork=devnet --clean ` to generate fixtures in ` fixtures/ `
57+
58+ ** Example spec test:**
59+ ``` python
60+ def test_block (state_transition_test : StateTransitionTestFiller) -> None :
61+ state_transition_test(
62+ pre = genesis_state,
63+ blocks = [block],
64+ post = StateExpectation(slot = Slot(1 )) # Only check what matters
65+ )
66+ ```
6867
69- - Line length: 79 characters
70- - Use type hints everywhere
71- - Follow Google docstring style
72- - No docstrings needed for ` __init__ ` methods
73- - Imports are automatically sorted by ` isort ` and ` ruff `
74-
75- ## Testing Philosophy
76-
77- - Tests should be simple and clear
78- - Test file names must start with ` test_ `
79- - Test function names must start with ` test_ `
80- - Use descriptive test names that explain what's being tested
81-
82- ## Common Commands Reference
83-
84- | Task | Command |
85- | ----------------------------------------| -------------------------------------|
86- | Install dependencies | ` uv sync --all-extras ` |
87- | Run tests | ` uv run pytest ` |
88- | Format code | ` uv run ruff format src tests ` |
89- | Lint code | ` uv run ruff check src tests ` |
90- | Fix lint errors | ` uv run ruff check --fix src tests ` |
91- | Type check | ` uv run mypy src tests ` |
92- | Build docs | ` uv run mkdocs build ` |
93- | Serve docs | ` uv run mkdocs serve ` |
94- | Run all quality checks (no tests/docs) | ` uv run tox -e all-checks ` |
95- | Run everything (checks + tests + docs) | ` uv run tox ` |
68+ ** How it works:**
69+ 1 . Test function receives a fixture class (not instance) as parameter
70+ 2 . Calling it creates a ` FixtureWrapper ` that runs ` make_fixture() `
71+ 3 . ` make_fixture() ` executes the spec code (state transitions, fork choice steps)
72+ 4 . Validates output against expectations (` StateExpectation ` , ` StoreChecks ` )
73+ 5 . Serializes to JSON via Pydantic's ` model_dump(mode="json") `
74+ 6 . Writes fixtures at session end to ` fixtures/{test_type}/{fork}/... `
75+
76+ ** Serialization requirements:**
77+ - All spec types (State, Block, Uint64, etc.) must be Pydantic models
78+ - Custom types need ` @field_serializer ` or ` model_serializer ` for JSON output
79+ - SSZ types typically serialize to hex strings (e.g., ` "0x1234..." ` )
80+ - Fixture models inherit from ` BaseConsensusFixture ` (uses ` CamelModel ` for camelCase JSON)
81+ - Test the serialization: ` fixture.model_dump(mode="json") ` must produce valid JSON
82+
83+ ** Key fixture types:**
84+ - ` StateTransitionTest ` - Tests state transitions with blocks
85+ - ` ForkChoiceTest ` - Tests fork choice with steps (tick/block/attestation)
86+ - Selective validation via ` StateExpectation ` and ` StoreChecks ` (only validates fields you specify)
9687
9788## Important Notes
9889
99- 1 . This repository uses Python 3.12+ features
100- 2 . All models should use Pydantic for automatic validation.
101- 3 . Keep things simple, readable, and clear. These are meant to be clear specifications.
102- 4 . The repository is ` leanSpec ` not ` lean-spec ` .
90+ - Python 3.12+ required
91+ - Use Pydantic models for validation
92+ - Keep specs simple, readable, and clear
93+ - Repository is ` leanSpec ` not ` lean-spec `
10394
10495## SSZ Type Design Patterns
10596
0 commit comments