test: refactor test fixture and more tests#484
Merged
tcoratger merged 3 commits intoleanEthereum:mainfrom Mar 26, 2026
Merged
Conversation
tcoratger
commented
Mar 25, 2026
Comment on lines
+574
to
+697
|
|
||
|
|
||
| FAKE_ROOT = Bytes32(b"\xde\xad" + b"\x00" * 30) | ||
| """A root that will never appear in the store.""" | ||
|
|
||
|
|
||
| def test_attestation_unknown_target_block_rejected( | ||
| fork_choice_test: ForkChoiceTestFiller, | ||
| ) -> None: | ||
| """ | ||
| Attestation referencing an unknown target block is rejected. | ||
|
|
||
| Scenario | ||
| -------- | ||
| Build a chain with blocks at slots 1 and 2. | ||
| Submit attestation whose target root does not exist in the store. | ||
|
|
||
| Expected: | ||
| - Validation fails with "Unknown target block" | ||
| """ | ||
| fork_choice_test( | ||
| steps=[ | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(1), label="block_1"), | ||
| checks=StoreChecks(head_slot=Slot(1)), | ||
| ), | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(2), label="block_2"), | ||
| checks=StoreChecks(head_slot=Slot(2)), | ||
| ), | ||
| AttestationStep( | ||
| attestation=GossipAttestationSpec( | ||
| validator_id=ValidatorIndex(1), | ||
| slot=Slot(2), | ||
| target_slot=Slot(2), | ||
| target_root_label="block_2", | ||
| target_root_override=FAKE_ROOT, | ||
| valid_signature=False, | ||
| ), | ||
| valid=False, | ||
| expected_error="Unknown target block", | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| def test_attestation_unknown_head_block_rejected( | ||
| fork_choice_test: ForkChoiceTestFiller, | ||
| ) -> None: | ||
| """ | ||
| Attestation referencing an unknown head block is rejected. | ||
|
|
||
| Scenario | ||
| -------- | ||
| Build a chain with blocks at slots 1 and 2. | ||
| Submit attestation whose head root does not exist in the store. | ||
|
|
||
| Expected: | ||
| - Validation fails with "Unknown head block" | ||
| """ | ||
| fork_choice_test( | ||
| steps=[ | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(1), label="block_1"), | ||
| checks=StoreChecks(head_slot=Slot(1)), | ||
| ), | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(2), label="block_2"), | ||
| checks=StoreChecks(head_slot=Slot(2)), | ||
| ), | ||
| AttestationStep( | ||
| attestation=GossipAttestationSpec( | ||
| validator_id=ValidatorIndex(1), | ||
| slot=Slot(2), | ||
| target_slot=Slot(2), | ||
| target_root_label="block_2", | ||
| head_root_override=FAKE_ROOT, | ||
| valid_signature=False, | ||
| ), | ||
| valid=False, | ||
| expected_error="Unknown head block", | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| def test_attestation_unknown_source_block_rejected( | ||
| fork_choice_test: ForkChoiceTestFiller, | ||
| ) -> None: | ||
| """ | ||
| Attestation referencing an unknown source block is rejected. | ||
|
|
||
| Scenario | ||
| -------- | ||
| Build a chain with blocks at slots 1 and 2. | ||
| Submit attestation whose source root does not exist in the store. | ||
|
|
||
| Expected: | ||
| - Validation fails with "Unknown source block" | ||
| """ | ||
| fork_choice_test( | ||
| steps=[ | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(1), label="block_1"), | ||
| checks=StoreChecks(head_slot=Slot(1)), | ||
| ), | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(2), label="block_2"), | ||
| checks=StoreChecks(head_slot=Slot(2)), | ||
| ), | ||
| AttestationStep( | ||
| attestation=GossipAttestationSpec( | ||
| validator_id=ValidatorIndex(1), | ||
| slot=Slot(2), | ||
| target_slot=Slot(2), | ||
| target_root_label="block_2", | ||
| source_root_override=FAKE_ROOT, | ||
| valid_signature=False, | ||
| ), | ||
| valid=False, | ||
| expected_error="Unknown source block", | ||
| ), | ||
| ], | ||
| ) |
Collaborator
Author
There was a problem hiding this comment.
Here I've identified attestation validations paths that were not tested!
| target_root_label="block_2", | ||
| ), | ||
| valid=False, | ||
| expected_error="Target checkpoint slot mismatch", |
Collaborator
Author
There was a problem hiding this comment.
I think this is nice to check the error message we expect to be sure that we are testing the right error and not another one that we don't expect to happen here.
Comment on lines
+719
to
+720
| # Reuse the spec for honest attestations. | ||
| attestation_data = store.produce_attestation_data(spec.slot) |
Collaborator
Author
There was a problem hiding this comment.
Here I think that it is better to reuse the spec method directly.
unnawut
approved these changes
Mar 26, 2026
tests/consensus/devnet/fc/test_gossip_attestation_validation.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Unnawut Leepaisalsuwanna <921194+unnawut@users.noreply.github.com>
1 task
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.
🗒️ Description
Followup PR on top of #479
🔗 Related Issues or PRs
✅ Checklist
toxchecks to avoid unnecessary CI fails:uvx tox