From 55efa8e42968f5c2acd9a465fd3c6cdaee30be1d Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Wed, 4 Oct 2023 11:14:34 -0700 Subject: [PATCH] Fix clippy warnings in test code Signed-off-by: Jacinta Ferrant --- src/state_machine.rs | 32 +++++++++++++++----------------- src/taproot.rs | 12 ++++++------ src/v1.rs | 12 ++++++------ src/v2.rs | 9 ++++----- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/state_machine.rs b/src/state_machine.rs index f3a8559..0d0ec4c 100644 --- a/src/state_machine.rs +++ b/src/state_machine.rs @@ -1557,12 +1557,13 @@ mod test { fn setup( ) -> (Coordinator, Vec>) { unsafe { - match LOG_INIT.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) { - Ok(false) => tracing_subscriber::registry() + if let Ok(false) = + LOG_INIT.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) + { + tracing_subscriber::registry() .with(fmt::layer()) .with(EnvFilter::from_default_env()) - .init(), - _ => {} + .init() } } @@ -1739,9 +1740,8 @@ mod test { } fn get_rng() -> impl RngCore + CryptoRng { - let rnd = OsRng; //rand::rngs::StdRng::seed_from_u64(rnd.next_u64()) // todo: fix trait `rand_core::RngCore` is not implemented for `StdRng` - rnd + OsRng } #[test] @@ -1802,7 +1802,7 @@ mod test { Default::default(), ); // publich_shares_done starts out as false - assert_eq!(false, signing_round.public_shares_done()); + assert!(!signing_round.public_shares_done()); // meet the conditions for all public keys received signing_round.state = SignerState::DkgPublicGather; @@ -1840,7 +1840,7 @@ mod test { Default::default(), ); // can_dkg_end starts out as false - assert_eq!(false, signing_round.can_dkg_end()); + assert!(!signing_round.can_dkg_end()); // meet the conditions for DKG_END signing_round.state = SignerState::DkgPrivateGather; @@ -1878,15 +1878,13 @@ mod test { Default::default(), Default::default(), ); - match signing_round.dkg_ended() { - Ok(dkg_end) => match dkg_end { - Message::DkgEnd(dkg_end) => match dkg_end.status { - DkgStatus::Failure(_) => assert!(true), - _ => assert!(false), - }, - _ => assert!(false), - }, - _ => assert!(false), + if let Ok(Message::DkgEnd(dkg_end)) = signing_round.dkg_ended() { + match dkg_end.status { + DkgStatus::Failure(_) => {} + _ => panic!("Expected DkgStatus::Failure"), + } + } else { + panic!("Unexpected Error"); } } } diff --git a/src/taproot.rs b/src/taproot.rs index 7fa5beb..018a338 100644 --- a/src/taproot.rs +++ b/src/taproot.rs @@ -165,7 +165,7 @@ mod test { #[allow(non_snake_case)] fn taproot_sign_verify_v1(merkle_root: Option<[u8; 32]>) { - let mut rng = OsRng::default(); + let mut rng = OsRng; // First create and verify a frost signature let msg = "It was many and many a year ago".as_bytes(); @@ -195,8 +195,8 @@ mod test { let mut sig_agg = v1::Aggregator::new(N, T); sig_agg.init(A.clone()).expect("aggregator init failed"); let tweaked_public_key = compute::tweaked_public_key(&sig_agg.poly[0], merkle_root); - let (nonces, sig_shares) = test_helpers::sign(&msg, &mut S, &mut rng, merkle_root); - let proof = match sig_agg.sign_taproot(&msg, &nonces, &sig_shares, &[], merkle_root) { + let (nonces, sig_shares) = test_helpers::sign(msg, &mut S, &mut rng, merkle_root); + let proof = match sig_agg.sign_taproot(msg, &nonces, &sig_shares, &[], merkle_root) { Err(e) => panic!("Aggregator sign failed: {:?}", e), Ok(proof) => proof, }; @@ -226,7 +226,7 @@ mod test { #[allow(non_snake_case)] fn taproot_sign_verify_v2(merkle_root: Option<[u8; 32]>) { - let mut rng = OsRng::default(); + let mut rng = OsRng; // First create and verify a frost signature let msg = "It was many and many a year ago".as_bytes(); @@ -258,8 +258,8 @@ mod test { let mut sig_agg = v2::Aggregator::new(Nk, T); sig_agg.init(A.clone()).expect("aggregator init failed"); let tweaked_public_key = compute::tweaked_public_key(&sig_agg.poly[0], merkle_root); - let (nonces, sig_shares) = test_helpers::sign(&msg, &mut S, &mut rng, merkle_root); - let proof = match sig_agg.sign_taproot(&msg, &nonces, &sig_shares, &key_ids, merkle_root) { + let (nonces, sig_shares) = test_helpers::sign(msg, &mut S, &mut rng, merkle_root); + let proof = match sig_agg.sign_taproot(msg, &nonces, &sig_shares, &key_ids, merkle_root) { Err(e) => panic!("Aggregator sign failed: {:?}", e), Ok(proof) => proof, }; diff --git a/src/v1.rs b/src/v1.rs index f1fb441..64b463a 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -650,7 +650,7 @@ mod tests { #[test] fn signer_new() { - let mut rng = OsRng::default(); + let mut rng = OsRng; let id = 1; let key_ids = [1, 2, 3]; let n: u32 = 10; @@ -663,7 +663,7 @@ mod tests { #[test] fn signer_gen_nonces() { - let mut rng = OsRng::default(); + let mut rng = OsRng; let id = 1; let key_ids = [1, 2, 3]; let n: u32 = 10; @@ -686,7 +686,7 @@ mod tests { #[test] fn signer_save_load() { - let mut rng = OsRng::default(); + let mut rng = OsRng; let id = 1; let key_ids = [1, 2, 3]; let n: u32 = 10; @@ -703,7 +703,7 @@ mod tests { #[allow(non_snake_case)] #[test] fn aggregator_sign() { - let mut rng = OsRng::default(); + let mut rng = OsRng; let msg = "It was many and many a year ago".as_bytes(); let N: u32 = 10; let T: u32 = 7; @@ -733,8 +733,8 @@ mod tests { let mut sig_agg = v1::Aggregator::new(N, T); sig_agg.init(comms.clone()).expect("aggregator init failed"); - let (nonces, sig_shares) = v1::test_helpers::sign(&msg, &mut signers, &mut rng); - if let Err(e) = sig_agg.sign(&msg, &nonces, &sig_shares, &[]) { + let (nonces, sig_shares) = v1::test_helpers::sign(msg, &mut signers, &mut rng); + if let Err(e) = sig_agg.sign(msg, &nonces, &sig_shares, &[]) { panic!("Aggregator sign failed: {:?}", e); } } diff --git a/src/v2.rs b/src/v2.rs index ffc86e6..e64301b 100644 --- a/src/v2.rs +++ b/src/v2.rs @@ -593,7 +593,7 @@ mod tests { #[test] fn party_save_load() { - let mut rng = OsRng::default(); + let mut rng = OsRng; let key_ids = [1, 2, 3]; let n: u32 = 10; let t: u32 = 7; @@ -609,7 +609,7 @@ mod tests { #[allow(non_snake_case)] #[test] fn aggregator_sign() { - let mut rng = OsRng::default(); + let mut rng = OsRng; let msg = "It was many and many a year ago".as_bytes(); let Nk: u32 = 10; let T: u32 = 7; @@ -641,9 +641,8 @@ mod tests { sig_agg.init(comms.clone()).expect("aggregator init failed"); - let (nonces, sig_shares, key_ids) = - v2::test_helpers::sign(&msg, &mut signers, &mut rng); - if let Err(e) = sig_agg.sign(&msg, &nonces, &sig_shares, &key_ids) { + let (nonces, sig_shares, key_ids) = v2::test_helpers::sign(msg, &mut signers, &mut rng); + if let Err(e) = sig_agg.sign(msg, &nonces, &sig_shares, &key_ids) { panic!("Aggregator sign failed: {:?}", e); } }