Skip to content

Commit 68f010a

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 68f010a

File tree

15 files changed

+455
-353
lines changed

15 files changed

+455
-353
lines changed

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)