Skip to content

test(rs-sdk): relocate DPNS network tests from src/ to tests/#3721

Open
lklimek wants to merge 5 commits into
v3.1-devfrom
refactor/rs-sdk-relocate-dpns-tests
Open

test(rs-sdk): relocate DPNS network tests from src/ to tests/#3721
lklimek wants to merge 5 commits into
v3.1-devfrom
refactor/rs-sdk-relocate-dpns-tests

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented May 21, 2026

Summary

Relocates 5 network-integration tests for DPNS username helpers out of src/platform/dpns_usernames/{queries.rs,contested_queries.rs} (where they sat as #[cfg(test)] mod tests blocks) into a new packages/rs-sdk/tests/dpns_usernames.rs, and wires them through the existing test harness (Config::new().setup_api(namespace).await from tests/fetch/config.rs).

Split off from #3711 so the V0/V1 wire compatibility fix can land focused; this PR carries the pure test-organization cleanup.

What's wrong today (on v3.1-dev)

  1. Wrong location. The DPNS network tests live in src/ even though they exercise only pub Sdk extension methods. They belong in tests/.
  2. Hardcoded endpoint. Each of the 5 tests hardcodes https://52.12.176.90:1443 (a testnet HPMN, currently half-up — TCP listens, TLS dead). The endpoint is invisible to tests/.env / Config.
  3. Wrong context provider for local devnets. Uses TrustedHttpContextProvider::new(Network::Testnet, ...) which fetches quorum info from a hardcoded testnet HTTP endpoint. Against a local devnet (e.g., dashmate + SDK_TEST_DATA=true), quorums don't match → Failed to find quorum: Quorum not found for type 106 ….
  4. Brittle assertions. test_dpns_queries_from_docs asserts the testnet identity 5DbLwAxGBzUzo81VewMUwn4b5P4bpv9FNFybi25XB5Bk exists — fails on any reset chain.
  5. Duplicate. tests/dpns_queries_test.rs repeats the same hardcoded endpoint pattern; another file to maintain.

What this PR does

Commit Change
09df598f3 Step 1 (band-aid): introduce src/.../test_address.rs reading DASH_SDK_PLATFORM_HOST/PORT/SSL from tests/.env to unblock vector regen on local devnets
9745211854 Step 2 (proper move): delete test_address.rs + the two #[cfg(test)] mod tests blocks in src/.../. Delete tests/dpns_queries_test.rs. Create tests/dpns_usernames.rs with all 7 relocated tests sharing one build_testnet_sdk() helper. Re-mount tests/fetch/config.rs + tests/fetch/generated_data.rs via #[path = "fetch/…"]
bd7117a1f7 Wire build_testnet_sdk() through Config::new().setup_api(namespace).await — switches the SDK off TrustedHttpContextProvider onto the canonical with_core(host, port, user, password) path that resolves quorums via local Dash Core RPC
75ed1d4203 Loosen test_dpns_queries_from_docstest_dpns_queries_smoke: all four existence assertions downgraded to println!. SDK calls still use .expect(…) so transport/proof errors panic loudly. Smoke guarantee is now "every fetch path returned Ok," not "the chain has alice."

Net effect: 5 tests moved out of src/, 1 file deleted (tests/dpns_queries_test.rs — folded in), 1 file created (tests/dpns_usernames.rs), 0 production-code changes. The methods under test were already pub on Sdk; no surface change.

The band-aid commit (09df598f3) is preserved in history rather than squashed — it's the smallest possible step that unblocked vector regen, useful as a bisect waypoint. If you prefer a single commit, squash on merge.

Test plan

  • cargo check -p dash-sdk --tests
  • cargo clippy -p dash-sdk --tests -- -D warnings
  • cargo fmt --all
  • On a local devnet (or SSH tunnel) with tests/.env populated:
    cargo test -p dash-sdk --features generate-test-vectors dpns_usernames -- --include-ignored
    Expect all 7 tests to pass (assuming devnet was built with SDK_TEST_DATA=true — see Seed DPNS contested-name prerequisites via SDK_TEST_DATA (extend create_sdk_test_data) #3720 for the prerequisite gap on test_contested_queries).

Out of scope


Co-authored by Claudius the Magnificent AI Agent

Summary by CodeRabbit

  • Tests
    • Consolidated and reorganized DPNS username and query tests into a new dedicated integration test file. Added comprehensive test coverage for name search and availability checks, resolution, identity-to-usernames lookup, contested username handling with vote state tracking, contest sorting and filtering, pagination validation, and limit behavior checks against live endpoints.

Review Change Stack

lklimek added 4 commits May 21, 2026 14:04
…ORM_* vars

Five DPNS network tests (one in queries.rs, four in contested_queries.rs)
hardcoded https://52.12.176.90:1443 (a testnet HPMN now half-up — TCP
listens, TLS hangs), which silently bypassed packages/rs-sdk/tests/.env and
made vector regeneration against a local devnet or SSH tunnel impossible.

Introduce a shared #[cfg(test)] helper test_address::test_address_list()
that loads tests/.env (best-effort) and builds an AddressList from
DASH_SDK_PLATFORM_HOST / DASH_SDK_PLATFORM_PORT / DASH_SDK_PLATFORM_SSL —
matching the existing Config schema used by tests/fetch/config.rs. The
five hardcoded blocks now call this helper.

Network/with_network(Testnet) is left untouched.
…and-aid endpoint helper

Five #[cfg(test)] blocks in src/platform/dpns_usernames/{queries,contested_queries}.rs
were really network-integration tests — they only used pub methods on Sdk (search,
availability, resolve, contested-vote-state, etc.) and shipped their own band-aid
test_address.rs helper to read DASH_SDK_PLATFORM_* env vars. They belong in tests/,
where the existing fetch::Config harness already loads tests/.env via dotenvy/envy
and exposes address_list() against the very same env vars.

This commit:
- Relocates all five #[ignore] network tests into a new tests/dpns_usernames.rs
  integration binary that re-mounts fetch::config + fetch::generated_data
  (#[path] sub-modules) so it can call Config::new().address_list() instead of
  parsing a hardcoded URL.
- Folds the previously hardcoded tests/dpns_queries_test.rs (which also pinned
  https://52.12.176.90:1443) into the same file via the shared
  build_testnet_sdk() helper, deleting the old file.
- Deletes src/platform/dpns_usernames/test_address.rs (the band-aid) and the
  five #[cfg(test)] mod tests blocks. No public-API change — the production
  helpers all stay where they were.

Net: -test_address.rs, -2 inline mod tests, -dpns_queries_test.rs,
+1 unified tests/dpns_usernames.rs, +consistent .env-driven endpoint config.

Run with:
  cargo test -p dash-sdk --features generate-test-vectors -- --include-ignored
… local Core RPC quorum lookup

build_testnet_sdk used TrustedHttpContextProvider::new(Network::Testnet, ...),
which fetches quorum info from a hardcoded testnet HTTP endpoint. Three of
the seven relocated DPNS tests (test_dpns_queries, test_dpns_queries_from_docs,
test_dpns_search_variations) panicked with `Failed to find quorum: Quorum
not found for type 106 and hash ...` when run against a local devnet or
SSH tunnel — the testnet quorums simply don't match the local chain.

Every other network test in `tests/fetch/*` solves this by going through
`Config::setup_api(namespace)`, which wires the SDK with
`SdkBuilder::with_core(host, port, user, password)`. Quorums are then
resolved via the local Dash Core RPC the user is already running.

This commit:
- Replaces build_testnet_sdk with a one-line async helper that delegates
  to `Config::new().setup_api(namespace).await`.
- Drops TrustedHttpContextProvider, build_testnet_context_provider, and the
  manual DPNS system-contract pre-load (Core RPC + standard fetch path is
  enough — no test depended on the pre-loaded contract for assertions).
- Gives each test a unique namespace so per-test vector dump dirs don't
  collide when running with `--features generate-test-vectors`.

The Network::Testnet hint is dropped along with the trusted context provider —
`Config::setup_api` doesn't expose the network field, and the canonical
`tests/fetch/*` suite operates without it just fine for proof verification
via Core RPC.
…(chain-agnostic)

The relocated test asserted testnet-specific data: that "alice" was registered,
that it resolved to a hardcoded identity, that a prefix search returned at
least one row. Against a local devnet or any reset chain those assertions
fail — the chain simply doesn't have that data.

Downgrade to a call-and-log smoke test (renamed test_dpns_queries_smoke):
each SDK call still uses .expect("…should succeed") so transport or
proof-verification failures still crash loudly, but the existence of
specific on-chain rows is logged, not asserted. The test now exercises the
DPNS query code paths against any network.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

Inline DPNS integration tests scattered across source files and an earlier test module are consolidated into a new dedicated test file. The consolidation removes test blocks from queries.rs, contested_queries.rs, and dpns_queries_test.rs, then implements a comprehensive integration test suite with shared infrastructure and eight test functions covering DPNS name operations, contested username queries, contest enumeration, and validation.

Changes

DPNS Integration Test Consolidation

Layer / File(s) Summary
Test consolidation and infrastructure setup
packages/rs-sdk/src/platform/dpns_usernames/queries.rs, packages/rs-sdk/tests/dpns_usernames.rs
Inline test modules are removed from source files. A new test file with shared build_testnet_sdk helper wires an SDK instance per test namespace using the existing Config harness.
Basic DPNS queries and search operations
packages/rs-sdk/tests/dpns_usernames.rs
Tests exercise DPNS name searching, availability checking, resolution to identity, fetching usernames by resolved identity, and search variations with prefix and limit validation.
Contested DPNS usernames and vote state
packages/rs-sdk/tests/dpns_usernames.rs
Comprehensive test for querying contested DPNS normalized usernames, parsing vote state with winner variants, handling vote tallies by identity, and exercising follow-up current-contest queries with detailed logging.
Contest enumeration, filtering, and non-resolved queries
packages/rs-sdk/tests/dpns_usernames.rs
Tests validate contest result ordering, time-range filtering relative to current time, pagination with duplicate detection, and fetch non-resolved contested usernames and contests for a given identity with limit behavior verification.
Chain-agnostic smoke tests and validation
packages/rs-sdk/tests/dpns_usernames.rs
Smoke tests exercise the full DPNS query surface from wasm-sdk documentation, asserting successful transport and proof execution across the API surface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Tests once scattered far and wide,
Now gathered in one cozy place inside,
DPNS queries, contests, and names so fine,
All consolidated in a suite divine,
Hop along, the integration's sound! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The pull request title clearly and accurately describes the main change: relocating DPNS network tests from inline src/ modules to a dedicated tests/ directory.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/rs-sdk-relocate-dpns-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lklimek lklimek marked this pull request as ready for review May 22, 2026 09:09
@lklimek lklimek changed the title refactor(rs-sdk): relocate DPNS network tests from src/ to tests/ test(rs-sdk): relocate DPNS network tests from src/ to tests/ May 22, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/rs-sdk/tests/dpns_usernames.rs (1)

37-653: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Avoid live network calls in integration tests; use mocked dependencies.

These tests directly hit Platform/Core RPC. Even with #[ignore], this violates the test isolation rule and keeps this suite environment-coupled.

As per coding guidelines, "Unit and integration tests should not perform network calls; mock dependencies."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/rs-sdk/tests/dpns_usernames.rs` around lines 37 - 653, Tests
currently perform live network calls (they call build_testnet_sdk and then
methods like search_dpns_names, check_dpns_name_availability,
resolve_dpns_name_to_identity, get_dpns_usernames_by_identity,
get_contested_dpns_normalized_usernames, get_contested_dpns_vote_state,
get_contested_dpns_usernames_by_identity, get_contested_dpns_identity_votes,
get_current_dpns_contests, get_contested_non_resolved_usernames,
get_non_resolved_dpns_contests_for_identity), which must be replaced with mocked
dependencies; refactor by introducing a build_mock_sdk (or extend
build_testnet_sdk to accept a Transport/Client trait impl) and update the tests
(test_dpns_queries, test_contested_queries, test_get_current_dpns_contests,
test_get_contested_non_resolved_usernames,
test_get_non_resolved_dpns_contests_for_identity, test_dpns_queries_smoke,
test_dpns_search_variations) to use the mock that stubs expected RPC responses
(use a mocking crate like mockall or wiremock), return deterministic data for
the SDK methods listed above, and remove live network usage so tests run in
isolation and deterministically.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/rs-sdk/tests/dpns_usernames.rs`:
- Around line 74-90: Replace the current logging-only error handling for SDK
calls with fail-fast behavior: instead of printing errors in the Err arm for
get_contested_dpns_normalized_usernames (and the other similar calls listed),
assert or unwrap the Result so the test fails on transport/proof/query errors;
locate uses of sdk.get_contested_dpns_normalized_usernames (and the other SDK
calls at the referenced ranges) and change the match/Err branches to call
unwrap() or use assert!(result.is_ok(), "...") with a concise message so
failures stop the test run immediately.

---

Outside diff comments:
In `@packages/rs-sdk/tests/dpns_usernames.rs`:
- Around line 37-653: Tests currently perform live network calls (they call
build_testnet_sdk and then methods like search_dpns_names,
check_dpns_name_availability, resolve_dpns_name_to_identity,
get_dpns_usernames_by_identity, get_contested_dpns_normalized_usernames,
get_contested_dpns_vote_state, get_contested_dpns_usernames_by_identity,
get_contested_dpns_identity_votes, get_current_dpns_contests,
get_contested_non_resolved_usernames,
get_non_resolved_dpns_contests_for_identity), which must be replaced with mocked
dependencies; refactor by introducing a build_mock_sdk (or extend
build_testnet_sdk to accept a Transport/Client trait impl) and update the tests
(test_dpns_queries, test_contested_queries, test_get_current_dpns_contests,
test_get_contested_non_resolved_usernames,
test_get_non_resolved_dpns_contests_for_identity, test_dpns_queries_smoke,
test_dpns_search_variations) to use the mock that stubs expected RPC responses
(use a mocking crate like mockall or wiremock), return deterministic data for
the SDK methods listed above, and remove live network usage so tests run in
isolation and deterministically.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1cb51ba8-f2b6-45b4-b12a-d0d4a2ba4e1c

📥 Commits

Reviewing files that changed from the base of the PR and between 12fd1a3 and 67716a7.

📒 Files selected for processing (4)
  • packages/rs-sdk/src/platform/dpns_usernames/contested_queries.rs
  • packages/rs-sdk/src/platform/dpns_usernames/queries.rs
  • packages/rs-sdk/tests/dpns_queries_test.rs
  • packages/rs-sdk/tests/dpns_usernames.rs
💤 Files with no reviewable changes (3)
  • packages/rs-sdk/src/platform/dpns_usernames/queries.rs
  • packages/rs-sdk/tests/dpns_queries_test.rs
  • packages/rs-sdk/src/platform/dpns_usernames/contested_queries.rs

Comment on lines +74 to +90
println!("Testing get_contested_dpns_usernames...");
let all_contested = sdk
.get_contested_dpns_normalized_usernames(Some(5), None)
.await;
match &all_contested {
Ok(names) => {
println!("Successfully queried contested DPNS usernames");
println!("Found {} contested DPNS usernames", names.len());
for name in names {
println!(" - {}", name);
}
}
Err(e) => {
println!("Could not fetch contested names (may not exist): {}", e);
println!("This is expected if there are no contested names on testnet.");
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail fast on SDK call errors instead of logging and passing.

Several tests currently treat transport/proof/query failures as informational logs, which can produce green runs even when the API path is broken.

Proposed fix pattern
-    let all_contested = sdk
-        .get_contested_dpns_normalized_usernames(Some(5), None)
-        .await;
-    match &all_contested {
-        Ok(names) => {
-            println!("Successfully queried contested DPNS usernames");
-            println!("Found {} contested DPNS usernames", names.len());
-        }
-        Err(e) => {
-            println!("Could not fetch contested names (may not exist): {}", e);
-            println!("This is expected if there are no contested names on testnet.");
-        }
-    }
+    let all_contested = sdk
+        .get_contested_dpns_normalized_usernames(Some(5), None)
+        .await
+        .expect("get_contested_dpns_normalized_usernames should succeed");
+    println!("Successfully queried contested DPNS usernames");
+    println!("Found {} contested DPNS usernames", all_contested.len());

Also applies to: 255-259, 282-285, 307-308, 341-343, 413-416, 517-520, 536-538, 547-550

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/rs-sdk/tests/dpns_usernames.rs` around lines 74 - 90, Replace the
current logging-only error handling for SDK calls with fail-fast behavior:
instead of printing errors in the Err arm for
get_contested_dpns_normalized_usernames (and the other similar calls listed),
assert or unwrap the Result so the test fails on transport/proof/query errors;
locate uses of sdk.get_contested_dpns_normalized_usernames (and the other SDK
calls at the referenced ranges) and change the match/Err branches to call
unwrap() or use assert!(result.is_ok(), "...") with a concise message so
failures stop the test run immediately.

@github-actions
Copy link
Copy Markdown
Contributor

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "64e3ebb2483e76e373b3a1c19f92c6f632169191462af5a3165486f9407ae3f2"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

Copy link
Copy Markdown
Collaborator

@thepastaclaw thepastaclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

I verified the only agent finding against 67716a719e32a708fe5e87d8e9775c9a9796290f and do not see a reviewable defect in this PR. The reduction from fixture-based assertions to smoke checks in test_dpns_queries_smoke is intentional, documented in the code and commit history, and necessary for the test's new goal of running against arbitrary networks configured via tests/.env rather than a hardcoded testnet endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants