Skip to content

test(drive): improve identity fetch, balance, and public key hash coverage#3443

Merged
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/drive-identity-fetch-coverage
Apr 7, 2026
Merged

test(drive): improve identity fetch, balance, and public key hash coverage#3443
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/drive-identity-fetch-coverage

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Apr 7, 2026

Summary

Adds 67 tests across 6 files in rs-drive identity fetch module, targeting the lowest-coverage areas.

File New Tests Coverage Before What's covered
fetch/queries/mod.rs 26 70% All query construction functions, IdentityProveRequestType::try_from, range queries with all pagination variants
fetch/fetch_by_public_key_hashes/mod.rs 21 69% Unique/non-unique hash lookups, batch fetches, has_*_hash checks, mixed known/unknown
fetch/full_identity/mod.rs 8 67% Batch fetch, fetch_with_costs, operations recording, transaction visibility
fetch/balance/mod.rs 7 80% Transaction visibility, costs in applied/estimated modes, negative balance/debt
fetch/mod.rs 3 94% Range balance queries with descending/pagination/empty DB
fetch/contract_keys/mod.rs 2 76% Empty results for non-existent identity/contract keys

Test plan

  • cargo test -p drive --lib -- identity::fetch passes
  • cargo fmt --all clean
  • CI

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for identity management operations including balance queries with cost calculations, contract key lookups, public key hash searches, full identity retrievals, batch operations, and query construction to enhance system reliability and code quality.

Add 67 new unit tests across the identity fetch subsystem targeting the
lowest-coverage areas: queries, fetch_by_public_key_hashes, full_identity,
balance, and contract_keys. Tests cover query construction (all branch
variants), IdentityProveRequestType conversion, fetch with/without
transactions, with-costs variants, negative balance/debt paths, estimated
mode, public key hash lookups (unique and non-unique), batch fetches with
missing identities, pagination with start_at (inclusive/exclusive,
ascending/descending), and contract key fetches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added this to the v3.1.0 milestone Apr 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 39 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 12 minutes and 39 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cf0d4a4f-1427-43bd-a668-05c0a226e1e4

📥 Commits

Reviewing files that changed from the base of the PR and between be8674d and d13c2ae.

📒 Files selected for processing (3)
  • packages/rs-drive/src/drive/identity/fetch/contract_keys/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/queries/mod.rs
📝 Walkthrough

Walkthrough

This PR adds comprehensive unit test coverage to identity fetch modules in the rs-drive package, covering balance queries, contract keys, public key hash lookups, full identity retrieval, and query construction across multiple scenarios without modifying any production code.

Changes

Cohort / File(s) Summary
Identity Balance Fetch Tests
packages/rs-drive/src/drive/identity/fetch/balance/mod.rs
Added test coverage for balance queries within GROVE transactions, balance fetching with/without cost application, debt balance scenarios, and negative balance operations in estimated mode.
Contract Keys & Public Key Hash Fetch Tests
packages/rs-drive/src/drive/identity/fetch/contract_keys/mod.rs, packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs
Added tests for contract-key queries with non-existent identities and empty inputs; comprehensive coverage for unique/non-unique public key hash lookups including batch retrieval, existence checks, and limit enforcement.
Full Identity & Batch Fetch Tests
packages/rs-drive/src/drive/identity/fetch/full_identity/mod.rs, packages/rs-drive/src/drive/identity/fetch/mod.rs
Added tests for batched full-identity retrieval with mixed existent/non-existent IDs, balance range pagination with ascending/descending ordering, transaction-scoped identity visibility, and costs/operations tracking.
Query Construction Tests
packages/rs-drive/src/drive/identity/fetch/queries/mod.rs
Added unit tests for IdentityProveRequestType conversions and query helper methods, validating PathQuery construction, path non-emptiness, and limit/offset field behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hop through the tests, each assertion rings clear,
Balance and keys and identities dear,
Coverage grows thick like carrots in spring,
No bugs shall escape our testing's sweet sing! 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and clearly summarizes the main change: adding test coverage improvements across identity fetch, balance, and public key hash modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/drive-identity-fetch-coverage

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.

