diff --git a/dash/src/bip152.rs b/dash/src/bip152.rs index ff3839868..ffb4949fe 100644 --- a/dash/src/bip152.rs +++ b/dash/src/bip152.rs @@ -504,7 +504,7 @@ mod test { fn test_getblocktx_panic_when_encoding_u64_max() { serialize(&BlockTransactionsRequest { block_hash: Hash::all_zeros(), - indexes: vec![core::u64::MAX], + indexes: vec![u64::MAX], }); } } diff --git a/dash/src/blockdata/fee_rate.rs b/dash/src/blockdata/fee_rate.rs index c781fdeb0..5514095e9 100644 --- a/dash/src/blockdata/fee_rate.rs +++ b/dash/src/blockdata/fee_rate.rs @@ -138,7 +138,6 @@ crate::parse::impl_parse_str_from_int_infallible!(FeeRate, u64, from_sat_per_kwu #[cfg(test)] mod tests { - use std::u64; use super::*; diff --git a/dash/src/blockdata/transaction/mod.rs b/dash/src/blockdata/transaction/mod.rs index c1fd3bb30..088790f90 100644 --- a/dash/src/blockdata/transaction/mod.rs +++ b/dash/src/blockdata/transaction/mod.rs @@ -468,7 +468,7 @@ impl Transaction { S: FnMut(&OutPoint) -> Option, F: Into, { - let tx = encode::serialize(&*self); + let tx = encode::serialize(self); let flags: u32 = flags.into(); for (idx, input) in self.input.iter().enumerate() { if let Some(output) = spent(&input.previous_output) { @@ -479,7 +479,7 @@ impl Transaction { flags, )?; } else { - return Err(script::Error::UnknownSpentOutput(input.previous_output.clone())); + return Err(script::Error::UnknownSpentOutput(input.previous_output)); } } Ok(()) diff --git a/dash/src/consensus/encode.rs b/dash/src/consensus/encode.rs index d2d31ff56..6adfc8f56 100644 --- a/dash/src/consensus/encode.rs +++ b/dash/src/consensus/encode.rs @@ -1438,7 +1438,7 @@ mod tests { .is_err() ); - let rand_io_err = Error::Io(io::Error::new(io::ErrorKind::Other, "")); + let rand_io_err = Error::Io(io::Error::other("")); // Check serialization that `if len > MAX_VEC_SIZE {return err}` isn't inclusive, // by making sure it fails with IO Error and not an `OversizedVectorAllocation` Error. @@ -1466,7 +1466,7 @@ mod tests { Vec: Decodable, T: fmt::Debug, { - let rand_io_err = Error::Io(io::Error::new(io::ErrorKind::Other, "")); + let rand_io_err = Error::Io(io::Error::other("")); let varint = VarInt((super::MAX_VEC_SIZE / mem::size_of::()) as u64); let err = deserialize::>(&serialize(&varint)).unwrap_err(); assert_eq!(discriminant(&err), discriminant(&rand_io_err)); @@ -1617,7 +1617,7 @@ mod tests { // Expect the write to succeed let bytes_written = result.expect("Failed to write"); // Calculate expected bytes written - let expected_bytes = (size + 7) / 8; + let expected_bytes = size.div_ceil(8); assert_eq!( bytes_written, expected_bytes, "Incorrect number of bytes written for bitset with size {}", diff --git a/dash/src/crypto/sighash.rs b/dash/src/crypto/sighash.rs index b6d14cdf6..a7a8761b0 100644 --- a/dash/src/crypto/sighash.rs +++ b/dash/src/crypto/sighash.rs @@ -1563,7 +1563,6 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KpsGiven { #[serde(with = "con_serde::With::")] raw_unsigned_tx: Transaction, @@ -1572,7 +1571,6 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KpsIntermediary { hash_prevouts: sha256::Hash, hash_outputs: sha256::Hash, @@ -1583,7 +1581,6 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KpsInputSpendingGiven { txin_index: usize, internal_privkey: SecretKey, @@ -1594,7 +1591,6 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KpsInputSpendingIntermediary { internal_pubkey: XOnlyPublicKey, tweak: TapTweakHash, @@ -1606,14 +1602,12 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KpsInputSpendingExpected { witness: Vec, } #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KpsInputSpending { given: KpsInputSpendingGiven, intermediary: KpsInputSpendingIntermediary, @@ -1623,7 +1617,6 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct KeyPathSpending { given: KpsGiven, intermediary: KpsIntermediary, @@ -1632,7 +1625,6 @@ mod tests { #[derive(serde::Deserialize)] #[serde(rename_all = "camelCase")] - struct TestData { version: u64, key_path_spending: Vec, diff --git a/dash/src/merkle_tree/block.rs b/dash/src/merkle_tree/block.rs index e4696ed63..ab43f385d 100644 --- a/dash/src/merkle_tree/block.rs +++ b/dash/src/merkle_tree/block.rs @@ -601,7 +601,7 @@ mod tests { let mut height = 1; let mut ntx = tx_count; while ntx > 1 { - ntx = (ntx + 1) / 2; + ntx = ntx.div_ceil(2); height += 1; } @@ -629,7 +629,7 @@ mod tests { // Verify PartialMerkleTree's size guarantees let n = min(tx_count, 1 + match_txid1.len() * height); - assert!(serialized.len() <= 10 + (258 * n + 7) / 8); + assert!(serialized.len() <= 10 + (258 * n).div_ceil(8)); // Deserialize into a tester copy let pmt2: PartialMerkleTree = diff --git a/dash/src/network/message.rs b/dash/src/network/message.rs index 7af31bbfd..cfa99c23a 100644 --- a/dash/src/network/message.rs +++ b/dash/src/network/message.rs @@ -994,7 +994,7 @@ mod test { // Verify match decoded.payload { NetworkMessage::SendDsq(wants_dsq) => { - assert_eq!(wants_dsq, true); + assert!(wants_dsq); } _ => panic!("Expected SendDsq message"), } @@ -1015,7 +1015,7 @@ mod test { // Verify match decoded.payload { NetworkMessage::SendDsq(wants_dsq) => { - assert_eq!(wants_dsq, false); + assert!(!wants_dsq); } _ => panic!("Expected SendDsq message"), } diff --git a/dash/src/pow.rs b/dash/src/pow.rs index 62f762cb5..3b7889a27 100644 --- a/dash/src/pow.rs +++ b/dash/src/pow.rs @@ -1490,7 +1490,7 @@ mod tests { let config = bincode::config::standard(); - let bin_encoded = bincode::encode_to_vec(&uint, config).unwrap(); + let bin_encoded = bincode::encode_to_vec(uint, config).unwrap(); let bin_decoded: U256 = bincode::decode_from_slice(&bin_encoded, config).unwrap().0; assert_eq!(bin_decoded, uint); }; diff --git a/dash/src/sml/masternode_list_engine/mod.rs b/dash/src/sml/masternode_list_engine/mod.rs index eea6d93fe..11a2a2e3d 100644 --- a/dash/src/sml/masternode_list_engine/mod.rs +++ b/dash/src/sml/masternode_list_engine/mod.rs @@ -1278,19 +1278,19 @@ mod tests { let block_container_bytes: &[u8] = include_bytes!("../../../tests/data/test_DML_diffs/block_container_2240504.dat"); let block_container: MasternodeListEngineBlockContainer = - bincode::decode_from_slice(&block_container_bytes, bincode::config::standard()) + bincode::decode_from_slice(block_container_bytes, bincode::config::standard()) .expect("expected to decode") .0; let mn_list_diffs_bytes: &[u8] = include_bytes!("../../../tests/data/test_DML_diffs/mnlistdiffs_2240504.dat"); let mn_list_diffs: BTreeMap<(CoreBlockHeight, CoreBlockHeight), MnListDiff> = - bincode::decode_from_slice(&mn_list_diffs_bytes, bincode::config::standard()) + bincode::decode_from_slice(mn_list_diffs_bytes, bincode::config::standard()) .expect("expected to decode") .0; let qr_info_bytes: &[u8] = include_bytes!("../../../tests/data/test_DML_diffs/qrinfo_2240504.dat"); let qr_info: QRInfo = - bincode::decode_from_slice(&qr_info_bytes, bincode::config::standard()) + bincode::decode_from_slice(qr_info_bytes, bincode::config::standard()) .expect("expected to decode") .0; @@ -1403,10 +1403,9 @@ mod tests { for (cycle_hash, quorums) in mn_list_engine.rotated_quorums_per_cycle.iter() { for (i, quorum) in quorums.iter().enumerate() { - mn_list_engine.validate_quorum(quorum).expect( - format!("expected to validate quorum {} in cycle hash {}", i, cycle_hash) - .as_str(), - ); + mn_list_engine.validate_quorum(quorum).unwrap_or_else(|_| { + panic!("expected to validate quorum {} in cycle hash {}", i, cycle_hash) + }); } } } diff --git a/dash/src/sml/quorum_entry/validation.rs b/dash/src/sml/quorum_entry/validation.rs index 05449902a..33738e66e 100644 --- a/dash/src/sml/quorum_entry/validation.rs +++ b/dash/src/sml/quorum_entry/validation.rs @@ -134,7 +134,7 @@ mod tests { #[test] fn test_real_operator_key_compatibility() { // Real operator public keys from mainnet quorum at height 2300832 - let real_keys = vec![ + let real_keys = [ hex!( "86e7ea34cc084da3ed0e90649ad444df0ca25d638164a596b4fbec9567bbcf3e635a8d8457107e7fe76326f3816e34d9" ), @@ -294,7 +294,7 @@ mod tests { println!("Verification with modern sig format: {:?}", result); // Try with reversed block hash (endianness) - let mut reversed_hash = block_hash.clone(); + let mut reversed_hash = block_hash; reversed_hash.reverse(); let result_reversed = sig.verify(&pk, &reversed_hash); println!("Verification with reversed block hash: {:?}", result_reversed); @@ -399,7 +399,7 @@ mod tests { for _ in 0..10 { let _ = verify_secure_basic_with_mode::( &operator_keys, - inner_sig.clone(), + inner_sig, msg, SerializationFormat::Modern, ); @@ -412,7 +412,7 @@ mod tests { for _ in 0..iterations { let _ = verify_secure_basic_with_mode::( &operator_keys, - inner_sig.clone(), + inner_sig, msg, SerializationFormat::Modern, ); diff --git a/hashes/Cargo.toml b/hashes/Cargo.toml index b0d24b182..1dfee3740 100644 --- a/hashes/Cargo.toml +++ b/hashes/Cargo.toml @@ -16,7 +16,7 @@ exclude = ["tests", "contrib"] default = ["std"] std = ["alloc", "internals/std"] alloc = ["internals/alloc"] -schemars = ["actual-schemars", "dyn-clone"] +schemars = ["actual-schemars"] serde-std = ["serde/std"] x11 = ["rs-x11-hash"] @@ -31,10 +31,7 @@ core2 = { version = "0.4.0", default-features = false, optional = true } # Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std". serde = { version = "1.0.219", default-features = false, optional = true } # Do NOT use this as a feature! Use the `schemars` feature instead. Can only be used with "std" enabled. -actual-schemars = { package = "schemars", version = "<=0.8.3", optional = true } -# Do NOT enable this dependency, this is just to pin dyn-clone (transitive dep from schemars) -# because 1.0.8 does not build with Rust 1.41.1 (because of useage of `Arc::as_ptr`). -dyn-clone = { version = "<=1.0.7", default-features = false, optional = true } +actual-schemars = { package = "schemars", version = "1.0", optional = true } secp256k1 = { default-features = false, features = ["hashes"], version= "0.30.0" } rs-x11-hash = { version = "0.1.8", optional = true } diff --git a/hashes/src/util.rs b/hashes/src/util.rs index 45e25b65c..412880265 100644 --- a/hashes/src/util.rs +++ b/hashes/src/util.rs @@ -583,19 +583,18 @@ macro_rules! hash_newtype_known_attrs { #[cfg(feature = "schemars")] pub mod json_hex_string { - use schemars::gen::SchemaGenerator; - use schemars::schema::{Schema, SchemaObject}; - use schemars::JsonSchema; + use schemars::SchemaGenerator; + use schemars::{Schema, json_schema}; macro_rules! define_custom_hex { ($name:ident, $len:expr) => { - pub fn $name(generator: &mut SchemaGenerator) -> Schema { - let mut schema: SchemaObject = ::json_schema(generator).into(); - schema.string = Some(Box::new(schemars::schema::StringValidation { - max_length: Some($len * 2), - min_length: Some($len * 2), - pattern: Some("[0-9a-fA-F]+".to_owned()), - })); - schema.into() + pub fn $name(_generator: &mut SchemaGenerator) -> Schema { + // In schemars 1.0, we can use the json_schema! macro to create schemas + json_schema!({ + "type": "string", + "minLength": $len * 2, + "maxLength": $len * 2, + "pattern": "^[0-9a-fA-F]+$" + }) } }; } diff --git a/key-wallet-ffi/include/key_wallet_ffi.h b/key-wallet-ffi/include/key_wallet_ffi.h index e9211f71f..9df10b15a 100644 --- a/key-wallet-ffi/include/key_wallet_ffi.h +++ b/key-wallet-ffi/include/key_wallet_ffi.h @@ -3789,16 +3789,30 @@ void wallet_manager_free_addresses(char **addresses, /* Encrypt a private key with BIP38 + + # Safety + + This function is unsafe because it dereferences raw pointers: + - `private_key` must be a valid, null-terminated C string + - `passphrase` must be a valid, null-terminated C string + - `error` must be a valid pointer to an FFIError or null */ char *bip38_encrypt_private_key(const char *private_key, const char *passphrase, - FFINetwork network, + FFINetwork _network, FFIError *error) ; /* Decrypt a BIP38 encrypted private key + + # Safety + + This function is unsafe because it dereferences raw pointers: + - `encrypted_key` must be a valid, null-terminated C string + - `passphrase` must be a valid, null-terminated C string + - `error` must be a valid pointer to an FFIError or null */ char *bip38_decrypt_private_key(const char *encrypted_key, diff --git a/key-wallet-ffi/src/account_collection.rs b/key-wallet-ffi/src/account_collection.rs index bbcf931ec..f8c7d61d5 100644 --- a/key-wallet-ffi/src/account_collection.rs +++ b/key-wallet-ffi/src/account_collection.rs @@ -1151,7 +1151,7 @@ mod tests { options.option_type = crate::types::FFIAccountCreationOptionType::AllAccounts; // Add provider operator keys account type - let special_types = vec![crate::types::FFIAccountType::ProviderOperatorKeys]; + let special_types = [crate::types::FFIAccountType::ProviderOperatorKeys]; options.special_account_types = special_types.as_ptr(); options.special_account_types_count = special_types.len(); @@ -1199,7 +1199,7 @@ mod tests { options.option_type = crate::types::FFIAccountCreationOptionType::AllAccounts; // Add provider platform keys account type - let special_types = vec![crate::types::FFIAccountType::ProviderPlatformKeys]; + let special_types = [crate::types::FFIAccountType::ProviderPlatformKeys]; options.special_account_types = special_types.as_ptr(); options.special_account_types_count = special_types.len(); @@ -1248,7 +1248,7 @@ mod tests { options.option_type = crate::types::FFIAccountCreationOptionType::AllAccounts; // Add various special accounts - let special_types = vec![ + let special_types = [ crate::types::FFIAccountType::ProviderVotingKeys, crate::types::FFIAccountType::ProviderOwnerKeys, crate::types::FFIAccountType::IdentityRegistration, @@ -1258,10 +1258,10 @@ mod tests { options.special_account_types_count = special_types.len(); // Configure standard accounts - store vectors in variables to keep them alive - let bip44_indices = vec![0, 4, 5, 8]; - let bip32_indices = vec![0]; - let coinjoin_indices = vec![0, 1]; - let topup_indices = vec![0, 1, 2]; + let bip44_indices = [0, 4, 5, 8]; + let bip32_indices = [0]; + let coinjoin_indices = [0, 1]; + let topup_indices = [0, 1, 2]; options.bip44_indices = bip44_indices.as_ptr(); options.bip44_count = bip44_indices.len(); @@ -1392,7 +1392,7 @@ mod tests { options.option_type = crate::types::FFIAccountCreationOptionType::AllAccounts; // Add various special accounts - let special_types = vec![ + let special_types = [ crate::types::FFIAccountType::ProviderVotingKeys, crate::types::FFIAccountType::ProviderOwnerKeys, crate::types::FFIAccountType::IdentityRegistration, @@ -1402,10 +1402,10 @@ mod tests { options.special_account_types_count = special_types.len(); // Configure standard accounts - let bip44_indices = vec![0, 4, 5, 8]; - let bip32_indices = vec![0]; - let coinjoin_indices = vec![0, 1]; - let topup_indices = vec![0, 1, 2]; + let bip44_indices = [0, 4, 5, 8]; + let bip32_indices = [0]; + let coinjoin_indices = [0, 1]; + let topup_indices = [0, 1, 2]; options.bip44_indices = bip44_indices.as_ptr(); options.bip44_count = bip44_indices.len(); diff --git a/key-wallet-ffi/src/account_tests.rs b/key-wallet-ffi/src/account_tests.rs index 93ebe7ec7..4282446f0 100644 --- a/key-wallet-ffi/src/account_tests.rs +++ b/key-wallet-ffi/src/account_tests.rs @@ -1,4 +1,5 @@ #[cfg(test)] +#[allow(clippy::module_inception)] mod tests { use super::super::*; use crate::error::{FFIError, FFIErrorCode}; diff --git a/key-wallet-ffi/src/bip38.rs b/key-wallet-ffi/src/bip38.rs index 744898fc3..1ff124531 100644 --- a/key-wallet-ffi/src/bip38.rs +++ b/key-wallet-ffi/src/bip38.rs @@ -1,6 +1,6 @@ //! BIP38 encryption support -use std::ffi::{CStr, CString}; +use std::ffi::CStr; use std::os::raw::c_char; use std::ptr; @@ -8,11 +8,18 @@ use crate::error::{FFIError, FFIErrorCode}; use crate::types::FFINetwork; /// Encrypt a private key with BIP38 +/// +/// # Safety +/// +/// This function is unsafe because it dereferences raw pointers: +/// - `private_key` must be a valid, null-terminated C string +/// - `passphrase` must be a valid, null-terminated C string +/// - `error` must be a valid pointer to an FFIError or null #[no_mangle] -pub extern "C" fn bip38_encrypt_private_key( +pub unsafe extern "C" fn bip38_encrypt_private_key( private_key: *const c_char, passphrase: *const c_char, - network: FFINetwork, + _network: FFINetwork, error: *mut FFIError, ) -> *mut c_char { #[cfg(feature = "bip38")] @@ -26,31 +33,27 @@ pub extern "C" fn bip38_encrypt_private_key( return ptr::null_mut(); } - let privkey_str = unsafe { - match CStr::from_ptr(private_key).to_str() { - Ok(s) => s, - Err(_) => { - FFIError::set_error( - error, - FFIErrorCode::InvalidInput, - "Invalid UTF-8 in private key".to_string(), - ); - return ptr::null_mut(); - } + let _privkey_str = match CStr::from_ptr(private_key).to_str() { + Ok(s) => s, + Err(_) => { + FFIError::set_error( + error, + FFIErrorCode::InvalidInput, + "Invalid UTF-8 in private key".to_string(), + ); + return ptr::null_mut(); } }; - let passphrase_str = unsafe { - match CStr::from_ptr(passphrase).to_str() { - Ok(s) => s, - Err(_) => { - FFIError::set_error( - error, - FFIErrorCode::InvalidInput, - "Invalid UTF-8 in passphrase".to_string(), - ); - return ptr::null_mut(); - } + let _passphrase_str = match CStr::from_ptr(passphrase).to_str() { + Ok(s) => s, + Err(_) => { + FFIError::set_error( + error, + FFIErrorCode::InvalidInput, + "Invalid UTF-8 in passphrase".to_string(), + ); + return ptr::null_mut(); } }; @@ -75,8 +78,15 @@ pub extern "C" fn bip38_encrypt_private_key( } /// Decrypt a BIP38 encrypted private key +/// +/// # Safety +/// +/// This function is unsafe because it dereferences raw pointers: +/// - `encrypted_key` must be a valid, null-terminated C string +/// - `passphrase` must be a valid, null-terminated C string +/// - `error` must be a valid pointer to an FFIError or null #[no_mangle] -pub extern "C" fn bip38_decrypt_private_key( +pub unsafe extern "C" fn bip38_decrypt_private_key( encrypted_key: *const c_char, passphrase: *const c_char, error: *mut FFIError, @@ -92,31 +102,27 @@ pub extern "C" fn bip38_decrypt_private_key( return ptr::null_mut(); } - let encrypted_str = unsafe { - match CStr::from_ptr(encrypted_key).to_str() { - Ok(s) => s, - Err(_) => { - FFIError::set_error( - error, - FFIErrorCode::InvalidInput, - "Invalid UTF-8 in encrypted key".to_string(), - ); - return ptr::null_mut(); - } + let _encrypted_str = match CStr::from_ptr(encrypted_key).to_str() { + Ok(s) => s, + Err(_) => { + FFIError::set_error( + error, + FFIErrorCode::InvalidInput, + "Invalid UTF-8 in encrypted key".to_string(), + ); + return ptr::null_mut(); } }; - let passphrase_str = unsafe { - match CStr::from_ptr(passphrase).to_str() { - Ok(s) => s, - Err(_) => { - FFIError::set_error( - error, - FFIErrorCode::InvalidInput, - "Invalid UTF-8 in passphrase".to_string(), - ); - return ptr::null_mut(); - } + let _passphrase_str = match CStr::from_ptr(passphrase).to_str() { + Ok(s) => s, + Err(_) => { + FFIError::set_error( + error, + FFIErrorCode::InvalidInput, + "Invalid UTF-8 in passphrase".to_string(), + ); + return ptr::null_mut(); } }; diff --git a/key-wallet-ffi/src/derivation_tests.rs b/key-wallet-ffi/src/derivation_tests.rs index 1a7c41841..e48cd2790 100644 --- a/key-wallet-ffi/src/derivation_tests.rs +++ b/key-wallet-ffi/src/derivation_tests.rs @@ -1,6 +1,7 @@ //! Tests for derivation path FFI functions #[cfg(test)] +#[allow(clippy::module_inception)] mod tests { use crate::derivation::*; use crate::error::{FFIError, FFIErrorCode}; diff --git a/key-wallet-ffi/src/keys_tests.rs b/key-wallet-ffi/src/keys_tests.rs index c279e548a..6ee7d68f3 100644 --- a/key-wallet-ffi/src/keys_tests.rs +++ b/key-wallet-ffi/src/keys_tests.rs @@ -1,6 +1,7 @@ //! Tests for key derivation FFI functions #[cfg(test)] +#[allow(clippy::module_inception)] mod tests { use crate::error::{FFIError, FFIErrorCode}; use crate::keys::*; diff --git a/key-wallet-ffi/src/managed_account.rs b/key-wallet-ffi/src/managed_account.rs index c991b3427..5cd4c9cf0 100644 --- a/key-wallet-ffi/src/managed_account.rs +++ b/key-wallet-ffi/src/managed_account.rs @@ -856,7 +856,7 @@ mod tests { let mut options = FFIWalletAccountCreationOptions::default_options(); options.option_type = FFIAccountCreationOptionType::BIP44AccountsOnly; - let bip44_indices = vec![0]; + let bip44_indices = [0]; options.bip44_indices = bip44_indices.as_ptr(); options.bip44_count = bip44_indices.len(); @@ -929,9 +929,9 @@ mod tests { let mut options = FFIWalletAccountCreationOptions::default_options(); options.option_type = FFIAccountCreationOptionType::AllAccounts; - let bip44_indices = vec![0, 1, 2]; - let bip32_indices = vec![0]; - let coinjoin_indices = vec![0]; + let bip44_indices = [0, 1, 2]; + let bip32_indices = [0]; + let coinjoin_indices = [0]; options.bip44_indices = bip44_indices.as_ptr(); options.bip44_count = bip44_indices.len(); @@ -1046,7 +1046,7 @@ mod tests { // Test get_is_watch_only let is_watch_only = managed_account_get_is_watch_only(account); - assert_eq!(is_watch_only, false); + assert!(!is_watch_only); // Test get_balance let mut balance_out = crate::types::FFIBalance { @@ -1094,7 +1094,7 @@ mod tests { assert_eq!(account_type, FFIAccountType::StandardBIP44); // Default type let is_watch_only = managed_account_get_is_watch_only(ptr::null()); - assert_eq!(is_watch_only, false); + assert!(!is_watch_only); let tx_count = managed_account_get_transaction_count(ptr::null()); assert_eq!(tx_count, 0); @@ -1261,7 +1261,7 @@ mod tests { // Create wallet with CoinJoin account let mut options = FFIWalletAccountCreationOptions::default_options(); options.option_type = FFIAccountCreationOptionType::SpecificAccounts; - let coinjoin_indices = vec![0]; + let coinjoin_indices = [0]; options.coinjoin_indices = coinjoin_indices.as_ptr(); options.coinjoin_count = coinjoin_indices.len(); diff --git a/key-wallet-ffi/src/managed_wallet.rs b/key-wallet-ffi/src/managed_wallet.rs index 9cf1475cf..31f4a474d 100644 --- a/key-wallet-ffi/src/managed_wallet.rs +++ b/key-wallet-ffi/src/managed_wallet.rs @@ -906,7 +906,7 @@ mod tests { // Create managed wallet info from the wallet let wallet_rust = unsafe { &(*wallet).wallet }; - let managed_info = ManagedWalletInfo::from_wallet(&wallet_rust); + let managed_info = ManagedWalletInfo::from_wallet(wallet_rust); let mut ffi_managed = FFIManagedWalletInfo::new(managed_info); // Test get_next_receive_address with valid pointers @@ -995,7 +995,7 @@ mod tests { // We need to work with the existing wallet structure // Create managed wallet info from the existing wallet - let mut managed_info = ManagedWalletInfo::from_wallet(&wallet_arc); + let mut managed_info = ManagedWalletInfo::from_wallet(wallet_arc); let network = key_wallet::Network::Testnet; @@ -1177,7 +1177,7 @@ mod tests { // Create managed wallet info let wallet_arc = unsafe { &(*wallet_ptr).wallet }; - let mut managed_info = ManagedWalletInfo::from_wallet(&wallet_arc); + let mut managed_info = ManagedWalletInfo::from_wallet(wallet_arc); // Set some test balance values managed_info.balance = WalletBalance { diff --git a/key-wallet-ffi/src/managed_wallet_tests.rs b/key-wallet-ffi/src/managed_wallet_tests.rs index b9064da93..7c7ba8d83 100644 --- a/key-wallet-ffi/src/managed_wallet_tests.rs +++ b/key-wallet-ffi/src/managed_wallet_tests.rs @@ -360,7 +360,7 @@ mod tests { }; // Create invalid UTF-8 string - let invalid_utf8 = vec![0xFF, 0xFE, 0xFD, 0x00]; // Invalid UTF-8 bytes with null terminator + let invalid_utf8 = [0xFF, 0xFE, 0xFD, 0x00]; // Invalid UTF-8 bytes with null terminator let success = unsafe { managed_wallet_mark_address_used( managed_wallet, diff --git a/key-wallet-ffi/src/mnemonic_tests.rs b/key-wallet-ffi/src/mnemonic_tests.rs index b53fa7ce6..466d55cc8 100644 --- a/key-wallet-ffi/src/mnemonic_tests.rs +++ b/key-wallet-ffi/src/mnemonic_tests.rs @@ -1,6 +1,7 @@ //! Unit tests for mnemonic FFI module #[cfg(test)] +#[allow(clippy::module_inception)] mod tests { use crate::error::{FFIError, FFIErrorCode}; use crate::mnemonic; @@ -380,7 +381,7 @@ mod tests { let mut error = FFIError::success(); // Create invalid UTF-8 string - let invalid_utf8 = vec![0xFF, 0xFE, 0xFD, 0x00]; + let invalid_utf8 = [0xFF, 0xFE, 0xFD, 0x00]; let count = unsafe { mnemonic::mnemonic_word_count( invalid_utf8.as_ptr() as *const std::os::raw::c_char, @@ -467,7 +468,7 @@ mod tests { let mut seed_len = 0usize; // Test invalid UTF-8 in mnemonic - let invalid_utf8 = vec![0xFF, 0xFE, 0xFD, 0x00]; + let invalid_utf8 = [0xFF, 0xFE, 0xFD, 0x00]; let success = unsafe { mnemonic::mnemonic_to_seed( invalid_utf8.as_ptr() as *const std::os::raw::c_char, @@ -500,7 +501,7 @@ mod tests { let mut error = FFIError::success(); // Create invalid UTF-8 string - let invalid_utf8 = vec![0xFF, 0xFE, 0xFD, 0x00]; + let invalid_utf8 = [0xFF, 0xFE, 0xFD, 0x00]; let is_valid = unsafe { mnemonic::mnemonic_validate( invalid_utf8.as_ptr() as *const std::os::raw::c_char, diff --git a/key-wallet-ffi/src/transaction_tests.rs b/key-wallet-ffi/src/transaction_tests.rs index 770ea1da5..6029cbb05 100644 --- a/key-wallet-ffi/src/transaction_tests.rs +++ b/key-wallet-ffi/src/transaction_tests.rs @@ -1,4 +1,5 @@ #[cfg(test)] +#[allow(clippy::module_inception)] mod transaction_tests { use super::super::*; use crate::error::{FFIError, FFIErrorCode}; @@ -89,7 +90,7 @@ mod transaction_tests { fn test_sign_transaction_with_null_wallet() { let mut error = FFIError::success(); - let tx_bytes = vec![0u8; 100]; + let tx_bytes = [0u8; 100]; let mut signed_tx_out: *mut u8 = ptr::null_mut(); let mut signed_len_out: usize = 0; @@ -225,7 +226,7 @@ mod transaction_tests { ) }; - let tx_bytes = vec![0u8; 100]; + let tx_bytes = [0u8; 100]; let mut signed_tx_out: *mut u8 = ptr::null_mut(); let mut signed_len_out: usize = 0; diff --git a/key-wallet-ffi/src/utils_tests.rs b/key-wallet-ffi/src/utils_tests.rs index 4a0eb6c01..74d4a1f10 100644 --- a/key-wallet-ffi/src/utils_tests.rs +++ b/key-wallet-ffi/src/utils_tests.rs @@ -1,6 +1,7 @@ //! Unit tests for utils FFI module #[cfg(test)] +#[allow(clippy::module_inception)] mod util_tests { use crate::utils; use std::ffi::CString; diff --git a/key-wallet-ffi/src/utxo_tests.rs b/key-wallet-ffi/src/utxo_tests.rs index 95fe21cec..16ecc0877 100644 --- a/key-wallet-ffi/src/utxo_tests.rs +++ b/key-wallet-ffi/src/utxo_tests.rs @@ -655,32 +655,14 @@ mod utxo_tests { #[test] fn test_utxo_array_free_with_mixed_content() { // Create UTXOs with different properties - let mut utxos = Vec::new(); - - // UTXO with normal values - utxos.push(FFIUTXO::new( - [0x01u8; 32], - 0, - 10000, - "address1".to_string(), - vec![0x76, 0xa9], - 100, - 10, - )); - - // UTXO with empty script - utxos.push(FFIUTXO::new([0x02u8; 32], 1, 20000, "address2".to_string(), vec![], 200, 20)); - - // UTXO with large script - utxos.push(FFIUTXO::new( - [0x03u8; 32], - 2, - 30000, - "address3".to_string(), - vec![0xAB; 500], - 300, - 30, - )); + let utxos = vec![ + // UTXO with normal values + FFIUTXO::new([0x01u8; 32], 0, 10000, "address1".to_string(), vec![0x76, 0xa9], 100, 10), + // UTXO with empty script + FFIUTXO::new([0x02u8; 32], 1, 20000, "address2".to_string(), vec![], 200, 20), + // UTXO with large script + FFIUTXO::new([0x03u8; 32], 2, 30000, "address3".to_string(), vec![0xAB; 500], 300, 30), + ]; let count = utxos.len(); let mut boxed_utxos = utxos.into_boxed_slice(); diff --git a/key-wallet-ffi/src/wallet_manager_serialization_tests.rs b/key-wallet-ffi/src/wallet_manager_serialization_tests.rs index 2df30bf94..7bb089046 100644 --- a/key-wallet-ffi/src/wallet_manager_serialization_tests.rs +++ b/key-wallet-ffi/src/wallet_manager_serialization_tests.rs @@ -365,7 +365,7 @@ mod tests { let passphrase = CString::new("").unwrap(); // Create custom account options (BIP44 accounts only) - let bip44_indices = vec![0u32, 1u32, 2u32]; + let bip44_indices = [0u32, 1u32, 2u32]; let account_options = FFIWalletAccountCreationOptions { option_type: FFIAccountCreationOptionType::BIP44AccountsOnly, diff --git a/key-wallet-ffi/src/wallet_manager_tests.rs b/key-wallet-ffi/src/wallet_manager_tests.rs index e22789ffd..1aa1f3eac 100644 --- a/key-wallet-ffi/src/wallet_manager_tests.rs +++ b/key-wallet-ffi/src/wallet_manager_tests.rs @@ -1,6 +1,7 @@ //! Unit tests for wallet_manager FFI module #[cfg(test)] +#[allow(clippy::module_inception)] mod tests { use crate::error::{FFIError, FFIErrorCode}; use crate::types::FFINetwork; @@ -537,8 +538,8 @@ mod tests { let wallet_count = 3; let mnemonics = [TEST_MNEMONIC, TEST_MNEMONIC_2, TEST_MNEMONIC_3]; unsafe { - for i in 0..wallet_count { - let mnemonic = CString::new(mnemonics[i]).unwrap(); + for mnemonic_str in &mnemonics[..wallet_count] { + let mnemonic = CString::new(*mnemonic_str).unwrap(); let success = wallet_manager::wallet_manager_add_wallet_from_mnemonic( manager, @@ -998,7 +999,7 @@ mod tests { assert_eq!(unsafe { (*error).code }, FFIErrorCode::InvalidInput); // Test with invalid wallet ID (all zeros which won't match any wallet) - let invalid_wallet_id = vec![0u8; 32]; + let invalid_wallet_id = [0u8; 32]; let success = unsafe { wallet_manager::wallet_manager_get_wallet_balance( manager, @@ -1043,7 +1044,7 @@ mod tests { // Create a sample transaction bytes (this is a minimal valid transaction structure) // This is a simplified transaction for testing - in real use you'd have actual transaction data - let tx_bytes = vec![ + let tx_bytes = [ 0x02, 0x00, 0x00, 0x00, // version 0x00, // input count 0x00, // output count @@ -1164,7 +1165,7 @@ mod tests { assert_eq!(unsafe { (*error).code }, FFIErrorCode::InvalidInput); // Test with invalid transaction bytes - let invalid_tx = vec![0xFF, 0xFF, 0xFF]; + let invalid_tx = [0xFF, 0xFF, 0xFF]; let processed = unsafe { wallet_manager::wallet_manager_process_transaction( manager, @@ -1246,7 +1247,7 @@ mod tests { assert_eq!(unsafe { (*error).code }, FFIErrorCode::Success); // Test with invalid wallet ID (all zeros) - let invalid_wallet_id = vec![0u8; 32]; + let invalid_wallet_id = [0u8; 32]; let wallet = unsafe { wallet_manager::wallet_manager_get_wallet(manager, invalid_wallet_id.as_ptr(), error) diff --git a/key-wallet-ffi/tests/integration_test.rs b/key-wallet-ffi/tests/integration_test.rs index c114bb6ae..3c64adc08 100644 --- a/key-wallet-ffi/tests/integration_test.rs +++ b/key-wallet-ffi/tests/integration_test.rs @@ -226,7 +226,7 @@ fn test_error_handling() { assert_eq!(unsafe { (*error).code }, FFIErrorCode::InvalidInput); // 3. Invalid seed size - let invalid_seed = vec![0u8; 10]; // Too small + let invalid_seed = [0u8; 10]; // Too small let wallet = unsafe { key_wallet_ffi::wallet::wallet_create_from_seed( invalid_seed.as_ptr(), diff --git a/key-wallet-ffi/tests/test_addr_checksum.rs b/key-wallet-ffi/tests/test_addr_checksum.rs index dc6649651..4b5c9fb85 100644 --- a/key-wallet-ffi/tests/test_addr_checksum.rs +++ b/key-wallet-ffi/tests/test_addr_checksum.rs @@ -9,7 +9,7 @@ fn test_address_checksum() { match base58::decode_check(test_addr) { Ok(data) => { println!("Base58 decode successful, {} bytes", data.len()); - if data.len() > 0 { + if !data.is_empty() { println!("Version byte: 0x{:02x}", data[0]); } } diff --git a/key-wallet-ffi/tests/test_addr_simple.rs b/key-wallet-ffi/tests/test_addr_simple.rs index 729267485..cff2538e1 100644 --- a/key-wallet-ffi/tests/test_addr_simple.rs +++ b/key-wallet-ffi/tests/test_addr_simple.rs @@ -7,7 +7,7 @@ fn test_address_simple() { let error = &mut error as *mut FFIError; // Create a wallet to get a valid address - let seed = vec![0x42u8; 64]; + let seed = [0x42u8; 64]; let wallet = unsafe { key_wallet_ffi::wallet::wallet_create_from_seed( seed.as_ptr(), diff --git a/key-wallet-manager/tests/integration_test.rs b/key-wallet-manager/tests/integration_test.rs index 4d4c91bc4..af4881af5 100644 --- a/key-wallet-manager/tests/integration_test.rs +++ b/key-wallet-manager/tests/integration_test.rs @@ -114,10 +114,7 @@ fn test_address_generation() { // Same check for change address if let Err(ref e) = change { match e { - WalletError::InvalidNetwork => { - // This is expected given the current implementation - return; - } + WalletError::InvalidNetwork => {} _ => panic!("Unexpected error: {:?}", e), } } diff --git a/key-wallet/src/account/account_collection_test.rs b/key-wallet/src/account/account_collection_test.rs index a47cf8c36..dead953e0 100644 --- a/key-wallet/src/account/account_collection_test.rs +++ b/key-wallet/src/account/account_collection_test.rs @@ -1,6 +1,7 @@ //! Tests for AccountCollection with different account types #[cfg(test)] +#[allow(clippy::module_inception)] mod tests { use crate::account::{ Account, AccountCollection, AccountType, BLSAccount, EdDSAAccount, StandardAccountType, diff --git a/key-wallet/src/account/serialization.rs b/key-wallet/src/account/serialization.rs index 37b75bd91..493a6b198 100644 --- a/key-wallet/src/account/serialization.rs +++ b/key-wallet/src/account/serialization.rs @@ -96,7 +96,7 @@ mod tests { index: 0, standard_account_type: StandardAccountType::BIP44Account, }, - public_key_bytes.try_into().expect("Failed to convert BLS public key bytes to array"), + public_key_bytes, Network::Testnet, ) .expect("Failed to create BLS account from public key bytes"); diff --git a/key-wallet/src/bip32.rs b/key-wallet/src/bip32.rs index cfbd59715..ab13df77b 100644 --- a/key-wallet/src/bip32.rs +++ b/key-wallet/src/bip32.rs @@ -2734,14 +2734,14 @@ mod tests { // Test to_priv() method let priv_key = ext_priv.to_priv(); - assert_eq!(priv_key.compressed, true); + assert!(priv_key.compressed); assert_eq!(priv_key.network, dashcore::Network::Testnet); assert_eq!(priv_key.inner, ext_priv.private_key); // Test to_pub() method let ext_pub = ExtendedPubKey::from_priv(&secp, &ext_priv); let pub_key = ext_pub.to_pub(); - assert_eq!(pub_key.compressed, true); + assert!(pub_key.compressed); assert_eq!(pub_key.inner, ext_pub.public_key); // Verify the keys match diff --git a/key-wallet/src/derivation_slip10.rs b/key-wallet/src/derivation_slip10.rs index d267cabeb..cf43fd166 100644 --- a/key-wallet/src/derivation_slip10.rs +++ b/key-wallet/src/derivation_slip10.rs @@ -609,7 +609,7 @@ mod test { fn case1_m() { assert_eq!( "2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7", - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!()) + derive_ed25519_private_key_hex(CASE_1_SEED, &[]) ); } @@ -617,7 +617,7 @@ mod test { fn case1_m_0h() { assert_eq!( "68e0fe46dfb67e368c75379acec591dad19df3cde26e63b93a8e704f1dade7a3", - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[0]) ); } @@ -625,7 +625,7 @@ mod test { fn case1_m_0h_1h() { assert_eq!( "b1d0bad404bf35da785a64ca1ac54b2617211d2777696fbffaf208f746ae84f2", - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0, 1)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[0, 1]) ); } @@ -633,7 +633,7 @@ mod test { fn case1_m_0h_1h_2h() { assert_eq!( "92a5b23c0b8a99e37d07df3fb9966917f5d06e02ddbd909c7e184371463e9fc9", - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0, 1, 2)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[0, 1, 2]) ); } @@ -641,7 +641,7 @@ mod test { fn case1_m_0h_1h_2h_2h() { assert_eq!( "30d1dc7e5fc04c31219ab25a27ae00b50f6fd66622f6e9c913253d6511d1e662", - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0, 1, 2, 2)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[0, 1, 2, 2]) ); } @@ -649,23 +649,23 @@ mod test { fn case1_m_0h_1h_2h_1000000000h() { assert_eq!( "8f94d394a8e8fd6b1bc2f3f49f5c47e385281d5c17e65324b0f62483e37e8793", - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0, 1, 2, 2, 1000000000)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[0, 1, 2, 2, 1000000000]) ); } #[test] fn case1_m_0h_already_hardened() { assert_eq!( - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0)), - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0x80000000)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[0]), + derive_ed25519_private_key_hex(CASE_1_SEED, &[0x80000000]) ); } #[test] fn case1_m_0h_1h_already_hardened() { assert_eq!( - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(1)), - derive_ed25519_private_key_hex(CASE_1_SEED, &vec!(0x80000001)) + derive_ed25519_private_key_hex(CASE_1_SEED, &[1]), + derive_ed25519_private_key_hex(CASE_1_SEED, &[0x80000001]) ); } @@ -675,7 +675,7 @@ mod test { fn case2_m() { assert_eq!( "171cb88b1b3c1db25add599712e36245d75bc65a1a5c9e18d76f9f2b1eab4012", - derive_ed25519_private_key_hex(CASE_2_SEED, &vec!()) + derive_ed25519_private_key_hex(CASE_2_SEED, &[]) ); } @@ -683,7 +683,7 @@ mod test { fn case2_m_0h() { assert_eq!( "1559eb2bbec5790b0c65d8693e4d0875b1747f4970ae8b650486ed7470845635", - derive_ed25519_private_key_hex(CASE_2_SEED, &vec!(0)) + derive_ed25519_private_key_hex(CASE_2_SEED, &[0]) ); } @@ -691,7 +691,7 @@ mod test { fn case2_m_0h_2147483647h() { assert_eq!( "ea4f5bfe8694d8bb74b7b59404632fd5968b774ed545e810de9c32a4fb4192f4", - derive_ed25519_private_key_hex(CASE_2_SEED, &vec!(0, 2147483647)) + derive_ed25519_private_key_hex(CASE_2_SEED, &[0, 2147483647]) ); } @@ -699,7 +699,7 @@ mod test { fn case2_m_0h_2147483647h_1h() { assert_eq!( "3757c7577170179c7868353ada796c839135b3d30554bbb74a4b1e4a5a58505c", - derive_ed25519_private_key_hex(CASE_2_SEED, &vec!(0, 2147483647, 1)) + derive_ed25519_private_key_hex(CASE_2_SEED, &[0, 2147483647, 1]) ); } @@ -707,7 +707,7 @@ mod test { fn case2_m_0h_2147483647h_1h_2147483646h() { assert_eq!( "5837736c89570de861ebc173b1086da4f505d4adb387c6a1b1342d5e4ac9ec72", - derive_ed25519_private_key_hex(CASE_2_SEED, &vec!(0, 2147483647, 1, 2147483646)) + derive_ed25519_private_key_hex(CASE_2_SEED, &[0, 2147483647, 1, 2147483646]) ); } @@ -715,7 +715,7 @@ mod test { fn case2_m_0h_2147483647h_1h_2147483646h_2h() { assert_eq!( "551d333177df541ad876a60ea71f00447931c0a9da16f227c11ea080d7391b8d", - derive_ed25519_private_key_hex(CASE_2_SEED, &vec!(0, 2147483647, 1, 2147483646, 2)) + derive_ed25519_private_key_hex(CASE_2_SEED, &[0, 2147483647, 1, 2147483646, 2]) ); } diff --git a/key-wallet/src/psbt/mod.rs b/key-wallet/src/psbt/mod.rs index 39335424f..48519cfdd 100644 --- a/key-wallet/src/psbt/mod.rs +++ b/key-wallet/src/psbt/mod.rs @@ -1174,7 +1174,6 @@ mod tests { PsbtParseError::PsbtEncoding(err) => err, PsbtParseError::Base64Encoding(_) => panic!("PSBT Base64 decoding failed") }) - .map_err(Error::from) .unwrap(); } diff --git a/key-wallet/src/tests/account_tests.rs b/key-wallet/src/tests/account_tests.rs index fec274a24..baa754996 100644 --- a/key-wallet/src/tests/account_tests.rs +++ b/key-wallet/src/tests/account_tests.rs @@ -21,8 +21,7 @@ fn create_test_mnemonic() -> Mnemonic { fn create_test_extended_priv_key(network: Network) -> ExtendedPrivKey { let mnemonic = create_test_mnemonic(); let seed = mnemonic.to_seed(""); - let master = ExtendedPrivKey::new_master(network.into(), &seed).unwrap(); - master + ExtendedPrivKey::new_master(network, &seed).unwrap() } #[test] @@ -43,7 +42,7 @@ fn test_bip44_account_creation() { let account = Account::from_xpriv( Some([0u8; 32]), // wallet_id - account_type.clone(), + account_type, account_key, network, ) @@ -83,8 +82,7 @@ fn test_bip32_account_creation() { let account_key = hd_wallet.derive(&derivation_path).unwrap(); let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network) - .unwrap(); + Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account properties match &account.account_type { @@ -119,8 +117,7 @@ fn test_coinjoin_account_creation() { let account_key = hd_wallet.derive(&derivation_path).unwrap(); let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network) - .unwrap(); + Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account properties match &account.account_type { @@ -148,8 +145,7 @@ fn test_identity_registration_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::IdentityRegistration)); @@ -174,8 +170,7 @@ fn test_identity_topup_account() { let account_key = hd_wallet.derive(&derivation_path).unwrap(); let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network) - .unwrap(); + Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account properties match &account.account_type { @@ -203,8 +198,7 @@ fn test_identity_topup_not_bound_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::IdentityTopUpNotBoundToIdentity)); @@ -224,8 +218,7 @@ fn test_identity_invitation_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::IdentityInvitation)); @@ -245,8 +238,7 @@ fn test_provider_voting_keys_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::ProviderVotingKeys)); @@ -266,8 +258,7 @@ fn test_provider_owner_keys_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::ProviderOwnerKeys)); @@ -287,8 +278,7 @@ fn test_provider_operator_keys_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::ProviderOperatorKeys)); @@ -308,8 +298,7 @@ fn test_provider_platform_keys_account() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify account type assert!(matches!(account.account_type, AccountType::ProviderPlatformKeys)); @@ -332,8 +321,7 @@ fn test_account_extended_key_generation() { let derivation_path = account_type.derivation_path(network).unwrap(); let account_key = hd_wallet.derive(&derivation_path).unwrap(); - let account = - Account::from_xpriv(Some([0u8; 32]), account_type, account_key.clone(), network).unwrap(); + let account = Account::from_xpriv(Some([0u8; 32]), account_type, account_key, network).unwrap(); // Verify extended public key can be derived let xpub = account.extended_public_key(); @@ -359,8 +347,7 @@ fn test_watch_only_account_creation() { standard_account_type: StandardAccountType::BIP44Account, }; - let account = - Account::from_xpub(Some([0u8; 32]), account_type.clone(), xpub.clone(), network).unwrap(); + let account = Account::from_xpub(Some([0u8; 32]), account_type, xpub, network).unwrap(); // Verify it's watch-only assert!(account.is_watch_only); @@ -410,7 +397,7 @@ fn test_account_network_consistency() { let address_xpub = account.account_xpub.derive_pub(&secp, &receive_path).unwrap(); let pubkey = dashcore::PublicKey::from_slice(&address_xpub.public_key.serialize()).unwrap(); - let address = dashcore::Address::p2pkh(&pubkey, network.into()); + let address = dashcore::Address::p2pkh(&pubkey, network); // Verify the address is for the correct network assert!( @@ -421,8 +408,7 @@ fn test_account_network_consistency() { // Test creating account with different network let dash_mainnet = Network::Dash; let mainnet_account = - Account::from_xpriv(Some([0u8; 32]), account_type.clone(), account_key, dash_mainnet) - .unwrap(); + Account::from_xpriv(Some([0u8; 32]), account_type, account_key, dash_mainnet).unwrap(); // Verify the mainnet account has the correct network assert_eq!(mainnet_account.network, dash_mainnet); diff --git a/key-wallet/src/tests/edge_case_tests.rs b/key-wallet/src/tests/edge_case_tests.rs index f45dec43e..acc312e43 100644 --- a/key-wallet/src/tests/edge_case_tests.rs +++ b/key-wallet/src/tests/edge_case_tests.rs @@ -30,7 +30,7 @@ fn test_account_index_overflow() { #[test] fn test_invalid_derivation_paths() { // Test various invalid derivation path scenarios - let _test_cases = vec![ + let _test_cases = [ "", // Empty path "m", // Just master "m/", // Trailing slash diff --git a/key-wallet/src/tests/immature_transaction_tests.rs b/key-wallet/src/tests/immature_transaction_tests.rs index 91c8c1b7a..dc8921de6 100644 --- a/key-wallet/src/tests/immature_transaction_tests.rs +++ b/key-wallet/src/tests/immature_transaction_tests.rs @@ -211,7 +211,7 @@ fn test_immature_transaction_ordering() { let block_hash = BlockHash::from_slice(&[0u8; 32]).unwrap(); // Add transactions in random order with different maturity heights - let heights = vec![100, 0, 200, 50]; + let heights = [100, 0, 200, 50]; let mut txids = Vec::new(); for (i, height) in heights.iter().enumerate() { diff --git a/key-wallet/src/tests/special_transaction_tests.rs b/key-wallet/src/tests/special_transaction_tests.rs index 567f02d55..d88d7bc5a 100644 --- a/key-wallet/src/tests/special_transaction_tests.rs +++ b/key-wallet/src/tests/special_transaction_tests.rs @@ -16,6 +16,7 @@ use std::net::SocketAddr; /// Special transaction types in Dash #[derive(Debug, Clone, Copy, PartialEq)] +#[allow(clippy::enum_variant_names)] enum SpecialTransactionType { ProviderRegistration = 1, // ProRegTx ProviderUpdate = 2, // ProUpServTx diff --git a/key-wallet/src/tests/transaction_tests.rs b/key-wallet/src/tests/transaction_tests.rs index 5cde50e42..d930818a5 100644 --- a/key-wallet/src/tests/transaction_tests.rs +++ b/key-wallet/src/tests/transaction_tests.rs @@ -63,10 +63,8 @@ fn test_coinbase_detection() { use crate::Network; // Create a test address - let address = Address::p2pkh( - &dashcore::PublicKey::from_slice(&[0x02; 33]).unwrap(), - Network::Testnet.into(), - ); + let address = + Address::p2pkh(&dashcore::PublicKey::from_slice(&[0x02; 33]).unwrap(), Network::Testnet); // Create a coinbase transaction let tx = create_coinbase_transaction(&address, 100000); diff --git a/key-wallet/src/tests/utxo_tests.rs b/key-wallet/src/tests/utxo_tests.rs index b6bda7ede..b0aa411da 100644 --- a/key-wallet/src/tests/utxo_tests.rs +++ b/key-wallet/src/tests/utxo_tests.rs @@ -9,8 +9,8 @@ use dashcore::{Address, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid}; use std::collections::{BTreeMap, HashMap}; /// Helper to create a test UTXO -fn create_test_utxo(txid: Txid, vout: u32, value: u64, height: Option) -> UTXO { - UTXO { +fn create_test_utxo(txid: Txid, vout: u32, value: u64, height: Option) -> Utxo { + Utxo { outpoint: OutPoint { txid, vout, @@ -60,7 +60,7 @@ fn test_utxo_creation_from_transaction() { // Create UTXOs from transaction outputs let mut utxos = Vec::new(); for (vout, output) in tx.output.iter().enumerate() { - let utxo = UTXO { + let utxo = Utxo { outpoint: OutPoint { txid, vout: vout as u32, @@ -321,7 +321,7 @@ fn test_utxo_dust_filtering() { mod mock { use super::*; - pub struct UTXO { + pub struct Utxo { pub outpoint: OutPoint, pub value: u64, pub script_pubkey: ScriptBuf, @@ -335,7 +335,7 @@ mod mock { } pub struct UTXOCollection { - utxos: HashMap, + utxos: HashMap, } impl UTXOCollection { @@ -345,15 +345,15 @@ mod mock { } } - pub fn add(&mut self, utxo: UTXO) { - self.utxos.insert(utxo.outpoint.clone(), utxo); + pub fn add(&mut self, utxo: Utxo) { + self.utxos.insert(utxo.outpoint, utxo); } - pub fn remove(&mut self, outpoint: &OutPoint) -> Option { + pub fn remove(&mut self, outpoint: &OutPoint) -> Option { self.utxos.remove(outpoint) } - pub fn spend(&mut self, outpoint: &OutPoint) -> Option { + pub fn spend(&mut self, outpoint: &OutPoint) -> Option { self.remove(outpoint) } @@ -397,7 +397,7 @@ mod mock { } } - pub fn select_utxos(&self, target: u64, _fee_per_input: u64) -> Option<(Vec, u64)> { + pub fn select_utxos(&self, target: u64, _fee_per_input: u64) -> Option<(Vec, u64)> { let mut selected = Vec::new(); let mut total = 0u64; @@ -424,7 +424,7 @@ mod mock { self.utxos.values().filter(|u| !u.is_change).map(|u| u.value).sum() } - pub fn get_non_dust_utxos(&self, dust_limit: u64) -> Vec<&UTXO> { + pub fn get_non_dust_utxos(&self, dust_limit: u64) -> Vec<&Utxo> { self.utxos.values().filter(|u| u.value >= dust_limit).collect() } @@ -439,10 +439,10 @@ mod mock { } } - impl Clone for UTXO { + impl Clone for Utxo { fn clone(&self) -> Self { Self { - outpoint: self.outpoint.clone(), + outpoint: self.outpoint, value: self.value, script_pubkey: self.script_pubkey.clone(), address: self.address.clone(), @@ -458,4 +458,4 @@ mod mock { } // Use the mock structures for testing -use mock::{UTXOCollection, UTXO}; +use mock::{UTXOCollection, Utxo}; diff --git a/key-wallet/src/tests/wallet_tests.rs b/key-wallet/src/tests/wallet_tests.rs index 56ff8246f..0f678c7fa 100644 --- a/key-wallet/src/tests/wallet_tests.rs +++ b/key-wallet/src/tests/wallet_tests.rs @@ -68,7 +68,7 @@ fn test_wallet_creation_from_seed() { let seed = Seed::new([0x42; 64]); let wallet = Wallet::from_seed( - seed.clone(), + seed, &[Network::Testnet], crate::wallet::initialization::WalletAccountCreationOptions::Default, ) @@ -100,7 +100,7 @@ fn test_wallet_creation_from_extended_key() { let master_key = root_key.to_extended_priv_key(Network::Testnet); let wallet = Wallet::from_extended_key( - master_key.clone(), + master_key, &[Network::Testnet], crate::wallet::initialization::WalletAccountCreationOptions::Default, ) @@ -280,8 +280,8 @@ fn test_wallet_multiple_networks() { .unwrap(); // Verify accounts exist for both networks - assert!(wallet.accounts.get(&Network::Testnet).is_some()); - assert!(wallet.accounts.get(&Network::Dash).is_some()); + assert!(wallet.accounts.contains_key(&Network::Testnet)); + assert!(wallet.accounts.contains_key(&Network::Dash)); } #[test] diff --git a/key-wallet/src/transaction_checking/transaction_router/tests/provider.rs b/key-wallet/src/transaction_checking/transaction_router/tests/provider.rs index 91c002210..edf323ea4 100644 --- a/key-wallet/src/transaction_checking/transaction_router/tests/provider.rs +++ b/key-wallet/src/transaction_checking/transaction_router/tests/provider.rs @@ -875,11 +875,11 @@ fn test_provider_revocation_classification_and_routing() { .next_receive_address(Some(&xpub), true) .expect("Failed to generate receive address"); - let mut tx = create_test_transaction(1, vec![1000_000_000]); // 10 DASH returned collateral + let mut tx = create_test_transaction(1, vec![1_000_000_000]); // 10 DASH returned collateral // Add output for returned collateral tx.output.push(TxOut { - value: 1000_000_000, + value: 1_000_000_000, script_pubkey: return_address.script_pubkey(), }); @@ -929,7 +929,7 @@ fn test_provider_revocation_classification_and_routing() { // Should have received the collateral assert_eq!( - result.total_received, 1000_000_000, + result.total_received, 1_000_000_000, "Should have received 10 DASH collateral return" ); diff --git a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs index 72f2294f8..b83bfe5a7 100644 --- a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs +++ b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs @@ -783,7 +783,7 @@ mod tests { let result = selector.select_coins(&utxos, 1500, fee_rate, 200).unwrap(); // OptimalConsolidation should work and produce a valid selection - assert!(result.selected.len() > 0); + assert!(!result.selected.is_empty()); assert!(result.total_value >= 1500 + result.estimated_fee); assert_eq!(result.target_amount, 1500); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs index bb416b0b0..b37f75d86 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs @@ -235,7 +235,7 @@ mod tests { let tx = builder.build().unwrap(); - assert!(tx.input.len() > 0); + assert!(!tx.input.is_empty()); assert_eq!(tx.output.len(), 2); // recipient + change // With BIP-69 sorting, outputs are sorted by amount diff --git a/key-wallet/tests/psbt.rs b/key-wallet/tests/psbt.rs index 11eeab10f..6262e235a 100644 --- a/key-wallet/tests/psbt.rs +++ b/key-wallet/tests/psbt.rs @@ -331,7 +331,7 @@ fn parse_and_verify_keys( let ext_derived = ext_priv.derive_priv(secp, &path).expect("failed to derive ext priv key"); let derived_priv = PrivateKey { compressed: true, - network: ext_derived.network.into(), + network: ext_derived.network, inner: ext_derived.private_key, }; assert_eq!(wif_priv, derived_priv); diff --git a/key-wallet/tests/test_optimal_consolidation.rs b/key-wallet/tests/test_optimal_consolidation.rs index 31d06df58..ca9845b42 100644 --- a/key-wallet/tests/test_optimal_consolidation.rs +++ b/key-wallet/tests/test_optimal_consolidation.rs @@ -49,7 +49,7 @@ fn test_optimal_consolidation_strategy() { let result = selector.select_coins(&utxos, 1500, fee_rate, 200).unwrap(); // OptimalConsolidation should work and produce a valid selection - assert!(result.selected.len() > 0); + assert!(!result.selected.is_empty()); assert!(result.total_value >= 1500 + result.estimated_fee); assert_eq!(result.target_amount, 1500);