11use crate :: common;
22
3- use mpc_primitives:: domain:: { Curve , DomainId } ;
3+ use mpc_primitives:: domain:: DomainId ;
44use near_mpc_contract_interface:: types:: {
55 DomainConfig , DomainPurpose , Protocol , ProtocolContractState , ReconstructionThreshold ,
6+ RunningContractState ,
67} ;
78use rand:: SeedableRng ;
89
10+ /// Panics if no domain matches; each protocol appears at most once in this test's domain set.
11+ fn find_domain_id ( contract_state : & RunningContractState , protocol_type : Protocol ) -> DomainId {
12+ contract_state
13+ . domains
14+ . domains
15+ . iter ( )
16+ . find ( |d| d. protocol == protocol_type)
17+ . unwrap_or_else ( || panic ! ( "no domain with protocol {protocol_type:?}" ) )
18+ . id
19+ }
20+
921/// Tests that signature and CKD requests are processed using the previous
1022/// running state's threshold while resharing is in progress.
1123///
@@ -46,43 +58,17 @@ async fn test_request_during_resharing() {
4658 cluster. kill_nodes ( & [ 5 ] ) . expect ( "failed to kill node 5" ) ;
4759
4860 // then
49- let ecdsa_domain = contract_state
50- . domains
51- . domains
52- . iter ( )
53- . find ( |d| {
54- Curve :: from ( d. protocol ) == Curve :: Secp256k1
55- && d. protocol == Protocol :: CaitSith
56- && d. purpose == DomainPurpose :: Sign
57- } )
58- . expect ( "no CaitSith Sign domain" ) ;
59- let robust_ecdsa_domain = contract_state
60- . domains
61- . domains
62- . iter ( )
63- . find ( |d| d. protocol == Protocol :: DamgardEtAl && d. purpose == DomainPurpose :: Sign )
64- . expect ( "no DamgardEtAl Sign domain" ) ;
65- let eddsa_domain = contract_state
66- . domains
67- . domains
68- . iter ( )
69- . find ( |d| {
70- Curve :: from ( d. protocol ) == Curve :: Edwards25519 && d. purpose == DomainPurpose :: Sign
71- } )
72- . expect ( "no Edwards25519 Sign domain" ) ;
73- let ckd_domain = contract_state
74- . domains
75- . domains
76- . iter ( )
77- . find ( |d| d. purpose == DomainPurpose :: CKD )
78- . expect ( "no CKD domain" ) ;
61+ let ecdsa_domain_id = find_domain_id ( & contract_state, Protocol :: CaitSith ) ;
62+ let robust_ecdsa_domain_id = find_domain_id ( & contract_state, Protocol :: DamgardEtAl ) ;
63+ let eddsa_domain_id = find_domain_id ( & contract_state, Protocol :: Frost ) ;
64+ let ckd_domain_id = find_domain_id ( & contract_state, Protocol :: ConfidentialKeyDerivation ) ;
7965
8066 let mut rng = rand:: rngs:: StdRng :: seed_from_u64 ( 0 ) ;
8167 for i in 0 ..3 {
8268 for ( label, domain_id, is_eddsa) in [
83- ( "ECDSA" , ecdsa_domain . id , false ) ,
84- ( "robust ECDSA" , robust_ecdsa_domain . id , false ) ,
85- ( "EdDSA" , eddsa_domain . id , true ) ,
69+ ( "ECDSA" , ecdsa_domain_id , false ) ,
70+ ( "robust ECDSA" , robust_ecdsa_domain_id , false ) ,
71+ ( "EdDSA" , eddsa_domain_id , true ) ,
8672 ] {
8773 let payload = if is_eddsa {
8874 common:: generate_eddsa_payload ( & mut rng)
@@ -104,7 +90,7 @@ async fn test_request_during_resharing() {
10490 tracing:: info!( i, "sending CKD request during resharing" ) ;
10591 let outcome = cluster
10692 . send_ckd_request (
107- ckd_domain . id ,
93+ ckd_domain_id ,
10894 common:: generate_ckd_app_public_key ( & mut rng) ,
10995 cluster. default_user_account ( ) ,
11096 )
0 commit comments