|
| 1 | +# CLAUDE.md - Ethereum Execution Spec Tests |
| 2 | + |
| 3 | +> **CRITICAL**: This repository aims to provide excellent tooling for generating JSON test vectors that test Ethereum execution layer clients. Correctness is absolute priority. The repo prioritizes a contributor-first mindset. |
| 4 | +
|
| 5 | +## 🎯 Core Purpose |
| 6 | + |
| 7 | +- `./tests/`: Python tests that **generate JSON test vectors (fixtures)** via `fill` command |
| 8 | +- `./src/pytest_plugins/filler/`: Implements `fill` command (test vector generation from Python source) |
| 9 | +- `./src/pytest_plugins/consume/`: Implements `consume` command (test vector execution) |
| 10 | +- `./src/pytest_plugins/execute/`: Implements `execute` command (live JSON-RPC testing from Python source) |
| 11 | +- `./src/ethereum_test_*`: Core framework libraries and data structures |
| 12 | + |
| 13 | +### Key Terminology (CRITICAL) |
| 14 | + |
| 15 | +**"Fixtures" has TWO meanings:** |
| 16 | + |
| 17 | +1. **Test Fixtures** (JSON files) - The test vectors this framework generates |
| 18 | +2. **Pytest Fixtures** - Standard pytest setup/teardown (`pre`, `state_test`, etc.) |
| 19 | + |
| 20 | +### Workflows |
| 21 | + |
| 22 | +```text |
| 23 | +Fill/Consume: Python Tests → fill → JSON Fixtures → consume → Client Testing |
| 24 | +Execute: Python Tests → execute → Live JSON-RPC Testing |
| 25 | +``` |
| 26 | + |
| 27 | +## 🚀 Essential Commands |
| 28 | + |
| 29 | +All commands use `uv run` prefix. |
| 30 | + |
| 31 | +### Setup |
| 32 | + |
| 33 | +```bash |
| 34 | +uv sync --all-extras |
| 35 | +uv run solc-select use 0.8.24 --always-install |
| 36 | +uvx pre-commit install |
| 37 | +``` |
| 38 | + |
| 39 | +### Core Workflow |
| 40 | + |
| 41 | +```bash |
| 42 | +# Create test |
| 43 | +uv run eest make test |
| 44 | + |
| 45 | +# Generate fixtures (PRIMARY WORKFLOW) |
| 46 | +uv run fill --fork=Prague path/to/test.py --clean -v -m "not slow" |
| 47 | + |
| 48 | +# Execute against client |
| 49 | +uv run consume direct --bin=evm fixtures/ |
| 50 | + |
| 51 | +# Framework testing |
| 52 | +uv run pytest -c pytest-framework.ini path/to/test.py::test_function |
| 53 | +``` |
| 54 | + |
| 55 | +### Quality Checks |
| 56 | + |
| 57 | +```bash |
| 58 | +# Check code style and errors |
| 59 | +uv run ruff check src tests .github/scripts |
| 60 | + |
| 61 | +# Format code |
| 62 | +uv run ruff format src tests .github/scripts |
| 63 | + |
| 64 | +# Fix auto-fixable issues |
| 65 | +uv run ruff check --fix src tests .github/scripts |
| 66 | + |
| 67 | +# Type checking |
| 68 | +uv run mypy src tests .github/scripts |
| 69 | + |
| 70 | +# Framework unit tests |
| 71 | +uv run pytest -c pytest-framework.ini -n auto -m "not run_in_serial" |
| 72 | +uv run pytest -c pytest-framework.ini -m run_in_serial |
| 73 | + |
| 74 | +# Run specific checks (fast checks) |
| 75 | +uvx --with=tox-uv tox -e lint,typecheck,spellcheck |
| 76 | + |
| 77 | +# Local docs check (fast mode: these warnings can be ignored "WARNING - Doc file 'writing_tests/..."): |
| 78 | +export FAST_DOCS=true && export GEN_TEST_DOC_VERSION="tox" && uv run mkdocs build |
| 79 | +``` |
| 80 | + |
| 81 | +## 🎯 Core Framework Rules |
| 82 | + |
| 83 | +### NEVER Use Hardcoded Addresses |
| 84 | + |
| 85 | +```python |
| 86 | +def test_example(pre: Alloc, state_test: StateTestFiller): |
| 87 | + # ✅ Dynamic allocation |
| 88 | + sender = pre.fund_eoa() |
| 89 | + contract = pre.deploy_contract(code=Op.SSTORE(1, 1)) |
| 90 | + |
| 91 | + tx = Transaction(sender=sender, to=contract, gas_limit=5_000_000) |
| 92 | + state_test(pre=pre, tx=tx, post={contract: Account(storage={1: 1})}) |
| 93 | +``` |
| 94 | + |
| 95 | +### Key Methods |
| 96 | + |
| 97 | +- `pre.deploy_contract(code, **kwargs) -> Address` |
| 98 | +- `pre.fund_eoa(amount=None, **kwargs) -> EOA` |
| 99 | +- `pre.fund_address(address, amount)` |
| 100 | + |
| 101 | +### Gas Calculation Pattern |
| 102 | + |
| 103 | +```python |
| 104 | +intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator() |
| 105 | +tx_gas_limit = intrinsic_gas_calculator( |
| 106 | + calldata=tx_data, |
| 107 | + contract_creation=False, |
| 108 | + access_list=access_lists, |
| 109 | +) + 100_000 |
| 110 | +``` |
| 111 | + |
| 112 | +## 📁 Key Directories |
| 113 | + |
| 114 | +```text |
| 115 | +src/ |
| 116 | +├── ethereum_test_tools/ # Core framework |
| 117 | +├── ethereum_test_types/ # Type definitions |
| 118 | +├── ethereum_test_fixtures/ # Pydantic models for test fixtures |
| 119 | +├── pytest_plugins/ # Plugin system |
| 120 | +tests/ # Test cases by fork |
| 121 | +fixtures/ # Generated test vectors (default output directory) |
| 122 | +``` |
| 123 | + |
| 124 | +## ⚠️ Critical Anti-Patterns |
| 125 | + |
| 126 | +- ❌ Hardcoded addresses (use `pre` fixture) |
| 127 | +- ❌ `TestAddress` in new tests (use `pre.fund_eoa()`) |
| 128 | +- ❌ Missing `sender` parameter in transactions |
| 129 | +- ❌ Missing `@pytest.mark.valid_from("Fork")` markers |
| 130 | +- ❌ Manual nonce management |
| 131 | + |
| 132 | +## 🔧 Common Patterns |
| 133 | + |
| 134 | +### Fork Compatibility |
| 135 | + |
| 136 | +```python |
| 137 | +@pytest.mark.valid_from("Cancun") |
| 138 | +def test_example(pre: Alloc, state_test: StateTestFiller): |
| 139 | + if fork >= Fork.Cancun: |
| 140 | + # Cancun-specific logic |
| 141 | + else: |
| 142 | + # Pre-Cancun logic |
| 143 | +``` |
| 144 | + |
| 145 | +### Parameterized Tests |
| 146 | + |
| 147 | +```python |
| 148 | +@pytest.mark.parametrize("value", [0, 1, 2**256-1]) |
| 149 | +def test_with_params(value: int, pre: Alloc, state_test: StateTestFiller): |
| 150 | +``` |
| 151 | + |
| 152 | +## 🐛 Debugging Test Filling |
| 153 | + |
| 154 | +### Generate EVM Traces |
| 155 | + |
| 156 | +```bash |
| 157 | +uv run fill --fork=Prague --evm-dump-dir=debug_output/ --traces path/to/test.py |
| 158 | +jq -r '.opName' debug_output/**/*.jsonl |
| 159 | +``` |
| 160 | + |
| 161 | +### Common Issues |
| 162 | + |
| 163 | +- **Fill failures**: Check gas limits (increase if needed, use `transaction_intrinsic_cost_calculator`) |
| 164 | +- **Address conflicts**: Always use `pre` fixture for dynamic allocation |
| 165 | +- **Test collection**: Functions must start with `test_` |
| 166 | +- **Import errors**: Check dependencies in `pyproject.toml`, run `uv sync --all-extras` |
| 167 | + |
| 168 | +## 📝 Code Standards |
| 169 | + |
| 170 | +- **Line length**: 100 characters |
| 171 | +- **Type annotations**: Required |
| 172 | +- **Import style**: Explicit imports only, no `import *`, no local imports. |
| 173 | +- **Path handling**: Use `pathlib` |
| 174 | +- **Code**: Use idiomatic python, prioritize readability. |
| 175 | +- **Docstrings**: Always include for methods and classes. For one-liners """Use one single-line docstring with quotes on same line.""" |
| 176 | + |
| 177 | +## Commit Format |
| 178 | + |
| 179 | +```text |
| 180 | +<type>(<scope>): <description> |
| 181 | +
|
| 182 | +# Types: feat, fix, docs, style, refactor, test, chore, new |
| 183 | +# Scopes: evm, forks, tools, pytest, tests, docs, ci, consume, fill, eest |
| 184 | +``` |
| 185 | + |
| 186 | +## 🔍 Tool Preferences |
| 187 | + |
| 188 | +- **Search**: `rg "pattern" --type python` (not grep) |
| 189 | +- **JSON**: `jq -r '.field' file.json` |
| 190 | +- **GitHub**: `gh` CLI for all operations |
| 191 | + |
| 192 | +## 🎯 Development Workflow |
| 193 | + |
| 194 | +1. `uv run eest make test` - Create test |
| 195 | +2. Implement tests using `pre` fixture patterns |
| 196 | +3. `uv run fill --fork=Fork test.py --clean -v tests/path/to/module` - Generate fixtures |
| 197 | +4. `uv run ruff check --fix` - Fix linting |
| 198 | +5. Commit with semantic format |
| 199 | + |
| 200 | +**Critical**: Always run linting and type checking. Use `--clean` when filling. Never use hardcoded addresses. |
0 commit comments