Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/testing/src/consensus_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
from .test_fixtures import (
ApiEndpointTest,
BaseConsensusFixture,
DropComponentMessageBinding,
ForkChoiceTest,
GossipsubHandlerTest,
IncrementComponentSlot,
IncrementEmittedSlot,
JustifiabilityTest,
NetworkingCodecTest,
PoseidonPermutationTest,
RebindComponentToAlternateHeadRoot,
RebindToAlternateHeadRoot,
SlotClockTest,
SSZTest,
StateTransitionTest,
SwapComponentMessageBindings,
SwapComponentParticipantPublicKey,
SwapParticipantPublicKey,
SyncTest,
VerifyMultiMessageProofsTest,
VerifySignaturesTest,
VerifySingleMessageProofsTest,
)
Expand All @@ -42,6 +48,7 @@
StateTransitionTestFiller = Type[StateTransitionTest]
ForkChoiceTestFiller = Type[ForkChoiceTest]
VerifySingleMessageProofsTestFiller = Type[VerifySingleMessageProofsTest]
VerifyMultiMessageProofsTestFiller = Type[VerifyMultiMessageProofsTest]
VerifySignaturesTestFiller = Type[VerifySignaturesTest]
SSZTestFiller = Type[SSZTest]
NetworkingCodecTestFiller = Type[NetworkingCodecTest]
Expand Down Expand Up @@ -70,6 +77,12 @@
"RebindToAlternateHeadRoot",
"IncrementEmittedSlot",
"SwapParticipantPublicKey",
"VerifyMultiMessageProofsTest",
"RebindComponentToAlternateHeadRoot",
"IncrementComponentSlot",
"SwapComponentParticipantPublicKey",
"SwapComponentMessageBindings",
"DropComponentMessageBinding",
"VerifySignaturesTest",
"SSZTest",
"NetworkingCodecTest",
Expand All @@ -94,6 +107,7 @@
"StateTransitionTestFiller",
"ForkChoiceTestFiller",
"VerifySingleMessageProofsTestFiller",
"VerifyMultiMessageProofsTestFiller",
"VerifySignaturesTestFiller",
"SSZTestFiller",
"NetworkingCodecTestFiller",
Expand Down
14 changes: 14 additions & 0 deletions packages/testing/src/consensus_testing/test_fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
from .ssz import SSZTest
from .state_transition import StateTransitionTest
from .sync import SyncTest
from .verify_multi_message_proofs import (
DropComponentMessageBinding,
IncrementComponentSlot,
RebindComponentToAlternateHeadRoot,
SwapComponentMessageBindings,
SwapComponentParticipantPublicKey,
VerifyMultiMessageProofsTest,
)
from .verify_signatures import VerifySignaturesTest
from .verify_single_message_proofs import (
IncrementEmittedSlot,
Expand All @@ -27,6 +35,12 @@
"RebindToAlternateHeadRoot",
"IncrementEmittedSlot",
"SwapParticipantPublicKey",
"VerifyMultiMessageProofsTest",
"RebindComponentToAlternateHeadRoot",
"IncrementComponentSlot",
"SwapComponentParticipantPublicKey",
"SwapComponentMessageBindings",
"DropComponentMessageBinding",
"VerifySignaturesTest",
"SSZTest",
"NetworkingCodecTest",
Expand Down
28 changes: 28 additions & 0 deletions packages/testing/src/consensus_testing/test_fixtures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,31 @@ def serialize_exception(self, value: type[Exception] | None) -> str | None:
if value is None:
return None
return value.__name__

def assert_expected_outcome(self, exception_raised: Exception | None) -> None:
"""Compare a self-verification outcome against the configured expectation.

A fixture that self-verifies its own output catches the verifier exception.
It then hands the caught exception here to decide pass or fail.

Args:
exception_raised: The exception the verifier raised, or None on success.

Raises:
AssertionError: When the outcome disagrees with the expectation.
"""
# No expectation means the bundle is honest and must verify.
if self.expect_exception is None:
if exception_raised is not None:
raise AssertionError(f"Verifier rejected an honest bundle: {exception_raised}")
# An expectation that produced no exception means the tamper went undetected.
elif exception_raised is None:
raise AssertionError(
f"Expected {self.expect_exception.__name__} but verification succeeded"
)
# A wrong exception type means the rejection fired for the wrong reason.
elif not isinstance(exception_raised, self.expect_exception):
raise AssertionError(
f"Expected {self.expect_exception.__name__} but got "
f"{type(exception_raised).__name__}: {exception_raised}"
)
Loading
Loading