@@ -2,6 +2,7 @@ use super::*;
22use crate :: sign:: tests:: KEY_ID ;
33use crate :: sign:: tests:: KEY_ID_STRING ;
44use crate :: sign:: threshold_sig:: ThresholdSigDataStore ;
5+ use assert_matches:: assert_matches;
56use ic_crypto_internal_csp:: types:: { CspPublicCoefficients , ThresBls12_381_Signature } ;
67use ic_crypto_internal_csp_test_utils:: types:: {
78 csp_sig_thres_bls12381_combined_from_array_of, csp_sig_thres_bls12381_indiv_from_array_of,
@@ -35,7 +36,6 @@ pub const NI_DKG_ID_1: NiDkgId = NiDkgId {
3536
3637mod sign_threshold {
3738 use super :: * ;
38- use assert_matches:: assert_matches;
3939 use ic_crypto_internal_csp:: key_id:: KeyId ;
4040
4141 #[ test]
@@ -570,65 +570,60 @@ mod verify_threshold_sig_share {
570570 }
571571
572572 #[ test]
573- #[ should_panic(
574- expected = "Illegal state: the algorithm of the public key from the threshold \
575- signature data store (which is based on the algorithm of the public coefficients in \
576- the store) is not supported"
577- ) ]
578- fn should_panic_if_csp_returns_invalid_argument_error ( ) {
573+ fn should_forward_error_if_csp_returns_invalid_argument_error ( ) {
579574 let ( sig_share, message, csp_public_key) = ( sig_share ( ) , signable_mock ( ) , csp_public_key ( ) ) ;
580575 let threshold_sig_data_store =
581576 threshold_sig_data_store_with_coeffs_and_pubkey ( & NI_DKG_ID_1 , NODE_ID , csp_public_key) ;
582577 let csp = csp_with_verify_indiv_sig_returning_once ( Err ( invalid_argument ( ) ) ) ;
583578
584- let _panic = ThresholdSigVerifierInternal :: verify_threshold_sig_share (
579+ let result = ThresholdSigVerifierInternal :: verify_threshold_sig_share (
585580 & threshold_sig_data_store,
586581 & csp,
587582 & sig_share,
588583 & message,
589584 & NI_DKG_ID_1 ,
590585 NODE_ID ,
591586 ) ;
587+
588+ assert_matches ! ( result, Err ( CryptoError :: InvalidArgument { .. } ) ) ;
592589 }
593590
594591 #[ test]
595- #[ should_panic(
596- expected = "Illegal state: the algorithm of the public key from the threshold signature data \
597- store (which is based on the algorithm of the public coefficients in the store) is \
598- not supported"
599- ) ]
600- fn should_panic_if_csp_returns_malformed_public_key_error ( ) {
592+ fn should_forward_error_if_csp_returns_malformed_public_key_error ( ) {
601593 let ( sig_share, message, csp_public_key) = ( sig_share ( ) , signable_mock ( ) , csp_public_key ( ) ) ;
602594 let threshold_sig_data_store =
603595 threshold_sig_data_store_with_coeffs_and_pubkey ( & NI_DKG_ID_1 , NODE_ID , csp_public_key) ;
604596 let csp = csp_with_verify_indiv_sig_returning_once ( Err ( malformed_public_key ( ) ) ) ;
605597
606- let _panic = ThresholdSigVerifierInternal :: verify_threshold_sig_share (
598+ let result = ThresholdSigVerifierInternal :: verify_threshold_sig_share (
607599 & threshold_sig_data_store,
608600 & csp,
609601 & sig_share,
610602 & message,
611603 & NI_DKG_ID_1 ,
612604 NODE_ID ,
613605 ) ;
606+
607+ assert_eq ! ( result, Err ( malformed_public_key( ) ) ) ;
614608 }
615609
616610 #[ test]
617- #[ should_panic( expected = "This case cannot occur" ) ]
618- fn should_panic_if_csp_returns_malformed_signature_error ( ) {
611+ fn should_forward_error_if_csp_returns_malformed_signature_error ( ) {
619612 let ( sig_share, message, csp_public_key) = ( sig_share ( ) , signable_mock ( ) , csp_public_key ( ) ) ;
620613 let threshold_sig_data_store =
621614 threshold_sig_data_store_with_coeffs_and_pubkey ( & NI_DKG_ID_1 , NODE_ID , csp_public_key) ;
622615 let csp = csp_with_verify_indiv_sig_returning_once ( Err ( malformed_signature ( ) ) ) ;
623616
624- let _panic = ThresholdSigVerifierInternal :: verify_threshold_sig_share (
617+ let result = ThresholdSigVerifierInternal :: verify_threshold_sig_share (
625618 & threshold_sig_data_store,
626619 & csp,
627620 & sig_share,
628621 & message,
629622 & NI_DKG_ID_1 ,
630623 NODE_ID ,
631624 ) ;
625+
626+ assert_eq ! ( result, Err ( malformed_signature( ) ) ) ;
632627 }
633628
634629 fn csp_with_indiv_pk_returning_once (
@@ -853,9 +848,7 @@ mod combine_threshold_sig_shares {
853848 }
854849
855850 #[ test]
856- #[ should_panic( expected = "The CSP must return a signature of type \
857- `CspSignature::ThresBls12_381(ThresBls12_381_Signature::Combined)`.") ]
858- fn should_panic_if_csp_returns_wrong_signature_type ( ) {
851+ fn should_return_malformed_signature_error_if_csp_returns_wrong_signature_type ( ) {
859852 let shares = shares ( vec ! [ (
860853 NODE_1 ,
861854 threshold_sig_share( vec![ 1 ; IndividualSignatureBytes :: SIZE ] ) ,
@@ -867,12 +860,14 @@ mod combine_threshold_sig_shares {
867860 let threshold_sig_data_store =
868861 threshold_sig_data_store_with ( & NI_DKG_ID_1 , pub_coeffs ( ) , indices) ;
869862
870- let _panic = ThresholdSigVerifierInternal :: combine_threshold_sig_shares (
863+ let result = ThresholdSigVerifierInternal :: combine_threshold_sig_shares (
871864 & threshold_sig_data_store,
872865 & csp,
873866 shares,
874867 & NI_DKG_ID_1 ,
875868 ) ;
869+
870+ assert_matches ! ( result, Err ( CryptoError :: MalformedSignature { .. } ) ) ;
876871 }
877872
878873 #[ test]
0 commit comments