From 1acb70ee70c74b63040c4d54d524ec08db2f030e Mon Sep 17 00:00:00 2001 From: ozankaymak Date: Thu, 29 Aug 2024 12:57:23 +0300 Subject: [PATCH] Apply clippy suggestions for all --- core/src/musig2.rs | 6 +++--- core/tests/common.rs | 21 ++++++++++----------- core/tests/musig2.rs | 38 +++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/core/src/musig2.rs b/core/src/musig2.rs index 434f2485..db923fb7 100644 --- a/core/src/musig2.rs +++ b/core/src/musig2.rs @@ -238,7 +238,7 @@ mod tests { message, ) .unwrap(); - musig2::verify_single(musig_agg_pubkey, &final_signature, message) + musig2::verify_single(musig_agg_pubkey, final_signature, message) .expect("Verification failed!"); println!("MuSig2 signature verified successfully!"); } @@ -486,7 +486,7 @@ mod tests { XOnlyPublicKey::from_musig2_pks(pks, merkle_root, true); // musig2::verify_single(musig_agg_pubkey, &final_signature, message) // .expect("Verification failed!"); - let _res = utils::SECP + utils::SECP .verify_schnorr( &secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(), &Message::from_digest(message), @@ -575,7 +575,7 @@ mod tests { .unwrap(); // musig2::verify_single(musig_agg_pubkey, &final_signature, message) // .expect("Verification failed!"); - let _res = utils::SECP + utils::SECP .verify_schnorr( &secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(), &Message::from_digest(message), diff --git a/core/tests/common.rs b/core/tests/common.rs index a65fcdd8..6a638b73 100644 --- a/core/tests/common.rs +++ b/core/tests/common.rs @@ -51,7 +51,7 @@ pub async fn run_single_deposit( let secret_key = secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()); - let signer_address = Actor::new(secret_key, config.network.clone()) + let signer_address = Actor::new(secret_key, config.network) .address .as_unchecked() .clone(); @@ -104,7 +104,7 @@ pub async fn run_single_deposit( &secp, *operator_internal_xonly_pk, None, - config.network.clone(), + config.network, ); let operator_funding_outpoint = rpc .send_to_address(&operator_address, 2 * BRIDGE_AMOUNT_SATS) @@ -136,7 +136,7 @@ pub async fn run_single_deposit( tracing::debug!("Now the verifiers sequence starts"); let mut slash_or_take_partial_sigs = Vec::new(); - for (_i, (client, ..)) in verifiers.iter().enumerate() { + for (client, ..) in verifiers.iter() { let (partial_sigs, _) = client .operator_kickoffs_generated_rpc( deposit_outpoint, @@ -159,14 +159,14 @@ pub async fn run_single_deposit( deposit_outpoint, kickoff_utxos[i].clone(), config.verifiers_public_keys.clone(), - config.operators_xonly_pks[i].clone(), + config.operators_xonly_pks[i], i, &agg_nonces[i + 1 + config.operators_xonly_pks.len()].clone(), slash_or_take_partial_sigs .iter() .map(|v| v.get(i).cloned().unwrap()) .collect::>(), - config.network.clone(), + config.network, )?; slash_or_take_sigs.push(secp256k1::schnorr::Signature::from_slice(&agg_sig)?); @@ -175,7 +175,7 @@ pub async fn run_single_deposit( // tracing::debug!("Slash or take sigs: {:#?}", slash_or_take_sigs); // call burn_txs_signed_rpc let mut operator_take_partial_sigs: Vec> = Vec::new(); - for (_i, (client, _, _)) in verifiers.iter().enumerate() { + for (client, _, _) in verifiers.iter() { let partial_sigs = client .burn_txs_signed_rpc(deposit_outpoint, vec![], slash_or_take_sigs.clone()) .await @@ -197,9 +197,9 @@ pub async fn run_single_deposit( &agg_nonces[i + 1].clone(), operator_take_partial_sigs .iter() - .map(|v| v[i].clone()) + .map(|v| v[i]) .collect(), - config.network.clone(), + config.network, )?; operator_take_sigs.push(secp256k1::schnorr::Signature::from_slice(&agg_sig)?); @@ -225,7 +225,7 @@ pub async fn run_single_deposit( config.verifiers_public_keys.clone(), &agg_nonces[0].clone(), move_tx_partial_sigs, - config.network.clone(), + config.network, )?; let move_tx_sig = secp256k1::schnorr::Signature::from_slice(&agg_move_tx_final_sig)?; @@ -243,8 +243,7 @@ pub async fn run_single_deposit( &nofn_xonly_pk, config.network, ); - let mut move_tx_witness_elements = Vec::new(); - move_tx_witness_elements.push(move_tx_sig.serialize().to_vec()); + let move_tx_witness_elements = vec![move_tx_sig.serialize().to_vec()]; handle_taproot_witness_new(&mut move_tx_handler, &move_tx_witness_elements, 0, Some(0))?; tracing::debug!("Move tx: {:#?}", move_tx_handler.tx); // tracing::debug!("Move tx_hex: {:?}", move_tx_handler.tx.raw_hex()); diff --git a/core/tests/musig2.rs b/core/tests/musig2.rs index 649a2a39..e66e4bc7 100644 --- a/core/tests/musig2.rs +++ b/core/tests/musig2.rs @@ -28,11 +28,11 @@ async fn test_musig2_key_spend() { let sks = config.all_verifiers_secret_keys.unwrap(); let kp_vec: Vec = sks .iter() - .map(|sk| Keypair::from_secret_key(&secp, &sk)) + .map(|sk| Keypair::from_secret_key(&secp, sk)) .collect(); let nonce_pair_vec: Vec = kp_vec .iter() - .map(|kp| nonce_pair(&kp, &mut secp256k1::rand::thread_rng())) + .map(|kp| nonce_pair(kp, &mut secp256k1::rand::thread_rng())) .collect(); let pks = kp_vec .iter() @@ -50,9 +50,9 @@ async fn test_musig2_key_spend() { let untweaked_xonly_pubkey: secp256k1::XOnlyPublicKey = secp256k1::XOnlyPublicKey::from_slice(&untweaked_pubkey.x_only_public_key().0.serialize()) .unwrap(); - let (to_address, _) = TransactionBuilder::create_taproot_address(&vec![], None, config.network); + let (to_address, _) = TransactionBuilder::create_taproot_address(&[], None, config.network); let (from_address, from_address_spend_info) = TransactionBuilder::create_taproot_address( - &vec![], + &[], Some(untweaked_xonly_pubkey), config.network, ); @@ -106,10 +106,10 @@ async fn test_musig2_key_spend() { let musig_agg_xonly_pubkey_wrapped = bitcoin::XOnlyPublicKey::from_slice(&musig_agg_xonly_pubkey.serialize()).unwrap(); - musig2::verify_single(musig_agg_pubkey, &final_signature, message) + musig2::verify_single(musig_agg_pubkey, final_signature, message) .expect("Verification failed!"); let schnorr_sig = secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(); - let res = secp + secp .verify_schnorr( &schnorr_sig, &Message::from_digest(message), @@ -117,8 +117,8 @@ async fn test_musig2_key_spend() { ) .unwrap(); println!("MuSig2 signature verified successfully!"); - println!("SECP Verification: {:?}", res); - tx_details.tx.input[0].witness.push(&final_signature); + println!("SECP Verified Successfully"); + tx_details.tx.input[0].witness.push(final_signature); let txid = rpc.send_raw_transaction(&tx_details.tx).unwrap(); println!("Transaction sent successfully! Txid: {}", txid); } @@ -132,11 +132,11 @@ async fn test_musig2_key_spend_with_script() { let sks = config.all_verifiers_secret_keys.unwrap(); let kp_vec: Vec = sks .iter() - .map(|sk| Keypair::from_secret_key(&secp, &sk)) + .map(|sk| Keypair::from_secret_key(&secp, sk)) .collect(); let nonce_pair_vec: Vec = kp_vec .iter() - .map(|kp| nonce_pair(&kp, &mut secp256k1::rand::thread_rng())) + .map(|kp| nonce_pair(kp, &mut secp256k1::rand::thread_rng())) .collect(); let pks = kp_vec .iter() @@ -156,7 +156,7 @@ async fn test_musig2_key_spend_with_script() { .unwrap(); let dummy_script = script::Builder::new().push_int(1).into_script(); let scripts: Vec = vec![dummy_script]; - let (to_address, _) = TransactionBuilder::create_taproot_address(&vec![], None, config.network); + let (to_address, _) = TransactionBuilder::create_taproot_address(&[], None, config.network); let (from_address, from_address_spend_info) = TransactionBuilder::create_taproot_address( &scripts, Some(untweaked_xonly_pubkey), @@ -211,10 +211,10 @@ async fn test_musig2_key_spend_with_script() { let musig_agg_xonly_pubkey_wrapped = bitcoin::XOnlyPublicKey::from_slice(&musig_agg_xonly_pubkey.serialize()).unwrap(); - musig2::verify_single(musig_agg_pubkey, &final_signature, message) + musig2::verify_single(musig_agg_pubkey, final_signature, message) .expect("Verification failed!"); let schnorr_sig = secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(); - let _res = secp + secp .verify_schnorr( &schnorr_sig, &Message::from_digest(message), @@ -223,7 +223,7 @@ async fn test_musig2_key_spend_with_script() { .unwrap(); // println!("MuSig2 signature verified successfully!"); // println!("SECP Verification: {:?}", res); - tx_details.tx.input[0].witness.push(&final_signature); + tx_details.tx.input[0].witness.push(final_signature); let _txid = rpc.send_raw_transaction(&tx_details.tx).unwrap(); // println!("Transaction sent successfully! Txid: {}", txid); } @@ -237,11 +237,11 @@ async fn test_musig2_script_spend() { let sks = config.all_verifiers_secret_keys.unwrap(); let kp_vec: Vec = sks .iter() - .map(|sk| Keypair::from_secret_key(&secp, &sk)) + .map(|sk| Keypair::from_secret_key(&secp, sk)) .collect(); let nonce_pair_vec: Vec = kp_vec .iter() - .map(|kp| nonce_pair(&kp, &mut secp256k1::rand::thread_rng())) + .map(|kp| nonce_pair(kp, &mut secp256k1::rand::thread_rng())) .collect(); let pks = kp_vec .iter() @@ -309,9 +309,9 @@ async fn test_musig2_script_spend() { let final_signature: [u8; 64] = aggregate_partial_signatures(pks.clone(), None, false, &agg_nonce, partial_sigs, message) .unwrap(); - musig2::verify_single(musig_agg_pubkey, &final_signature, message) + musig2::verify_single(musig_agg_pubkey, final_signature, message) .expect("Verification failed!"); - let res = utils::SECP + utils::SECP .verify_schnorr( &secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(), &Message::from_digest(message), @@ -319,7 +319,7 @@ async fn test_musig2_script_spend() { ) .unwrap(); println!("MuSig2 signature verified successfully!"); - println!("SECP Verification: {:?}", res); + println!("SECP Verified Successfully"); let schnorr_sig = secp256k1::schnorr::Signature::from_slice(&final_signature).unwrap(); let witness_elements = vec![schnorr_sig.as_ref()]; handle_taproot_witness_new(&mut tx_details, &witness_elements, 0, Some(0)).unwrap();