test: add unit tests for generate_crypto_multi_accounts function
What changed, and why it matters
This commit only adds new automated unit tests for an existing function called generate_crypto_multi_accounts. It does not change any production code, so it cannot introduce a security vulnerability or fix one. The tests check that the function accepts certain cryptocurrency key paths, rejects an unsupported path, and handles empty input.
No security action needed. Review the tests as part of normal QA if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure test addition in rust/apps/wallets/src/core_wallet.rs under #[cfg(test)]. It defines a constant test xpub, a helper to build ExtendedPublicKey values, and six test cases covering AVAX standard path (m/44’/60’/0’), AVAX X&P path (m/44’/9000’/0’), mixed paths, an unsupported path (m/44’/1’/0’), empty keys, and a custom device_type string. No production logic is modified.
Changed components
rust/apps/wallets/src/core_wallet.rs (test module only)Inspect captured patch +124 / −0
diff --git a/rust/apps/wallets/src/core_wallet.rs b/rust/apps/wallets/src/core_wallet.rs
index 6f1e47f..ee23c39 100644
--- a/rust/apps/wallets/src/core_wallet.rs
+++ b/rust/apps/wallets/src/core_wallet.rs
@@ -92,3 +92,127 @@ fn generate_k1_normal_key(
note,
))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use alloc::vec;
+ use bitcoin::bip32::DerivationPath;
+ use core::str::FromStr;
+
+ const VALID_XPUB_HEX: &str = "0488b21e003442193e0000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689034c729aa638b3261640a8f06a5eabbfe4c04d2e0aac434b344147a1a5fa3555a3";
+
+ fn create_test_extended_public_key(path_str: &str, xpub_hex: &str) -> ExtendedPublicKey {
+ // Convert hex string to bytes
+ let bytes = hex::decode(xpub_hex).unwrap();
+ ExtendedPublicKey::new(DerivationPath::from_str(path_str).unwrap(), bytes)
+ }
+
+ #[test]
+ fn test_generate_crypto_multi_accounts_with_avax_standard() {
+ let master_fingerprint = [0x12, 0x34, 0x56, 0x78];
+ let device_type = "Keystone 3 Pro";
+
+ let keys = vec![create_test_extended_public_key(
+ "m/44'/60'/0'",
+ VALID_XPUB_HEX,
+ )];
+
+ let result = generate_crypto_multi_accounts(master_fingerprint, keys, device_type);
+ println!("Result: {:?}", result);
+
+ assert!(
+ result.is_ok(),
+ "Should successfully generate crypto multi accounts for AVAX standard path"
+ );
+ let multi_accounts = result.unwrap();
+ assert_eq!(multi_accounts.get_master_fingerprint(), master_fingerprint);
+ }
+
+ #[test]
+ fn test_generate_crypto_multi_accounts_with_avax_xp() {
+ let master_fingerprint = [0xAB, 0xCD, 0xEF, 0x00];
+ let device_type = "Keystone 3 Pro";
+
+ let keys = vec![create_test_extended_public_key(
+ "m/44'/9000'/0'",
+ VALID_XPUB_HEX,
+ )];
+
+ let result = generate_crypto_multi_accounts(master_fingerprint, keys, device_type);
+
+ assert!(
+ result.is_ok(),
+ "Should successfully generate crypto multi accounts for AVAX X&P path"
+ );
+ }
+
+ #[test]
+ fn test_generate_crypto_multi_accounts_with_mixed_paths() {
+ let master_fingerprint = [0xFF, 0xEE, 0xDD, 0xCC];
+ let device_type = "Keystone 3 Pro";
+
+ let keys = vec![
+ create_test_extended_public_key("m/44'/60'/0'", VALID_XPUB_HEX),
+ create_test_extended_public_key("m/44'/9000'/0'", VALID_XPUB_HEX),
+ ];
+
+ let result = generate_crypto_multi_accounts(master_fingerprint, keys, device_type);
+
+ assert!(
+ result.is_ok(),
+ "Should successfully generate crypto multi accounts with mixed paths"
+ );
+ let multi_accounts = result.unwrap();
+ // Should have 2 keys generated
+ assert!(multi_accounts.get_keys().len() >= 1);
+ }
+
+ #[test]
+ fn test_generate_crypto_multi_accounts_with_invalid_path() {
+ let master_fingerprint = [0x11, 0x22, 0x33, 0x44];
+ let device_type = "Keystone 3 Pro";
+
+ let keys = vec![create_test_extended_public_key(
+ "m/44'/1'/0'",
+ VALID_XPUB_HEX,
+ )];
+
+ let result = generate_crypto_multi_accounts(master_fingerprint, keys, device_type);
+
+ assert!(
+ result.is_err(),
+ "Should return error for unsupported key path"
+ );
+ }
+
+ #[test]
+ fn test_generate_crypto_multi_accounts_empty_keys() {
+ let master_fingerprint = [0x99, 0x88, 0x77, 0x66];
+ let device_type = "Keystone 3 Pro";
+ let keys = vec![];
+
+ let result = generate_crypto_multi_accounts(master_fingerprint, keys, device_type);
+
+ assert!(result.is_ok(), "Should handle empty key list");
+ let multi_accounts = result.unwrap();
+ assert_eq!(multi_accounts.get_keys().len(), 0);
+ }
+
+ #[test]
+ fn test_generate_crypto_multi_accounts_device_type() {
+ let master_fingerprint = [0x12, 0x34, 0x56, 0x78];
+ let device_type = "Custom Device Type";
+
+ let keys = vec![create_test_extended_public_key(
+ "m/44'/60'/0'",
+ VALID_XPUB_HEX,
+ )];
+
+ let result = generate_crypto_multi_accounts(master_fingerprint, keys, device_type);
+
+ assert!(result.is_ok());
+ let multi_accounts = result.unwrap();
+ assert_eq!(multi_accounts.get_device(), Some(device_type.to_string()));
+ }
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.