Skip to content

Commit 97f6040

Browse files
committed
fix: cleanups from comments on PR leanEthereum#76
1 parent 6c892e4 commit 97f6040

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

packages/tests/src/lean_spec_tests/pytest_plugins/filler.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"""Pytest plugin for generating consensus test fixtures."""
22

33
import json
4+
import shutil
5+
import sys
6+
import textwrap
7+
from collections import defaultdict
48
from pathlib import Path
59
from typing import Any, List
610

@@ -75,8 +79,6 @@ def write_fixtures(self) -> None:
7579
Groups fixtures by their base test function (stripping parameters)
7680
so all parametrized variations end up in the same JSON file.
7781
"""
78-
from collections import defaultdict
79-
8082
# Group fixtures by (file_path, base_function_name, format)
8183
grouped: dict[tuple[str, str, str], list[tuple[str, Any, str]]] = defaultdict(list)
8284

@@ -154,9 +156,6 @@ def pytest_addoption(parser: pytest.Parser) -> None:
154156

155157
def pytest_configure(config: pytest.Config) -> None:
156158
"""Setup fixture generation session."""
157-
import sys
158-
import textwrap
159-
160159
# Register fork validity markers
161160
config.addinivalue_line(
162161
"markers",
@@ -227,8 +226,6 @@ def pytest_configure(config: pytest.Config) -> None:
227226
returncode=pytest.ExitCode.USAGE_ERROR,
228227
)
229228
# Clean if requested
230-
import shutil
231-
232229
shutil.rmtree(output_dir)
233230

234231
# Create output directory

packages/tests/src/lean_spec_tests/test_fixtures/fork_choice.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from lean_spec.subspecs.containers.block.types import Attestations
1010
from lean_spec.subspecs.containers.slot import Slot
1111
from lean_spec.subspecs.containers.state.state import State
12+
from lean_spec.subspecs.forkchoice import Store
13+
from lean_spec.subspecs.ssz import hash_tree_root
14+
from lean_spec.types import Uint64
1215

1316
from ..test_types import AttestationStep, BlockStep, ForkChoiceStep, TickStep
1417
from .base import BaseConsensusFixture
@@ -64,8 +67,6 @@ def set_anchor_block_default(self) -> "ForkChoiceTest":
6467
anchor_state itself.
6568
"""
6669
if self.anchor_block is None:
67-
from lean_spec.subspecs.ssz.hash import hash_tree_root
68-
6970
self.anchor_block = Block(
7071
slot=self.anchor_state.latest_block_header.slot,
7172
proposer_index=self.anchor_state.latest_block_header.proposer_index,
@@ -94,8 +95,6 @@ def make_fixture(self) -> "ForkChoiceTest":
9495
AssertionError
9596
If any step fails unexpectedly or checks don't match Store state.
9697
"""
97-
from lean_spec.subspecs.forkchoice.store import Store
98-
9998
# Initialize Store from anchor
10099
# anchor_block is guaranteed to be set by the validator
101100
assert self.anchor_block is not None, "anchor_block must be set"
@@ -109,15 +108,10 @@ def make_fixture(self) -> "ForkChoiceTest":
109108
try:
110109
if isinstance(step, TickStep):
111110
# Advance time
112-
from lean_spec.types import Uint64
113-
114111
store.advance_time(Uint64(step.time), has_proposal=False)
115112

116113
elif isinstance(step, BlockStep):
117114
# Automatically advance time to block's slot before processing
118-
# (Like consensus-specs' tick_and_add_block helper)
119-
from lean_spec.types import Uint64
120-
121115
block = step.block.message
122116
block_time = store.config.genesis_time + block.slot * Uint64(SECONDS_PER_SLOT)
123117

src/lean_spec/subspecs/forkchoice/helpers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ def get_fork_choice_head(
5555
children_map.setdefault(block.parent_root, []).append(block_hash)
5656

5757
# Walk down tree, choosing child with most votes (tiebreak by lexicographic hash)
58-
# Matches consensus-specs: (weight, root) for tie-breaking
5958
current = root
6059
while True:
6160
children = children_map.get(current, [])
6261
if not children:
6362
return current
6463

6564
# Choose best child: most votes, then lexicographically highest hash
66-
# Note: Removed slot tiebreaker to match consensus-specs
6765
current = max(children, key=lambda x: (vote_weights.get(x, 0), x))
6866

6967

src/lean_spec/subspecs/forkchoice/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class method acts as a factory for creating a new Store instance.
102102
anchor_root = hash_tree_root(anchor_block)
103103
anchor_slot = anchor_block.slot
104104

105-
# Create checkpoint from anchor block (matches consensus-specs)
105+
# Create checkpoint from anchor block
106106
# The anchor block becomes the initial justified and finalized checkpoint
107107
anchor_checkpoint = Checkpoint(root=anchor_root, slot=anchor_slot)
108108

0 commit comments

Comments
 (0)