Skip to content

test(drive): improve coverage for vote paths, document info, token ops, and asset lock proofs#3452

Merged
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/drive-votes-paths-docinfo
Apr 8, 2026
Merged

test(drive): improve coverage for vote paths, document info, token ops, and asset lock proofs#3452
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/drive-votes-paths-docinfo

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Apr 8, 2026

Summary

Adds 101 tests across 4 files in rs-drive and rs-dpp.

File Tests What's covered
drive/votes/paths.rs 37 All path construction functions, consistency between slice/vec variants
util/object_size_info/document_info.rs 32 All DocumentInfo variant methods, size calculations
util/batch/drive_op_batch/token.rs 11 Token operation construction (burn, mint, transfer, freeze, etc.)
asset_lock_proof/instant/instant_asset_lock_proof.rs 21 Construction, accessors, output/outpoint, serialization round-trips

Test plan

  • cargo test -p drive --lib and cargo test -p dpp --lib pass
  • cargo fmt --all clean
  • CI

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for identity state transition, vote path construction, token operation types, and document information handling. All changes are internal testing improvements with no impact on user-facing functionality.

…ops, and instant asset lock proof

Add 101 unit tests across four previously untested files:
- drive::votes::paths (37 tests): path construction, vec/slice consistency, constant values
- util::object_size_info::document_info (32 tests): variant methods, accessors, size info
- util::batch::drive_op_batch::token (11 tests): operation construction, clone, debug
- dpp::identity::state_transition::asset_lock_proof::instant (21 tests): construction, accessors, round-trip serialization, equality

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 8, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 44 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 6 minutes and 44 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: cf73b47f-03ba-484e-8deb-a2b8b934e7f8

📥 Commits

Reviewing files that changed from the base of the PR and between 9d06b38 and c0cc03e.

📒 Files selected for processing (1)
  • packages/rs-drive/src/util/batch/drive_op_batch/token.rs
📝 Walkthrough

Walkthrough

This PR adds comprehensive test coverage to four files across rs-dpp and rs-drive packages with no production code changes, introducing approximately 1,320 lines of unit tests for InstantAssetLockProof, vote-tree paths, TokenOperationType, and DocumentInfo variants.

Changes

Cohort / File(s) Summary
InstantAssetLockProof Tests
packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs
Added 220 lines of tests covering default initialization, constructor correctness, accessor behavior, output handling, identifier creation, serialization round-trips, cloning, equality, and type conversion via TryFrom<Value>.
Vote Path Construction Tests
packages/rs-drive/src/drive/votes/paths.rs
Added 448 lines of tests validating path structure and lengths for vote-tree functions, comparing slice and vec variants, asserting path differences for contracts/documents/dates, verifying identity-votes paths include identity IDs, and confirming expected values for exported key constants.
TokenOperationType Tests
packages/rs-drive/src/util/batch/drive_op_batch/token.rs
Added 294 lines of tests covering enum variant construction (TokenBurn, TokenMint, TokenMintMany, TokenTransfer, TokenFreeze, TokenUnfreeze, TokenSetPriceForDirectPurchase, TokenMarkPreProgrammedReleaseAsDistributed), cloning behavior, and Debug formatting.
DocumentInfo Tests
packages/rs-drive/src/util/object_size_info/document_info.rs
Added 359 lines of tests for DocumentInfo variant behavior, including variant discrimination, document borrowing, key-value info requests, storage flags handling, and document ID extraction across estimated and non-estimated variants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through test files bright,
Each assertion penned just right,
From locks to paths, from tokens too,
A thousand lines of code so true!
Coverage grows with every hop—
Quality's ascending up the top! 🧪✨

🚥 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 title accurately summarizes the main objective: adding comprehensive unit tests to improve coverage across four key components (vote paths, document info, token operations, and asset lock proofs).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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-votes-paths-docinfo

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 8, 2026

Review Gate

