|
| 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 | + """ |
0 commit comments