@thepastaclaw
Copy link
Copy Markdown
Collaborator

thepastaclaw commented Apr 7, 2026

⏳ Review in progress (commit d13c2ae)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 98.93617% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.35%. Comparing base (8a83981) to head (d13c2ae).
⚠️ Report is 8 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...e/identity/fetch/fetch_by_public_key_hashes/mod.rs 97.78% 10 Missing ⚠️
...rive/src/drive/identity/fetch/contract_keys/mod.rs 96.77% 2 Missing ⚠️
packages/rs-drive/src/drive/identity/fetch/mod.rs 99.37% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3443      +/-   ##
============================================
+ Coverage     80.66%   81.35%   +0.68%     
============================================
  Files          2852     2852              
  Lines        285371   291573    +6202     
============================================
+ Hits         230190   237203    +7013     
+ Misses        55181    54370     -811     
Components Coverage Δ
dpp 74.38% <ø> (+1.09%) ⬆️
drive 83.51% <98.93%> (+1.01%) ⬆️
drive-abci 86.70% <ø> (ø)
sdk 36.55% <ø> (ø)
dapi-client 79.06% <ø> (ø)
platform-version ∅ <ø> (∅)
platform-value 92.00% <ø> (+1.21%) ⬆️
platform-wallet 76.09% <ø> (ø)
drive-proof-verifier 55.26% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/rs-drive/src/drive/identity/fetch/contract_keys/mod.rs`:
- Around line 94-101: The test currently treats Err(_) as acceptable when
matching on result, weakening coverage; instead assert that result is Ok and
that the returned map is empty. Replace the match on result (the branch Ok(map)
=> assert!(map.is_empty()), Err(_) => { ... }) with a strict check such as let
map = result.expect("expected Ok(map) for non-existent contract-key");
assert!(map.is_empty()); and apply the same change to the second occurrence that
also matches on the variable result so any Err now fails the test.

In
`@packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs`:
- Around line 284-291: The test currently uses conditional blocks like `if let
Some(key) = non_unique_key` which silently skip checks when `non_unique_key` is
None; change these to hard preconditions by asserting the presence of the key
(e.g., `assert!(non_unique_key.is_some())`) and then unwrapping it before
calling `key.public_key_hash()` and `drive.has_non_unique_public_key_hash(...)`;
apply the same change to all occurrences of `non_unique_key` in this module
(including the other ranges noted) so the assertions always run and the test
fails if a non-unique key was not produced.

In `@packages/rs-drive/src/drive/identity/fetch/queries/mod.rs`:
- Around line 703-716: The test should assert that the document type actually
influences the generated query path: update the
should_build_identities_contract_document_type_keys_query test that calls
Drive::identities_contract_document_type_keys_query so it verifies pq.path
encodes the supplied document type ("profile") (e.g., contains the document type
string or its expected encoded representation) in addition to the existing
non-empty check and limit assertion; reference
identities_contract_document_type_keys_query, pq.path, contract_id and the
"profile" document type when adding the assertion.
🪄 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: 2c4e46b9-60c2-403b-86b4-51d59dc0412b

📥 Commits

Reviewing files that changed from the base of the PR and between e4efd88 and be8674d.

📒 Files selected for processing (6)
  • packages/rs-drive/src/drive/identity/fetch/balance/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/contract_keys/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/full_identity/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/mod.rs
  • packages/rs-drive/src/drive/identity/fetch/queries/mod.rs

Comment thread packages/rs-drive/src/drive/identity/fetch/contract_keys/mod.rs Outdated
Comment thread packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs Outdated
Comment thread packages/rs-drive/src/drive/identity/fetch/queries/mod.rs
- contract_keys: assert Ok instead of matching Ok/Err
- fetch_by_public_key_hashes: require non-unique key exists instead of
  conditional assertion
- queries: document that doc type param doesn't affect query path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer merged commit 439eb60 into v3.1-dev Apr 7, 2026
38 checks passed
@QuantumExplorer QuantumExplorer deleted the test/drive-identity-fetch-coverage branch April 7, 2026 21:09
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