Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
2. Install dependencies: `uv sync --all-packages`
3. Make your changes
4. Run checks: `uvx tox -e all-checks`
5. Run tests: `uvx pytest`
5. Run tests: `uvx tox -e pytest`
6. Submit a pull request

## Pull Request Guidelines
Expand Down
7 changes: 2 additions & 5 deletions packages/testing/src/consensus_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

from typing import Type

from framework.base_types import CamelModel

from . import forks
from .block_spec import BlockSpec
from .genesis import generate_pre_state
from .test_fixtures import (
BaseConsensusFixture,
ForkChoiceTest,
Expand All @@ -15,11 +11,13 @@
from .test_types import (
AttestationStep,
BaseForkChoiceStep,
BlockSpec,
BlockStep,
ForkChoiceStep,
StateExpectation,
StoreChecks,
TickStep,
generate_pre_state,
)

StateTransitionTestFiller = Type[StateTransitionTest]
Expand All @@ -31,7 +29,6 @@
"forks",
"generate_pre_state",
# Base types
"CamelModel",
# Fixture classes
"BaseConsensusFixture",
"StateTransitionTest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from lean_spec.subspecs.ssz import hash_tree_root
from lean_spec.types import Bytes32, Bytes4000, Uint64, ValidatorIndex

from ..block_spec import BlockSpec
from ..test_types import AttestationStep, BlockStep, ForkChoiceStep, TickStep
from ..test_types import AttestationStep, BlockSpec, BlockStep, ForkChoiceStep, TickStep
from .base import BaseConsensusFixture


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from lean_spec.subspecs.ssz.hash import hash_tree_root
from lean_spec.types import Bytes32, ValidatorIndex

from ..block_spec import BlockSpec
from ..test_types import StateExpectation
from ..test_types import BlockSpec, StateExpectation
from .base import BaseConsensusFixture


Expand Down
4 changes: 4 additions & 0 deletions packages/testing/src/consensus_testing/test_types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test types for consensus test fixtures."""

from .block_spec import BlockSpec
from .genesis import generate_pre_state
from .state_expectation import StateExpectation
from .step_types import (
AttestationStep,
Expand All @@ -14,8 +16,10 @@
"StateExpectation",
"StoreChecks",
"BaseForkChoiceStep",
"BlockSpec",
"TickStep",
"BlockStep",
"AttestationStep",
"ForkChoiceStep",
"generate_pre_state",
]
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""Lightweight block specification for test definitions."""

from pydantic import BaseModel

from lean_spec.subspecs.containers.block import BlockBody
from lean_spec.subspecs.containers.slot import Slot
from lean_spec.types import Bytes32, ValidatorIndex
from lean_spec.types import Bytes32, CamelModel, ValidatorIndex


class BlockSpec(BaseModel):
class BlockSpec(CamelModel):
"""
Block specification for test definitions.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

from typing import TYPE_CHECKING

from pydantic import BaseModel

from lean_spec.subspecs.containers.slot import Slot
from lean_spec.types import Bytes32
from lean_spec.types import Bytes32, CamelModel

if TYPE_CHECKING:
from lean_spec.subspecs.containers.state import State


class StateExpectation(BaseModel):
class StateExpectation(CamelModel):
"""
Expected State fields after state transition (selective validation).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

from typing import Annotated, Any, Literal, Union

from pydantic import BaseModel, ConfigDict, Field, PrivateAttr, field_serializer
from pydantic import ConfigDict, Field, PrivateAttr, field_serializer

from lean_spec.subspecs.containers import SignedAttestation
from lean_spec.subspecs.containers.block.block import Block
from lean_spec.types import CamelModel

from ..block_spec import BlockSpec
from .block_spec import BlockSpec
from .store_checks import StoreChecks


class BaseForkChoiceStep(BaseModel):
class BaseForkChoiceStep(CamelModel):
"""
Base class for fork choice event steps.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

from typing import TYPE_CHECKING

from pydantic import BaseModel

from lean_spec.subspecs.containers.slot import Slot
from lean_spec.types import Bytes32, Uint64
from lean_spec.types import Bytes32, CamelModel, Uint64

if TYPE_CHECKING:
from lean_spec.subspecs.forkchoice.store import Store


class StoreChecks(BaseModel):
class StoreChecks(CamelModel):
"""
Store state checks for fork choice tests.

Expand Down
6 changes: 0 additions & 6 deletions packages/testing/src/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@
This module provides base classes and utilities that are common across
both consensus and execution layer testing.
"""

from framework.base_types import CamelModel

__all__ = [
"CamelModel",
]
30 changes: 0 additions & 30 deletions packages/testing/src/framework/base_types.py

This file was deleted.

6 changes: 3 additions & 3 deletions packages/testing/src/framework/test_fixtures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from pydantic import Field

from framework.base_types import CamelModel
from framework.forks import BaseFork
from lean_spec.types import CamelModel


class BaseFixture(CamelModel):
Expand Down Expand Up @@ -117,9 +117,9 @@ def fill_info(
"""
if "comment" not in self.info:
self.info["comment"] = "`leanSpec` generated test"
self.info["test-id"] = test_id
self.info["testId"] = test_id
self.info["description"] = description
self.info["fixture-format"] = self.format_name
self.info["fixtureFormat"] = self.format_name

# Set network field on the fixture itself
self.network = fork.name()
Expand Down
8 changes: 2 additions & 6 deletions src/lean_spec/subspecs/chain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
Lean Consensus Experimental Chain.
"""

from pydantic import BaseModel, ConfigDict
from typing_extensions import Final

from lean_spec.types import BasisPoint, Uint64
from lean_spec.types import BasisPoint, StrictBaseModel, Uint64

# --- Time Parameters ---

Expand Down Expand Up @@ -75,15 +74,12 @@
"""The maximum number of validators that can be in the registry."""


class _ChainConfig(BaseModel):
class _ChainConfig(StrictBaseModel):
"""
A model holding the canonical, immutable configuration constants
for the chain.
"""

# Configuration to make the model immutable.
model_config = ConfigDict(frozen=True, extra="forbid")

# Time Parameters
slot_duration_ms: Uint64
second_per_slot: Uint64
Expand Down
8 changes: 4 additions & 4 deletions src/lean_spec/subspecs/koalabear/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from typing import Self

from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import Field, field_validator

from lean_spec.types import StrictBaseModel

# =================================================================
# Field Constants
Expand Down Expand Up @@ -67,11 +69,9 @@
# =================================================================


class Fp(BaseModel):
class Fp(StrictBaseModel):
"""An element in the KoalaBear prime field F_p."""

model_config = ConfigDict(frozen=True)

value: int = Field(ge=0, lt=P, description="Field element value in the range [0, P)")

@field_validator("value", mode="before")
Expand Down
7 changes: 3 additions & 4 deletions src/lean_spec/subspecs/poseidon2/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from itertools import chain
from typing import List

from pydantic import BaseModel, ConfigDict, Field, model_validator
from pydantic import Field, model_validator

from ...types import StrictBaseModel
from ..koalabear.field import Fp
from .constants import (
ROUND_CONSTANTS_16,
Expand All @@ -30,11 +31,9 @@
"""


class Poseidon2Params(BaseModel):
class Poseidon2Params(StrictBaseModel):
"""Parameters for a specific Poseidon2 instance."""

model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)

