Skip to content

refactor(forks): rewrite test call sites through the spec (Stage 4B of #686)#703

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/spec-call-sites-stage4b
May 3, 2026
Merged

refactor(forks): rewrite test call sites through the spec (Stage 4B of #686)#703
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/spec-call-sites-stage4b

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

Stage 4B of the multi-fork architecture refactor (#686): rewrite test call sites that go through container methods to instead go through the fork's spec class.

The pattern:

Before After
`state.process_block(block)` `spec.process_block(state, block)`
`store.on_block(signed_block)` `spec.on_block(store, signed_block)`
`signed_block.verify_signatures(vs)` `spec.verify_signatures(signed_block, vs)`
`store.produce_attestation_data(slot)` `spec.produce_attestation_data(store, slot)`
... ...

How tests get `spec`

Two patterns:

  • Test functions: a session-scoped `spec` pytest fixture in `tests/lean_spec/conftest.py` returns `LstarSpec()`. Tests add `spec: LstarSpec` to their signature.
  • Helper / library code (`tests/lean_spec/helpers/builders.py`, `packages/testing/...`): a module-level `_SPEC = LstarSpec()` constant. `LstarSpec` is stateless so a single shared instance is fine.

Out of scope

Internal Store helpers (`aggregate`, `update_head`, `accept_new_attestations`, `update_safe_target`, `tick_interval`, `validate_attestation`, `prune_stale_attestation_data`, `extract_attestations_from_aggregated_payloads`, `compute_block_weights`) are not yet on the spec surface and are left as direct method calls — they migrate alongside the body move in the next stage.

Subspec call sites (`subspecs/sync/`, `subspecs/validator/`, etc.) are also out of scope here — they migrate when the bodies move.

Test plan

  • `uvx tox -e all-checks` (ruff check + format + ty + codespell + mdformat) green.

🤖 Generated with Claude Code

…leanEthereum#686)

Tests that drive state transition, fork choice, block production, and
signature verification now go through the fork's spec class instead of
calling methods directly on the State / Store / SignedBlock containers.

The pattern:

    state.process_block(block)             →  spec.process_block(state, block)
    store.on_block(signed_block)           →  spec.on_block(store, signed_block)
    signed_block.verify_signatures(vs)     →  spec.verify_signatures(signed_block, vs)
    store.produce_attestation_data(slot)   →  spec.produce_attestation_data(store, slot)
    ...

Test functions consume `spec` via a new session-scoped pytest fixture
defined in `tests/lean_spec/conftest.py`. Helper / library code uses a
module-level `_SPEC = LstarSpec()` constant — `LstarSpec` is stateless,
so a single shared instance is fine.

Internal Store helpers (`aggregate`, `update_head`, `accept_new_attestations`,
`update_safe_target`, `tick_interval`, `validate_attestation`,
`prune_stale_attestation_data`, `extract_attestations_from_aggregated_payloads`,
`compute_block_weights`) are not yet on the spec surface and are left as
direct method calls — they migrate alongside the body move in the next stage.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 22afd98 into leanEthereum:main May 3, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant