From 94bd5fce4b65d7d45757e722684559111fe25150 Mon Sep 17 00:00:00 2001 From: PastaClaw Date: Fri, 20 Feb 2026 22:04:14 -0600 Subject: [PATCH] test(rs-sdk): keep DPNS/assertion test updates only --- packages/rs-sdk/tests/dpns_queries_test.rs | 183 ++++----------------- packages/rs-sdk/tests/dpns_unit_tests.rs | 137 +++++---------- packages/rs-sdk/tests/fetch/identity.rs | 35 ++++ 3 files changed, 108 insertions(+), 247 deletions(-) diff --git a/packages/rs-sdk/tests/dpns_queries_test.rs b/packages/rs-sdk/tests/dpns_queries_test.rs index ef319c3e2d9..3f8e904780a 100644 --- a/packages/rs-sdk/tests/dpns_queries_test.rs +++ b/packages/rs-sdk/tests/dpns_queries_test.rs @@ -1,9 +1,12 @@ use dash_sdk::SdkBuilder; use dpp::dashcore::Network; -// Test values from wasm-sdk docs.html +// Test values from wasm-sdk docs.html (testnet DPNS integration test fixtures) +/// Base58-encoded testnet identity ID used for DPNS query testing (source: wasm-sdk docs.html) const TEST_IDENTITY_ID: &str = "5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk"; +/// Known testnet DPNS username for integration testing (source: wasm-sdk docs.html) const TEST_USERNAME: &str = "alice"; +/// Search prefix for DPNS name search testing (source: wasm-sdk docs.html) const TEST_PREFIX: &str = "ali"; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -21,6 +24,7 @@ async fn test_dpns_queries_from_docs() { .expect("Failed to create context provider"); // Initialize SDK for testnet with trusted context provider + // Dash Platform testnet node address (DAPI endpoint) let address_list = "https://52.12.176.90:1443" .parse() .expect("Failed to parse address"); @@ -30,146 +34,48 @@ async fn test_dpns_queries_from_docs() { .build() .expect("Failed to create SDK"); - println!("Testing DPNS queries with values from wasm-sdk docs.html...\n"); - // Test 1: Check availability of "alice" - println!("1. Testing dpns_check_availability('alice'):"); - match sdk.check_dpns_name_availability(TEST_USERNAME).await { - Ok(is_available) => { - println!( - " ✅ Success: Name 'alice' is {}", - if is_available { - "AVAILABLE" - } else { - "NOT AVAILABLE" - } - ); - } - Err(e) => { - println!(" ❌ Error: {}", e); - } - } - println!(); + let _is_available = sdk + .check_dpns_name_availability(TEST_USERNAME) + .await + .expect("check availability should succeed"); // Test 2: Resolve "alice" to identity ID - println!("2. Testing dpns_resolve_name('alice'):"); - match sdk.resolve_dpns_name_to_identity(TEST_USERNAME).await { - Ok(Some(identity_id)) => { - println!( - " ✅ Success: 'alice' resolves to identity: {}", - identity_id - ); - } - Ok(None) => { - println!(" ℹ️ Name 'alice' not found (not registered)"); - } - Err(e) => { - println!(" ❌ Error: {}", e); - } - } - println!(); + let _maybe_identity = sdk + .resolve_dpns_name_to_identity(TEST_USERNAME) + .await + .expect("resolve should succeed"); // Test 3: Get DPNS usernames for identity - println!( - "3. Testing get_dpns_usernames_by_identity('{}'):", - TEST_IDENTITY_ID - ); - // Parse the identity ID from base58 - let identity_id = match dash_sdk::dpp::prelude::Identifier::from_string( + let identity_id = dash_sdk::dpp::prelude::Identifier::from_string( TEST_IDENTITY_ID, dpp::platform_value::string_encoding::Encoding::Base58, - ) { - Ok(id) => id, - Err(e) => { - println!(" ❌ Error parsing identity ID: {}", e); - return; - } - }; - - match sdk + ) + .expect("identity id should parse"); + + let _usernames = sdk .get_dpns_usernames_by_identity(identity_id, Some(10)) .await - { - Ok(usernames) => { - if usernames.is_empty() { - println!(" ℹ️ No usernames found for this identity"); - } else { - println!(" ✅ Success: Found {} usernames:", usernames.len()); - for (i, username) in usernames.iter().enumerate() { - println!(" [{}] {}", i + 1, username.full_name); - println!(" - Label: {}", username.label); - println!(" - Normalized: {}", username.normalized_label); - println!(" - Owner ID: {}", username.owner_id); - if let Some(records_id) = &username.records_identity_id { - println!(" - Records Identity: {}", records_id); - } - } - } - } - Err(e) => { - println!(" ❌ Error: {}", e); - } - } - println!(); + .expect("get usernames by identity should succeed"); // Test 4: Search DPNS names by prefix "ali" - println!("4. Testing search_dpns_names('{}'):", TEST_PREFIX); - match sdk.search_dpns_names(TEST_PREFIX, Some(10)).await { - Ok(usernames) => { - if usernames.is_empty() { - println!(" ℹ️ No names found starting with '{}'", TEST_PREFIX); - } else { - println!( - " ✅ Success: Found {} names starting with '{}':", - usernames.len(), - TEST_PREFIX - ); - for (i, username) in usernames.iter().enumerate() { - println!(" [{}] {}", i + 1, username.full_name); - println!(" - Label: {}", username.label); - println!(" - Normalized: {}", username.normalized_label); - println!(" - Owner ID: {}", username.owner_id); - } - } - } - Err(e) => { - println!(" ❌ Error: {}", e); - } - } - println!(); + let _search_results = sdk + .search_dpns_names(TEST_PREFIX, Some(10)) + .await + .expect("search should succeed"); // Test with a name that's more likely to exist on testnet - println!("5. Testing with 'therealslimshaddy5' (known existing name):"); - match sdk + let maybe_identity = sdk .resolve_dpns_name_to_identity("therealslimshaddy5") .await - { - Ok(Some(identity_id)) => { - println!( - " ✅ Success: 'therealslimshaddy5' resolves to identity: {}", - identity_id - ); - - // Get usernames for this identity - match sdk - .get_dpns_usernames_by_identity(identity_id, Some(5)) - .await - { - Ok(usernames) => { - println!(" ✅ This identity owns {} usernames", usernames.len()); - } - Err(e) => { - println!(" ❌ Error getting usernames: {}", e); - } - } - } - Ok(None) => { - println!(" ℹ️ Name 'therealslimshaddy5' not found"); - } - Err(e) => { - println!(" ❌ Error: {}", e); - } + .expect("resolve should succeed"); + + if let Some(identity_id) = maybe_identity { + let _usernames = sdk + .get_dpns_usernames_by_identity(identity_id, Some(5)) + .await + .expect("get usernames by identity should succeed"); } } @@ -187,6 +93,7 @@ async fn test_dpns_search_variations() { ) .expect("Failed to create context provider"); + // Dash Platform testnet node address (DAPI endpoint) let address_list = "https://52.12.176.90:1443" .parse() .expect("Failed to parse address"); @@ -196,30 +103,12 @@ async fn test_dpns_search_variations() { .build() .expect("Failed to create SDK"); - println!("Testing DPNS search with various prefixes...\n"); - let test_prefixes = vec!["a", "test", "d", "dash", "demo", "user"]; for prefix in test_prefixes { - println!("Searching for names starting with '{}':", prefix); - match sdk.search_dpns_names(prefix, Some(5)).await { - Ok(usernames) => { - if usernames.is_empty() { - println!(" - No names found"); - } else { - println!(" - Found {} names:", usernames.len()); - for username in usernames.iter().take(3) { - println!(" • {}", username.full_name); - } - if usernames.len() > 3 { - println!(" ... and {} more", usernames.len() - 3); - } - } - } - Err(e) => { - println!(" - Error: {}", e); - } - } - println!(); + let _results = sdk + .search_dpns_names(prefix, Some(5)) + .await + .expect("search should succeed"); } } diff --git a/packages/rs-sdk/tests/dpns_unit_tests.rs b/packages/rs-sdk/tests/dpns_unit_tests.rs index 0b2d2efc4dd..5d6cef33904 100644 --- a/packages/rs-sdk/tests/dpns_unit_tests.rs +++ b/packages/rs-sdk/tests/dpns_unit_tests.rs @@ -4,35 +4,29 @@ use dash_sdk::platform::dpns_usernames::{ #[test] fn test_dpns_validation_functions() { - println!("Testing DPNS validation functions with values from docs...\n"); - // Test username validation - println!("1. Testing is_valid_username:"); let test_names = vec![ - "alice", - "test", - "dash", - "a", - "ab", - "123", - "test-name", - "test--name", - "-test", - "test-", + ("alice", true), + ("test", true), + ("dash", true), + ("a", false), + ("ab", false), + ("123", true), + ("test-name", true), + ("test--name", false), + ("-test", false), + ("test-", false), ]; - for name in test_names { - let is_valid = is_valid_username(name); - println!( - " '{}' is {}", - name, - if is_valid { "✅ VALID" } else { "❌ INVALID" } + for (name, expected_valid) in test_names { + assert_eq!( + is_valid_username(name), + expected_valid, + "is_valid_username({name}) should be {expected_valid}" ); } - println!(); // Test homograph conversion - println!("2. Testing convert_to_homograph_safe_chars:"); let test_conversions = vec![ ("alice", "a11ce"), ("bob", "b0b"), @@ -44,21 +38,13 @@ fn test_dpns_validation_functions() { for (input, expected) in test_conversions { let result = convert_to_homograph_safe_chars(input); - let matches = result == expected; - println!( - " '{}' → '{}' {}", - input, - result, - if matches { "✅" } else { "❌ (expected: {})" } + assert_eq!( + result, expected, + "convert_to_homograph_safe_chars({input}) should be {expected}" ); - if !matches { - println!(" Expected: {}", expected); - } } - println!(); // Test contested username check - println!("3. Testing is_contested_username:"); let test_contested = vec![ ("abc", true), // 3 chars ("test", true), // 4 chars @@ -72,55 +58,28 @@ fn test_dpns_validation_functions() { ]; for (name, expected) in test_contested { - let result = is_contested_username(name); - let matches = result == expected; - println!( - " '{}' is {} contested {}", + assert_eq!( + is_contested_username(name), + expected, + "is_contested_username({}) should be {}", name, - if result { "🔥" } else { "📝" }, - if matches { "✅" } else { "❌" } + expected ); } } #[test] fn test_dpns_edge_cases() { - println!("\nTesting DPNS edge cases...\n"); - // Test minimum and maximum length usernames let min_name = "abc"; let max_name = "a".repeat(63); let too_long = "a".repeat(64); - println!("Length tests:"); - println!( - " 3 chars '{}': {}", - min_name, - if is_valid_username(min_name) { - "✅ VALID" - } else { - "❌ INVALID" - } - ); - println!( - " 63 chars: {}", - if is_valid_username(&max_name) { - "✅ VALID" - } else { - "❌ INVALID" - } - ); - println!( - " 64 chars: {}", - if is_valid_username(&too_long) { - "✅ VALID (should be invalid!)" - } else { - "❌ INVALID (correct)" - } - ); + assert!(is_valid_username(min_name)); + assert!(is_valid_username(&max_name)); + assert!(!is_valid_username(&too_long)); // Test special characters - println!("\nSpecial character tests:"); let special_tests = vec![ "test_name", // underscore "test.name", // dot @@ -135,19 +94,13 @@ fn test_dpns_edge_cases() { ]; for name in special_tests { - println!( - " '{}': {}", - name, - if is_valid_username(name) { - "✅ VALID" - } else { - "❌ INVALID" - } + assert!( + !is_valid_username(name), + "special-character username should be invalid: {name}" ); } // Test Unicode/international characters - println!("\nUnicode character tests:"); let unicode_tests = vec![ "café", // French "münchen", // German @@ -157,22 +110,15 @@ fn test_dpns_edge_cases() { ]; for name in unicode_tests { - println!( - " '{}': {}", - name, - if is_valid_username(name) { - "✅ VALID" - } else { - "❌ INVALID" - } + assert!( + !is_valid_username(name), + "unicode username should be invalid: {name}" ); } } #[test] fn test_dpns_homograph_safety() { - println!("\nTesting DPNS homograph safety conversions...\n"); - // Test various homograph attacks let homograph_tests = vec![ ("paypal", "paypa1"), // lowercase L to 1 @@ -189,27 +135,18 @@ fn test_dpns_homograph_safety() { for (input, expected) in homograph_tests { let result = convert_to_homograph_safe_chars(input); - println!(" '{}' → '{}' (expected: {})", input, result, expected); + assert_eq!( + result, expected, + "convert_to_homograph_safe_chars({input}) should be {expected}" + ); } // Test that the conversion is idempotent - println!("\nIdempotency test (converting twice should give same result):"); let test_names = vec!["alice", "bob", "cool", "test"]; for name in test_names { let once = convert_to_homograph_safe_chars(name); let twice = convert_to_homograph_safe_chars(&once); - let matches = once == twice; - println!( - " '{}' → '{}' → '{}' {}", - name, - once, - twice, - if matches { - "✅ Idempotent" - } else { - "❌ Not idempotent!" - } - ); + assert_eq!(once, twice, "conversion should be idempotent for '{name}'"); } } diff --git a/packages/rs-sdk/tests/fetch/identity.rs b/packages/rs-sdk/tests/fetch/identity.rs index a3c3acb2bf4..afd8cc270dd 100644 --- a/packages/rs-sdk/tests/fetch/identity.rs +++ b/packages/rs-sdk/tests/fetch/identity.rs @@ -28,6 +28,22 @@ async fn test_identity_read() { assert_eq!(identity.id(), id); } +/// Given a non-existent identity ID, when I fetch the identity, I get None. +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +#[ignore = "requires mock vectors to be generated against a running Platform"] +async fn test_identity_read_not_found() { + setup_logs(); + + let cfg = Config::new(); + let sdk = cfg.setup_api("test_identity_read_not_found").await; + + let result = Identity::fetch(&sdk, super::generated_data::UNKNOWN_IDENTITY_ID) + .await + .expect("fetch should not error for non-existent identity"); + + assert!(result.is_none(), "non-existent identity should return None"); +} + /// Given some existing identity public key, when I fetch the identity, and I get it. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_identity_read_by_key() { @@ -92,6 +108,25 @@ async fn test_identity_balance_revision_read() { tracing::debug!(balance, revision, ?id, "identity balance and revision") } +/// Given a non-existent identity ID, when I fetch the identity balance, I get None. +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +#[ignore = "requires mock vectors to be generated against a running Platform"] +async fn test_identity_balance_read_not_found() { + setup_logs(); + + let cfg = Config::new(); + let sdk = cfg.setup_api("test_identity_balance_read_not_found").await; + + let result = IdentityBalance::fetch(&sdk, super::generated_data::UNKNOWN_IDENTITY_ID) + .await + .expect("fetch should not error for non-existent identity"); + + assert!( + result.is_none(), + "non-existent identity balance should return None" + ); +} + /// Given some existing identity ID, when I fetch the identity keys, I get some of them indexed by key ID. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_identity_public_keys_all_read() {