Commit: c0cc03e4

  • Debounce: 3m ago (need 30m)

  • CI checks: checks still running (2 pending)

  • CodeRabbit review: comment found

  • Off-peak hours: off-peak (12:21 AM PT Wednesday)

  • Run review now (check to override)

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

🧹 Nitpick comments (5)
packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs (1)

277-284: test_new_stores_fields_correctly currently does not validate new() field assignment.

At Line 279 the test uses a fixture and only checks output_index plus accessor calls; it never proves constructor inputs are preserved. Please construct via InstantAssetLockProof::new(...) and assert equality on all three fields.

Proposed test tightening
 #[test]
 fn test_new_stores_fields_correctly() {
-    let proof = raw_instant_asset_lock_proof_fixture(None, None);
-    assert_eq!(proof.output_index(), 0);
-    // Verify the instant lock and transaction are accessible
-    let _il = proof.instant_lock();
-    let _tx = proof.transaction();
+    let base = raw_instant_asset_lock_proof_fixture(None, None);
+    let instant_lock = base.instant_lock.clone();
+    let transaction = base.transaction.clone();
+    let output_index = 5;
+
+    let proof = InstantAssetLockProof::new(
+        instant_lock.clone(),
+        transaction.clone(),
+        output_index,
+    );
+
+    assert_eq!(proof.instant_lock(), &instant_lock);
+    assert_eq!(proof.transaction(), &transaction);
+    assert_eq!(proof.output_index(), output_index);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs`
around lines 277 - 284, The test test_new_stores_fields_correctly should
construct an InstantAssetLockProof using InstantAssetLockProof::new(...) instead
of using the raw fixture return value directly; obtain the expected
output_index, instant_lock, and transaction from
raw_instant_asset_lock_proof_fixture(None, None) (or from dedicated fixtures),
call InstantAssetLockProof::new(expected_output_index,
expected_instant_lock.clone(), expected_transaction.clone()), then assert that
proof.output_index() == expected_output_index, proof.instant_lock() ==
&expected_instant_lock, and proof.transaction() == &expected_transaction to
verify the constructor stored all fields correctly.
packages/rs-drive/src/drive/votes/paths.rs (1)

572-579: Consider extracting a shared helper for vec/slice parity assertions.

The repeated for (vec_elem, slice_elem) comparison blocks are consistent but duplicated; a small local helper would reduce maintenance overhead.

Also applies to: 595-601, 617-623, 640-646, 669-672, 721-724, 764-767, 794-797, 872-875, 899-902

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive/src/drive/votes/paths.rs` around lines 572 - 579, Extract a
small test helper (e.g., assert_path_vec_slice_parity or
assert_vec_matches_slice) that accepts a Vec of path elements and a slice
(&[&[u8]] or whatever types used) and asserts equal length and that each
vec_elem.as_slice() == *slice_elem; then replace the repeated for-loop blocks in
functions like test_vote_decisions_tree_path_vec_matches_slice_form, the tests
around lines 595-601, 617-623, 640-646, 669-672, 721-724, 764-767, 794-797,
872-875, and 899-902 to call this helper (pass
vote_decisions_tree_path_vec()/vote_decisions_tree_path() and the analogous
path_vec/path pairs in other tests), removing duplicated loop logic. Ensure the
helper name is descriptive and used consistently across those test functions.
packages/rs-drive/src/util/object_size_info/document_info.rs (2)

503-527: Consider renaming this test to reflect what it actually verifies.

This test doesn't call get_estimated_size_for_document_type; it only verifies the constant values. The current name test_estimated_size_for_owner_id is misleading. Consider renaming to something like test_system_field_size_constants.

Also, the drop(info) at line 526 is unnecessary—Rust automatically drops values at the end of their scope.

♻️ Suggested rename and cleanup
     #[test]
-    fn test_estimated_size_for_owner_id() {
-        let info = DocumentInfo::DocumentEstimatedAverageSize(100);
-        // We cannot build a real DocumentTypeRef without a full contract,
-        // but for system fields the document type is not consulted.
+    fn test_system_field_size_constants() {
+        // DocumentTypeRef requires a full DataContract, so we verify the
+        // constant values that get_estimated_size_for_document_type returns
+        // for system fields like $ownerId, $createdAt, etc.
         ...
-        drop(info);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive/src/util/object_size_info/document_info.rs` around lines
503 - 527, Rename the test function test_estimated_size_for_owner_id to a name
that reflects it only verifies constant sizes (e.g.,
test_system_field_size_constants) and remove the unnecessary drop(info) call;
update the test declaration (the function name) that references DocumentInfo and
assert constants DEFAULT_HASH_SIZE_U16, U64_SIZE_U16, and U32_SIZE_U16 so the
test name matches its actual purpose.

584-600: Consider adding a test for get_storage_flags_ref with DocumentEstimatedAverageSize.

The implementation handles DocumentEstimatedAverageSize differently—it returns StorageFlags::optional_default_as_ref() (line 278-279)—but this behavior is not covered by any test. Adding a test would ensure this edge case remains consistent.

🧪 Suggested additional test
     #[test]
     fn test_get_storage_flags_ref_none_for_owned_without_flags() {
         let doc = make_document([41; 32]);
         let info = DocumentInfo::DocumentOwnedInfo((doc, None));
         assert!(info.get_storage_flags_ref().is_none());
     }
+
+    #[test]
+    fn test_get_storage_flags_ref_for_estimated_returns_optional_default() {
+        let info = DocumentInfo::DocumentEstimatedAverageSize(100);
+        // Implementation returns StorageFlags::optional_default_as_ref()
+        let flags = info.get_storage_flags_ref();
+        assert_eq!(flags, StorageFlags::optional_default_as_ref());
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive/src/util/object_size_info/document_info.rs` around lines
584 - 600, Add a unit test that covers the DocumentEstimatedAverageSize variant
for get_storage_flags_ref: construct a
DocumentInfo::DocumentEstimatedAverageSize instance (e.g. with an estimated size
value), call info.get_storage_flags_ref(), and assert it returns
StorageFlags::optional_default_as_ref(); reference get_storage_flags_ref,
DocumentEstimatedAverageSize, and StorageFlags::optional_default_as_ref() so the
test verifies this specific branch.
packages/rs-drive/src/util/batch/drive_op_batch/token.rs (1)

575-605: Consider testing Clone and Debug for additional variants.

The Clone and Debug tests currently only validate the TokenBurn variant. While the derived implementations should work consistently, testing a couple more variants (especially those with different field types like TokenMintMany with a Vec or TokenSetPriceForDirectPurchase with an Option) would provide additional confidence.

♻️ Optional: expand Clone and Debug test coverage
 #[test]
 fn test_token_operation_clone() {
     let op = TokenOperationType::TokenBurn {
         token_id: test_token_id(),
         identity_balance_holder_id: test_identity_id(),
         burn_amount: 100,
     };
     let cloned = op.clone();
     match cloned {
         TokenOperationType::TokenBurn { burn_amount, .. } => {
             assert_eq!(burn_amount, 100);
         }
         _ => panic!("clone should preserve variant"),
     }
+
+    // Test cloning a variant with Vec
+    let op2 = TokenOperationType::TokenMintMany {
+        token_id: test_token_id(),
+        recipients: vec![(test_recipient_id(), 100)],
+        mint_amount: 500,
+        allow_first_mint: true,
+    };
+    let cloned2 = op2.clone();
+    match cloned2 {
+        TokenOperationType::TokenMintMany { recipients, .. } => {
+            assert_eq!(recipients.len(), 1);
+        }
+        _ => panic!("clone should preserve variant"),
+    }
 }

 #[test]
 fn test_token_operation_debug() {
     let op = TokenOperationType::TokenBurn {
         token_id: test_token_id(),
         identity_balance_holder_id: test_identity_id(),
         burn_amount: 42,
     };
     let debug_str = format!("{:?}", op);
     assert!(debug_str.contains("TokenBurn"));
     assert!(debug_str.contains("42"));
+
+    // Test Debug for variant with Option
+    let op2 = TokenOperationType::TokenSetPriceForDirectPurchase {
+        token_id: test_token_id(),
+        price: None,
+    };
+    let debug_str2 = format!("{:?}", op2);
+    assert!(debug_str2.contains("TokenSetPriceForDirectPurchase"));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive/src/util/batch/drive_op_batch/token.rs` around lines 575 -
605, Add additional unit tests exercising Clone and Debug for other
TokenOperationType variants (e.g., TokenMintMany and
TokenSetPriceForDirectPurchase). For Clone: create instances of TokenMintMany
(with a non-empty Vec) and TokenSetPriceForDirectPurchase (with Some(price)),
call .clone(), and assert cloned fields (Vec length/contents and Option value)
match originals; name tests like test_token_operation_clone_mint_many and
test_token_operation_clone_set_price. For Debug: format!("{:?}", instance) for
the same variants and assert the debug string contains the variant name
("TokenMintMany", "TokenSetPriceForDirectPurchase") and representative data
(e.g., an element from the Vec or the price value); mimic the existing
test_token_operation_debug structure.
🤖 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/util/batch/drive_op_batch/token.rs`:
- Around line 314-606: Add unit tests covering the three missing
TokenOperationType variants and the Some case for price: implement tests named
like test_token_set_status_construction (construct
TokenOperationType::TokenSetStatus with test_token_id() and a TokenStatus
variant and assert fields), test_token_history_construction (construct
TokenOperationType::TokenHistory with test_token_id(), test_identity_id(), nonce
and a TokenEvent and assert token_id/owner_id/nonce),
test_token_mark_perpetual_release_construction (construct
TokenOperationType::TokenMarkPerpetualReleaseAsDistributed with test_token_id(),
test_recipient_id(), a RewardDistributionMoment value and assert fields), and
test_token_set_price_some (construct
TokenOperationType::TokenSetPriceForDirectPurchase with price:
Some(TokenPricingSchedule) and assert token_id and price.is_some()); use the
helper functions test_token_id()/test_identity_id()/test_recipient_id() and
existing enum types TokenStatus, TokenEvent, RewardDistributionMoment,
TokenPricingSchedule to build valid values.

---

Nitpick comments:
In
`@packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs`:
- Around line 277-284: The test test_new_stores_fields_correctly should
construct an InstantAssetLockProof using InstantAssetLockProof::new(...) instead
of using the raw fixture return value directly; obtain the expected
output_index, instant_lock, and transaction from
raw_instant_asset_lock_proof_fixture(None, None) (or from dedicated fixtures),
call InstantAssetLockProof::new(expected_output_index,
expected_instant_lock.clone(), expected_transaction.clone()), then assert that
proof.output_index() == expected_output_index, proof.instant_lock() ==
&expected_instant_lock, and proof.transaction() == &expected_transaction to
verify the constructor stored all fields correctly.

In `@packages/rs-drive/src/drive/votes/paths.rs`:
- Around line 572-579: Extract a small test helper (e.g.,
assert_path_vec_slice_parity or assert_vec_matches_slice) that accepts a Vec of
path elements and a slice (&[&[u8]] or whatever types used) and asserts equal
length and that each vec_elem.as_slice() == *slice_elem; then replace the
repeated for-loop blocks in functions like
test_vote_decisions_tree_path_vec_matches_slice_form, the tests around lines
595-601, 617-623, 640-646, 669-672, 721-724, 764-767, 794-797, 872-875, and
899-902 to call this helper (pass
vote_decisions_tree_path_vec()/vote_decisions_tree_path() and the analogous
path_vec/path pairs in other tests), removing duplicated loop logic. Ensure the
helper name is descriptive and used consistently across those test functions.

In `@packages/rs-drive/src/util/batch/drive_op_batch/token.rs`:
- Around line 575-605: Add additional unit tests exercising Clone and Debug for
other TokenOperationType variants (e.g., TokenMintMany and
TokenSetPriceForDirectPurchase). For Clone: create instances of TokenMintMany
(with a non-empty Vec) and TokenSetPriceForDirectPurchase (with Some(price)),
call .clone(), and assert cloned fields (Vec length/contents and Option value)
match originals; name tests like test_token_operation_clone_mint_many and
test_token_operation_clone_set_price. For Debug: format!("{:?}", instance) for
the same variants and assert the debug string contains the variant name
("TokenMintMany", "TokenSetPriceForDirectPurchase") and representative data
(e.g., an element from the Vec or the price value); mimic the existing
test_token_operation_debug structure.

In `@packages/rs-drive/src/util/object_size_info/document_info.rs`:
- Around line 503-527: Rename the test function test_estimated_size_for_owner_id
to a name that reflects it only verifies constant sizes (e.g.,
test_system_field_size_constants) and remove the unnecessary drop(info) call;
update the test declaration (the function name) that references DocumentInfo and
assert constants DEFAULT_HASH_SIZE_U16, U64_SIZE_U16, and U32_SIZE_U16 so the
test name matches its actual purpose.
- Around line 584-600: Add a unit test that covers the
DocumentEstimatedAverageSize variant for get_storage_flags_ref: construct a
DocumentInfo::DocumentEstimatedAverageSize instance (e.g. with an estimated size
value), call info.get_storage_flags_ref(), and assert it returns
StorageFlags::optional_default_as_ref(); reference get_storage_flags_ref,
DocumentEstimatedAverageSize, and StorageFlags::optional_default_as_ref() so the
test verifies this specific branch.
🪄 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: 31efb203-0b8d-4905-b3a9-af0e58c4eab9

📥 Commits

Reviewing files that changed from the base of the PR and between 59f233f and 9d06b38.

📒 Files selected for processing (4)
  • packages/rs-dpp/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs
  • packages/rs-drive/src/drive/votes/paths.rs
  • packages/rs-drive/src/util/batch/drive_op_batch/token.rs
  • packages/rs-drive/src/util/object_size_info/document_info.rs

Comment thread packages/rs-drive/src/util/batch/drive_op_batch/token.rs
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 97.67712% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.30%. Comparing base (59f233f) to head (c0cc03e).
⚠️ Report is 3 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...es/rs-drive/src/util/batch/drive_op_batch/token.rs 93.96% 14 Missing ⚠️
...s-drive/src/util/object_size_info/document_info.rs 97.28% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3452      +/-   ##
============================================
+ Coverage     83.13%   83.30%   +0.16%     
============================================
  Files          2621     2621              
  Lines        270434   272169    +1735     
============================================
+ Hits         224833   226726    +1893     
+ Misses        45601    45443     -158     
Components Coverage Δ
dpp 76.18% <100.00%> (+0.06%) ⬆️
drive 84.19% <97.26%> (+0.13%) ⬆️
drive-abci 87.03% <ø> (+0.28%) ⬆️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.01% <ø> (+<0.01%) ⬆️
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 55.66% <ø> (ø)
🚀 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.

Add tests for TokenSetStatus, TokenHistory,
TokenMarkPerpetualReleaseAsDistributed, and TokenSetPriceForDirectPurchase
with Some(price).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer merged commit f733c4d into v3.1-dev Apr 8, 2026
38 checks passed
@QuantumExplorer QuantumExplorer deleted the test/drive-votes-paths-docinfo branch April 8, 2026 07:29
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