test(validator): add coverage for registry and service modules#502
Merged
tcoratger merged 2 commits intoleanEthereum:mainfrom Mar 30, 2026
Merged
Conversation
tcoratger
reviewed
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #493.
validator/registry.pyandvalidator/service.pyhad 0% test coveragedespite being actively used production modules. This PR adds comprehensive
unit and integration tests for both.
What was tested and why
registry.py
ValidatorManifestEntry— field validation including YAML's integercoercion of
0x-prefixed hex strings, which silently breaks pubkeyparsing without this test
ValidatorManifest.from_yaml_file()— direct YAML loading, previouslyuntested even though it's the only entry point for key metadata
load_node_validator_mapping()— normal loading, empty file, singlenode cases
ValidatorRegistry— full lifecycle:add/get,__contains__,__len__,indices(),primary_index(),from_yaml()(happy path,unknown node, missing manifest entry, missing key file, corrupt key
file for both attestation and proposal keys), and
from_secret_keys()ValidatorEntry— construction and immutability (frozen dataclass)service.py
_sign_with_key— key advancement loop (no advance, one advance,multiple advances), registry persistence after advancement, and
isolation between attestation and proposal keys. This is the most
security-sensitive path: a bug here could exhaust OTS keys or reuse them
_sign_block/_sign_attestation— correct field population, correctkey routing (proposal vs attestation), and
ValueErrorfor unknownvalidators
_maybe_produce_block— not-proposer early exit, no-head-state earlyexit, and
AssertionErrorfrom the store being swallowed gracefully_produce_attestations— block-wait polling loop (8 retries, earlyexit when block arrives), local gossip processing before publish,
counter increments
run()— interval 0 routes to block production, interval ≥ 1 routesto attestation, empty registry skips all duties, duplicate slot
prevention, and
_attested_slotspruning to bound memoryCoverage achieved
validator/registry.pyvalidator/service.pyNotes
@dataclass(slots=True)onValidatorServicepreventspatch.object(instance, method)— all mocks patch the class andinclude
selfas the first parameterSignature.zero()is used wherever Pydantic validation rejectsMagicMockfor signature fieldspytest-asynciowithmode=autoalready configuredin
pyproject.tomltmp_pathfor temporary YAML files and mock key files.SyncService,SlotClock, andStore, and use_zero_sig()for signature fields.uvx tox -e all-checks(ruff,ty,codespell,mdformat).