Skip to content

test: refactor test fixture and more tests#484

Merged
tcoratger merged 3 commits intoleanEthereum:mainfrom
tcoratger:test-fixture
Mar 26, 2026
Merged

test: refactor test fixture and more tests#484
tcoratger merged 3 commits intoleanEthereum:mainfrom
tcoratger:test-fixture

Conversation

@tcoratger
Copy link
Collaborator

🗒️ Description

Followup PR on top of #479

🔗 Related Issues or PRs

✅ Checklist

  • Ran tox checks to avoid unnecessary CI fails:
    uvx tox
  • Considered adding appropriate tests for the changes.
  • Considered updating the online docs in the ./docs/ directory.

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",
),
],
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I've identified attestation validations paths that were not tested!

target_root_label="block_2",
),
valid=False,
expected_error="Target checkpoint slot mismatch",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think that it is better to reuse the spec method directly.

Copy link
Collaborator

@unnawut unnawut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀 🚀

@unnawut unnawut added the tests Scope: Changes to the spec tests label Mar 26, 2026
tcoratger and others added 2 commits March 26, 2026 12:16
Co-authored-by: Unnawut Leepaisalsuwanna <921194+unnawut@users.noreply.github.com>
@tcoratger tcoratger merged commit 23486fc into leanEthereum:main Mar 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Scope: Changes to the spec tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants