Skip to content

Commit fd8e8ef

Browse files
committed
fix: reconcile differences with main after rebase + cleanup impl
- Reconcile differences with ``main`` after rebase. - Clean up the implementation of the test fixtures + remove clunky builder for now.
1 parent 5209b20 commit fd8e8ef

File tree

19 files changed

+466
-363
lines changed

19 files changed

+466
-363
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ subspecifications that the Lean Ethereum protocol relies on.
1717

1818
### Running Tests
1919
```bash
20-
uv sync # Install dependencies
20+
uv sync --all-packages # Install dependencies
2121
uv run pytest # Run unit tests
2222
uv run fill --fork=devnet --clean # Generate test vectors
2323
# Note: execution layer support is planned for future, infrastructure is ready

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
## Quick Start
44

55
1. Fork and clone the repository
6-
2. Install dependencies: `uv sync`
6+
2. Install dependencies: `uv sync --all-packages`
77
3. Make your changes
88
4. Run checks: `uvx tox -e all-checks`
9-
5. Run tests: `uv run pytest`
9+
5. Run tests: `uvx pytest`
1010
6. Submit a pull request
1111

1212
## Pull Request Guidelines

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,16 @@ def test_withdrawal_amount_above_uint64_max():
177177

178178
| Task | Command |
179179
|-----------------------------------------------|------------------------------------|
180-
| Install and sync project and dev dependencies | `uv sync` |
181-
| Run tests | `uv run pytest` |
180+
| Install and sync project and dev dependencies | `uv sync --all-packages` |
181+
| Run tests | `uv run pytest ...` |
182182
| Format code | `uv run ruff format src tests` |
183183
| Lint code | `uv run ruff check src tests` |
184184
| Fix lint errors | `uv run ruff check --fix src tests` |
185185
| Type check | `uv run mypy src tests` |
186186
| Build docs | `uv run mkdocs build` |
187187
| Serve docs | `uv run mkdocs serve` |
188-
| Run all quality checks (no tests/docs) | `uvx tox -e all-checks` |
189188
| Run everything (checks + tests + docs) | `uvx tox` |
190-
| Run specific tox environment | `uvx tox -e lint` |
189+
| Run all quality checks (no tests/docs) | `uvx tox -e all-checks` |
191190

192191

193192
## Contributing

packages/testing/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ This package provides tools for generating consensus test fixtures, including:
99

1010
## Installation
1111

12-
This package is part of the lean-spec workspace and is automatically installed when you sync the parent project:
12+
This package is part of the lean-spec workspace and is automatically installed when you
13+
sync the parent project with `--all-packages`.
1314

1415
```bash
15-
cd ../..
16-
uv sync --all-extras
16+
# from `leanSpec/` (root of workspace)
17+
uv sync --all-packages
1718
```
1819

1920
## Usage
2021

2122
Generate test fixtures using the `fill` command:
2223

2324
```bash
25+
# from `leanSpec/` (root of workspace)
2426
uv run fill --clean --fork=devnet
2527
```
2628

packages/testing/src/consensus_testing/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
from framework.base_types import CamelModel
66

7-
from .builders import BlockBuilder
7+
from . import forks
8+
from .block_spec import BlockSpec
9+
from .genesis import generate_pre_state
810
from .test_fixtures import (
911
BaseConsensusFixture,
1012
ForkChoiceTest,
@@ -25,7 +27,9 @@
2527

2628
__all__ = [
2729
# Public API
28-
"BlockBuilder",
30+
"BlockSpec",
31+
"forks",
32+
"generate_pre_state",
2933
# Base types
3034
"CamelModel",
3135
# Fixture classes
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Lightweight block specification for test definitions."""
2+
3+
from pydantic import BaseModel
4+
5+
from lean_spec.subspecs.containers.block import BlockBody
6+
from lean_spec.subspecs.containers.slot import Slot
7+
from lean_spec.types import Bytes32, ValidatorIndex
8+
9+
10+
class BlockSpec(BaseModel):
11+
"""
12+
Block specification for test definitions.
13+
14+
Contains the same fields as Block, but all optional except slot.
15+
The framework fills in any missing fields automatically.
16+
17+
This matches the pattern from execution-specs where Block(...) is a spec
18+
that the framework builds into a full block.
19+
20+
Usage:
21+
- Simple: BlockSpec(slot=Slot(1)) - framework computes everything
22+
- Custom: BlockSpec(slot=Slot(1), proposer_index=ValidatorIndex(5)) - override specific fields
23+
- Invalid: BlockSpec(slot=Slot(1), state_root=Bytes32.zero()) - test invalid blocks
24+
"""
25+
26+
slot: Slot
27+
"""The slot for this block (required)."""
28+
29+
proposer_index: ValidatorIndex | None = None
30+
"""
31+
The proposer index for this block.
32+
33+
If None, framework selects using round-robin based on slot and num_validators.
34+
"""
35+
36+
parent_root: Bytes32 | None = None
37+
"""
38+
The root of the parent block.
39+
40+
If None, framework computes from state.latest_block_header.
41+
"""
42+
43+
state_root: Bytes32 | None = None
44+
"""
45+
The state root after applying this block.
46+
47+
If None, framework computes via state_transition dry-run.
48+
"""
49+
50+
body: BlockBody | None = None
51+
"""
52+
The block body containing attestations.
53+
54+
If None, framework creates empty body for state transition tests,
55+
or collects attestations for fork choice tests.
56+
"""

packages/testing/src/consensus_testing/builders.py

Lines changed: 0 additions & 129 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Consensus layer pre-state generation."""
2+
3+
from typing import Any
4+
5+
from lean_spec.subspecs.containers.state import State, Validators
6+
from lean_spec.subspecs.containers.validator import Validator
7+
from lean_spec.types import Bytes52, Uint64
8+
9+
10+
def generate_pre_state(**kwargs: Any) -> State:
11+
"""
12+
Generate a default pre-state for consensus tests.
13+
14+
Args:
15+
**kwargs: Optional keyword arguments:
16+
- genesis_time: The genesis timestamp (defaults to Uint64(0)).
17+
- validators: Validators list (defaults to 4 validators with dummy pubkeys).
18+
19+
Returns:
20+
State: A properly initialized consensus state.
21+
"""
22+
genesis_time = kwargs.get("genesis_time", Uint64(0))
23+
24+
# If validators not provided, create a default set of 4 validators with dummy pubkeys
25+
if "validators" not in kwargs:
26+
validators = Validators(data=[Validator(pubkey=Bytes52.zero()) for _ in range(4)])
27+
else:
28+
validators = kwargs["validators"]
29+
30+
return State.generate_genesis(genesis_time=genesis_time, validators=validators)

0 commit comments

Comments
 (0)