Add tests to ensure that cryptography exception during transcript generation / verification does not get propagated during ritual ceremony.

pull/3524/head
derekpierre 2024-07-29 16:37:27 -04:00
parent 81fb62dc07
commit 2135d32885
No known key found for this signature in database
1 changed files with 22 additions and 2 deletions

View File

@ -1,3 +1,5 @@
from unittest.mock import patch
import pytest import pytest
from atxm.exceptions import Fault, InsufficientFunds from atxm.exceptions import Fault, InsufficientFunds
@ -139,8 +141,18 @@ def test_perform_round_1(
lambda *args, **kwargs: Coordinator.RitualStatus.DKG_AWAITING_TRANSCRIPTS lambda *args, **kwargs: Coordinator.RitualStatus.DKG_AWAITING_TRANSCRIPTS
) )
phase_id = PhaseId(ritual_id=0, phase=PHASE1) # cryptographic issue does not raise exception
with patch(
"nucypher.crypto.ferveo.dkg.generate_transcript",
side_effect=Exception("transcript cryptography failed"),
):
async_tx = ursula.perform_round_1(
ritual_id=0, authority=random_address, participants=cohort, timestamp=0
)
# exception not raised, but None returned
assert async_tx is None
phase_id = PhaseId(ritual_id=0, phase=PHASE1)
assert ( assert (
ursula.dkg_storage.get_ritual_phase_async_tx(phase_id=phase_id) is None ursula.dkg_storage.get_ritual_phase_async_tx(phase_id=phase_id) is None
), "no tx data as yet" ), "no tx data as yet"
@ -244,8 +256,16 @@ def test_perform_round_2(
lambda *args, **kwargs: Coordinator.RitualStatus.DKG_AWAITING_AGGREGATIONS lambda *args, **kwargs: Coordinator.RitualStatus.DKG_AWAITING_AGGREGATIONS
) )
phase_2_id = PhaseId(ritual_id=0, phase=PHASE2) # cryptographic issue does not raise exception
with patch(
"nucypher.crypto.ferveo.dkg.verify_aggregate",
side_effect=Exception("aggregate cryptography failed"),
):
async_tx = ursula.perform_round_2(ritual_id=0, timestamp=0)
# exception not raised, but None returned
assert async_tx is None
phase_2_id = PhaseId(ritual_id=0, phase=PHASE2)
assert ( assert (
ursula.dkg_storage.get_ritual_phase_async_tx(phase_id=phase_2_id) is None ursula.dkg_storage.get_ritual_phase_async_tx(phase_id=phase_2_id) is None
), "no tx data as yet" ), "no tx data as yet"