width: int = Field(gt=0, description="The size of the state (t).")
rounds_f: int = Field(gt=0, description="Total number of 'full' rounds.")
rounds_p: int = Field(ge=0, description="Total number of 'partial' rounds.")
Expand Down
8 changes: 4 additions & 4 deletions src/lean_spec/subspecs/ssz/merkle_proof/gindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

from typing import List

from pydantic import BaseModel, ConfigDict, Field
from pydantic import Field

from lean_spec.types import StrictBaseModel

class GeneralizedIndex(BaseModel):

class GeneralizedIndex(StrictBaseModel):
"""
Represents a Generalized Merkle Tree Index.

Helper methods are provided for tree navigation.
"""

model_config = ConfigDict(strict=True)

value: int = Field(..., gt=0, description="The index value, must be a positive integer.")

def __hash__(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/ssz/merkle_proof/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pydantic import Field, model_validator

from lean_spec.types.base import StrictBaseModel
from lean_spec.types import StrictBaseModel
from lean_spec.types.byte_arrays import Bytes32

from ..constants import ZERO_HASH
Expand Down
7 changes: 3 additions & 4 deletions src/lean_spec/subspecs/xmss/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
We also provide a test instantiation for testing purposes.
"""

from pydantic import BaseModel, ConfigDict
from typing_extensions import Final

from lean_spec.types import StrictBaseModel

from ..koalabear import Fp


class XmssConfig(BaseModel):
class XmssConfig(StrictBaseModel):
"""A model holding the configuration constants for an XMSS preset."""

model_config = ConfigDict(frozen=True, extra="forbid")

# --- Core Scheme Configuration ---
MESSAGE_LENGTH: int
"""The length in bytes for all messages to be signed."""
Expand Down
Loading
Loading