-
Notifications
You must be signed in to change notification settings - Fork 58
test: improve coverage for checkpoint sync client (83%) #522
Copy link
Copy link
Open
Labels
good first issueGood for newcomersGood for newcomerstestsScope: Changes to the spec testsScope: Changes to the spec tests
Description
Summary
src/lean_spec/subspecs/sync/checkpoint_sync.py has 83% test coverage. While test_checkpoint_sync.py exists, the fetch_finalized_state() error paths and verify_checkpoint_state() validation logic are not fully covered.
Coverage stats:
| File | Statements | Covered | Coverage |
|---|---|---|---|
sync/checkpoint_sync.py |
48 | 9 uncovered | 83% |
Uncovered lines: 94–103 (HTTP error handling in fetch_finalized_state), 153–155 (exception path in verify_checkpoint_state)
What needs testing
fetch_finalized_state()
- Happy path: Mock HTTP response with valid SSZ data, verify deserialization
- Network error:
httpx.RequestErrorwrapped inCheckpointSyncError - HTTP error status:
httpx.HTTPStatusError(e.g., 404, 500) wrapped inCheckpointSyncError - Deserialization error: Corrupt SSZ data raises
CheckpointSyncError - URL normalization: Trailing slash in URL is stripped before appending endpoint
verify_checkpoint_state()
- Valid state: Returns True for state with validators
- No validators: Returns False, logs error
- Exceeds registry limit: Returns False when validator count > VALIDATOR_REGISTRY_LIMIT
- Exception during verification: Returns False (catches any exception)
- State root computation: Verify
hash_tree_rootis called (logged for debugging)
Why this matters
- Fast startup: Checkpoint sync enables nodes to start in seconds vs hours. Error handling must be robust
- Trust boundary: The fetched state comes from an external source. Validation prevents using corrupt state
- Error clarity: Specific
CheckpointSyncErrormessages help operators diagnose connectivity issues
How to test
Running tests with coverage
uv run pytest tests/lean_spec/subspecs/sync/test_checkpoint_sync.py -v \
--cov=src/lean_spec/subspecs/sync/checkpoint_sync --cov-report=term-missingTarget: ≥95% line coverage (small module).
Test file location
tests/lean_spec/subspecs/sync/test_checkpoint_sync.py (extend existing)
Testing tips
- Use
pytest-httpxor mockhttpx.AsyncClientfor HTTP tests - For
verify_checkpoint_state(), create a mock State with configurable validator count - Test
CheckpointSyncErrormessage content for each error path - The
FINALIZED_STATE_ENDPOINTconstant can be used to verify correct URL construction
Using Claude Code subagents
1. code-tester agent — Generate the tests
Extend tests in
tests/lean_spec/subspecs/sync/test_checkpoint_sync.py. Cover fetch_finalized_state error paths (httpx.RequestError, HTTPStatusError, corrupt SSZ), verify_checkpoint_state with no validators, exceeding registry limit, and exception during hash_tree_root.
Workflow
- Add HTTP error path tests for fetch_finalized_state
- Add validation edge cases for verify_checkpoint_state
- Run
uvx tox -e all-checksto pass all quality checks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomerstestsScope: Changes to the spec testsScope: Changes to the spec tests