Skip to content

test: cover drive/document, votes, queries, object_size_info, and lowcov#3513

Merged
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/coverage-drive-document-votes-and-misc
Apr 23, 2026
Merged

test: cover drive/document, votes, queries, object_size_info, and lowcov#3513
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/coverage-drive-document-votes-and-misc

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Apr 21, 2026

Issue being fixed or feature implemented

Seventh PR in the push toward 90% global coverage. After #3503#3512 we were at 86.77%. This PR targets ~4,000 missed lines across 4 focus areas and brings the project to 87.04%.

What was done?

181 new unit tests across 30 files.

Target Prev cov Missed Tests added
rs-drive/drive/document (error paths only) 83% 1572 11
rs-drive/drive/votes 81% 517 37
rs-drive/state_transition_action/identity 82% 294 10
rs-drive-abci/query/token_queries + system + voting 81–83% 1000 21
rs-dpp/data_contract/config 76% 169 11
rs-drive/util/object_size_info 76% 160 50+
rs-dpp/voting/contender_structs 68% 135 4
rs-drive/drive/balances 73% 110 10
rs-dpp/voting/vote_info_storage 69% 100 26
rs-drive-abci/platform_types/platform 46% 119 5

Highlighted coverage wins

drive/document — error-path focus: DataContractNotFound + unknown-document-type + malformed-bytes rejection paths in add_document_v0 / delete_document_for_contract_id_* / update_document_for_contract_id_* / update_document_with_serialization_for_contract_v0, plus apply=false estimation-costs branches.

drive/votesResourceVoteChoice::to_key all 3 variants; TreePath for ResourceVote error branches (contract-id mismatch, unknown doc type, unknown index name); TreePathStorageForm::try_from_tree_path exhaustive error matrix across two impls; resolve_with_contract UnknownVersionMismatch dispatch error; ContestedDocumentResourceVotePoll index/document_type accessor errors + owned/borrowed parity.

state_transition_action/identityidentity_create_from_addresses + identity_topup_from_addresses transformers: empty-inputs ValueError, input-sum overflow, output > inputs overflow, success with and without output.

query modulesprove: true paths (previously untested in 5 voting modules), InvalidLimit propagation for token_pre_programmed_distributions, u16::MAX range guard in finalized_epoch_infos, limit-rejection in contested_resource_identity_votes and vote_polls_by_end_date_query. Fixed two mis-named count_* tests in contested_resource_vote_state to reflect that they pin validation ordering (contract_id check runs before count), not the count branch itself.

voting/vote_info_storagefinalize_vote_poll guards (NotStarted/Locked), all three ContestedDocumentVotePollWinnerInfo branches, last_locked_votes + last_abstain_votes aggregation, bincode roundtrip, all ContestedDocumentVotePollStoredInfoV0Getters proxies.

util/object_size_info (50+ tests across 6 files) — drive_key_info/key_value_info/path_info/path_key_info/path_key_element_info/contract_info len/is_empty/convert branches, push error paths (fixed-size, KeySize-into-Vec), KeyUnknownElementSize rejection, DocumentTypeInfo::resolve missing-type errors.

drive/balances — path-helper consistency (array form matches vec form); add_to_system_credits + remove_from_system_credits roundtrip under a real Drive; zero-amount no-op.

platform_types/platform — Debug impls, From<&PlatformRef> for PlatformStateRef pointer-equality forwarding, open-with-latest-protocol success, committed_block_height_guard init.

CodeRabbit review addressed

8 review comments handled in the follow-up commit, all test-quality tightenings:

  • data_contract/config reads_booleans_from_map: use distinct (true, false) / (false, true) pairs so a key mix-up would fail.
  • voting/vote_info_storage (3 sites) + util/object_size_info (~13 sites): wrap bare matches!(...) in assert!(matches!(...)) — the bare form returns a discarded bool, making the tests no-ops.
  • drive/document/delete test_delete_nonexistent_document_without_apply_estimation_costs: the estimation branch actually succeeds (fake cost estimates, not real grove ops). Assert success + non-zero fee estimate instead of dropping the result.
  • query/voting/contested_resource_vote_state count_* tests: renamed to reflect they pin validation ordering, and tightened the second assertion to match the same InvalidArgument("contract_id …") as the first.

Follow-up observations

Two things surfaced during coverage work that deserve visibility but are out of scope for this PR:

V0 config parser quirk — consensus-frozen, NOT a bug

get_contract_configuration_properties_v0 at packages/rs-dpp/src/data_contract/config/v0/mod.rs:177-185 reads the decryption bounded-key field from REQUIRES_IDENTITY_ENCRYPTION_BOUNDED_KEY (V1 at v1/mod.rs:140 reads from the correct key).

Originally flagged in the commit message as a potential bug. That characterization was wrong — this is consensus-frozen V0 parser behavior. Changing it would risk a fork on any node replaying historical V0 contracts. #3514 pins the current behavior in place with lock-in tests and an in-code CONSENSUS-FROZEN BUG comment so it doesn't get "fixed" later.

InvalidLimit error surface in query modules (minor design observation)

Multiple query modules propagate InvalidLimit via a top-level Err(Error::Drive(Query(InvalidLimit))) instead of wrapping it in a QueryValidationResult::new_with_error(...). This is inconsistent with sibling validators in the same files, and means gRPC clients see a transport-level error for limit=0 / limit>max rather than a structured validation response. Not incorrect — just inconsistent. Worth a small unifying PR but not required here.

How Has This Been Tested?

  • cargo check --tests -p dpp -p drive -p drive-abci — clean
  • cargo fmt -p dpp -p drive -p drive-abci — clean
  • Per-target test runs (all pass): drive::document, drive::votes, state_transition_action::identity, query::token_queries, query::system, query::voting, data_contract::config, voting::contender_structs, voting::vote_info_storage, util::object_size_info, drive::balances, platform_types::platform.
  • Codecov: project 86.77% → 87.04% (+0.27%), patch 98%+.

Breaking Changes

None. Tests only.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Add 181 new unit tests across 30 files targeting the biggest
remaining gaps.

Per-target breakdown:

- rs-drive/drive/document (83% → error-path focus, 11 tests):
  DataContractNotFound + unknown-document-type + malformed-bytes
  rejection paths in add_document_v0 /
  delete_document_for_contract_id / delete_document_for_contract_id
  _with_named_type_operations / update_document_for_contract_id /
  update_document_with_serialization_for_contract, plus apply=false
  estimation-costs branches.

- rs-drive/drive/votes (81% → 37 tests): ResourceVoteChoice::to_key
  for all 3 variants; TreePath for ResourceVote error branches
  (contract-id mismatch, unknown doc type, unknown index name);
  TreePathStorageForm::try_from_tree_path exhaustive error matrix
  across two impls (length, empty/wrong bytes, non-UTF-8 doc type,
  VOTE_DECISIONS_TREE_KEY NotSupported); resolve_with_contract
  UnknownVersionMismatch dispatch error; ContestedDocumentResource
  VotePoll index/document_type accessor errors + owned/borrowed
  parity.

- rs-drive/state_transition_action/identity (82% → 10 tests):
  identity_create_from_addresses + identity_topup_from_addresses
  transformers — empty-inputs ValueError, input-sum overflow,
  output > inputs overflow, success with and without output.

- rs-drive-abci/query/token_queries + query/system + query/voting
  (81-83% → 21 tests): token_pre_programmed_distributions
  limit=0/over-max; system/path_elements missing-key + empty-keys;
  system/finalized_epoch_infos equal-indexes-both-included +
  u16::MAX range guard; voting/contested_resource_identity_votes
  prove + descending start_at + limit-rejection; contested_resource
  _vote_state prove + count zero/over-u16; contested_resource_
  voters_for_identity prove + validation ordering; contested_
  resources prove + short-contract-id identifier-byte-length error;
  vote_polls_by_end_date_query both limit-rejection branches + prove.

- rs-dpp/data_contract/config (76% → 11 tests): V0 + V1 bincode
  roundtrips including sized_integer_types field; from_value
  empty-object defaults; get_contract_configuration_properties
  boolean reads + fallback + non-bool-value error.

- rs-dpp/voting/contender_structs (68% → 4 tests):
  FinalizedResourceVoteChoicesWithVoterInfo Display + bincode
  roundtrip; FinalizedContenderWithSerializedDocument defaults;
  TryFrom<ContenderWithSerializedDocument> error paths (missing
  serialized_document, missing vote_tally) + happy path.

- rs-dpp/voting/vote_info_storage (69% → 26 tests):
  finalize_vote_poll guards (NotStarted/Locked), all three
  ContestedDocumentVotePollWinnerInfo branches (NoWinner with/
  without prior locks, WonByIdentity, Locked), last_locked_votes +
  last_abstain_votes aggregation, Display for status variants,
  bincode roundtrip, new/update_to_latest_version, all
  ContestedDocumentVotePollStoredInfoV0Getters proxies.

- rs-drive/util/object_size_info (76% → 50+ tests):
  drive_key_info variants len/is_empty/to_owned_key_info/
  to_key_info/add_path_* routing; key_value_info
  as_key_ref_request CorruptedCodeExecution branch; path_info
  push errors (fixed-size + KeySize-into-Vec) + convert_to_key_
  info_path; path_key_info TryFrom empty-vec error + 5-variant
  len/is_empty/cache/convert/Display; path_key_element_info
  from_*_and_key_element across three branches +
  KeyUnknownElementSize rejection; contract_info accessors +
  DocumentTypeInfo::resolve missing-type errors.

- rs-drive/drive/balances (73% → 10 tests): all path-helper
  functions shape-checked (array form matches vec form);
  add_to_system_credits + remove_from_system_credits roundtrip
  via setup_drive_with_initial_state_structure; zero-amount no-op.

- rs-drive-abci/platform_types/platform (46% → 5 tests): Debug
  impls, From<&PlatformRef> for PlatformStateRef pointer-
  equality forwarding, open-with-latest-protocol success,
  committed_block_height_guard init.

A latent production bug in data_contract/config/v0/mod.rs
(requires_identity_encryption_bounded_key and
requires_identity_decryption_bounded_key both read from same map
key — v1 has the correct code) was flagged via a follow-up task
and is out of scope for this PR.

All tests pass.

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

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

This PR adds extensive unit tests across rs-dpp and rs-drive packages (many modules), covering data-contract config, voting structures, drive queries, document operations, vote path/storage forms, state-transition transformers, and object-size utilities. All changes are test-only; no production APIs or logic were modified.

Changes

Cohort / File(s) Summary
Data Contract & Voting Core
packages/rs-dpp/src/data_contract/config/mod.rs, packages/rs-dpp/src/voting/contender_structs/mod.rs, packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_stored_info/mod.rs, packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_stored_info/v0/mod.rs, packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_winner_info/mod.rs
Added unit tests for DataContractConfig (bincode round-trips, defaults), finalized vote contenders (Display, equality, bincode round-trips), contested vote-poll stored info (lifecycle, finalize logic, serialization), and poll winner enum (Display, equality, serde/bincode).
Platform & Query Validation
packages/rs-drive-abci/src/platform_types/platform/mod.rs, packages/rs-drive-abci/src/query/system/finalized_epoch_infos/v0/mod.rs, packages/rs-drive-abci/src/query/system/path_elements/v0/mod.rs, packages/rs-drive-abci/src/query/token_queries/token_pre_programmed_distributions/v0/mod.rs, packages/rs-drive-abci/src/query/voting/contested_resource_identity_votes/v0/mod.rs, packages/rs-drive-abci/src/query/voting/contested_resource_vote_state/v0/mod.rs, packages/rs-drive-abci/src/query/voting/contested_resource_voters_for_identity/v0/mod.rs, packages/rs-drive-abci/src/query/voting/contested_resources/v0/mod.rs, packages/rs-drive-abci/src/query/voting/vote_polls_by_end_date_query/v0/mod.rs
Added tests for Platform/PlatformStateRef debug and conversions, protocol version init, finalized-epoch and path-element query edge cases, token distribution limit validation, and multiple contested-voting query validation/prove-mode and limit-ordering scenarios.
Drive Document Operations
packages/rs-drive/src/drive/document/delete/mod.rs, packages/rs-drive/src/drive/document/insert/mod.rs, packages/rs-drive/src/drive/document/update/mod.rs
Added error-path tests asserting proper error variants for missing contracts, invalid document types, malformed serialized documents, and estimation-only delete behavior.
Drive Balances & Vote Paths
packages/rs-drive/src/drive/balances/mod.rs, packages/rs-drive/src/drive/votes/mod.rs, packages/rs-drive/src/drive/votes/resolved/vote_polls/contested_document_resource_vote_poll/mod.rs, packages/rs-drive/src/drive/votes/storage_form/contested_document_resource_storage_form/mod.rs, packages/rs-drive/src/drive/votes/storage_form/vote_storage_form/mod.rs
Added tests for balance path structures and totals, credits add/remove flows, resource vote key derivation, tree-path construction/errors (contract mismatch, unknown types/indexes), storage-form parsing/errors, version mismatch, and deterministic serialization/hash parity.
State Transition Action Transformers
packages/rs-drive/src/state_transition_action/identity/identity_create_from_addresses/v0/transformer.rs, packages/rs-drive/src/state_transition_action/identity/identity_topup_from_addresses/v0/transformer.rs
Added tests for transformers covering empty-inputs, overflow detection, output vs inputs arithmetic, and resulting fund/topup amount semantics.
Object Size Info Utilities
packages/rs-drive/src/util/object_size_info/contract_info.rs, packages/rs-drive/src/util/object_size_info/drive_key_info.rs, packages/rs-drive/src/util/object_size_info/key_value_info.rs, packages/rs-drive/src/util/object_size_info/path_info.rs, packages/rs-drive/src/util/object_size_info/path_key_element_info.rs, packages/rs-drive/src/util/object_size_info/path_key_info.rs
Added comprehensive tests for contract resolution wrappers (owned/borrowed/Arc), document-type lookup errors, DriveKeyInfo behavior, KeyValueInfo key-ref/max-size handling, PathInfo push/len/convert behavior, PathKeyElementInfo variant mapping and errors, and PathKeyInfo parsing/len/display/cache interactions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A hop, a test, a careful trace,
Through votes and contracts I boundlessly race,
I check each path and edge with delight,
Ensuring each corner behaves just right.
Hooray for tests — a coder's bright light!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding comprehensive test coverage across multiple modules including drive/document, votes, queries, and object_size_info to improve code coverage.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 test/coverage-drive-document-votes-and-misc

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

⏳ Review in progress (commit 4da56df)

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

🧹 Nitpick comments (2)
packages/rs-drive-abci/src/query/voting/contested_resource_voters_for_identity/v0/mod.rs (1)

365-393: Test name doesn't match what's being asserted.

test_query_voters_count_zero_rejected asserts DataContractNotFound, not a count-rejection error, because contract lookup runs before count validation (as your own comment notes). The test therefore doesn't actually cover the count=0 → "out of bounds of [1, ...]" branch — it only pins the current validation order. Consider renaming it (e.g., test_query_voters_count_zero_hidden_by_contract_lookup_order) to avoid misleading future readers, or — if covering the count guard is the goal — add a fixture with a real contract so the count check actually executes.

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

In
`@packages/rs-drive-abci/src/query/voting/contested_resource_voters_for_identity/v0/mod.rs`
around lines 365 - 393, The test test_query_voters_count_zero_rejected is
misleading because it asserts a DataContractNotFound error (contract lookup runs
before count validation); either rename the test to reflect that behavior (e.g.,
test_query_voters_count_zero_hidden_by_contract_lookup_order) or modify the
fixture so count validation actually runs: use setup_platform to provide a real
contract/valid contract_id (or set contract_id to a known existing id) so that
calling query_contested_resource_voters_for_identity_v0 with
GetContestedResourceVotersForIdentityRequestV0 and count: Some(0) triggers the
out-of-bounds/count validation branch instead of DataContractNotFound; update
the assertion accordingly.
packages/rs-drive-abci/src/query/voting/contested_resource_identity_votes/v0/mod.rs (1)

316-365: Fragile assertions via Debug string matching; consider matching the error variant instead.

Matching format!("{:?}", err).contains("InvalidLimit") || contains("limit") will silently keep passing even if the error becomes something unrelated that happens to contain the substring "limit" (e.g., a message mentioning "client limit reached"). Since both paths go through the .ok_or(drive::error::Error::Query(QuerySyntaxError::InvalidLimit(...)))? construction, a structural matches! on the Error/QuerySyntaxError::InvalidLimit variant would be far more robust and future-proof. Non-blocking; fine as-is for coverage, but worth tightening.

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

In
`@packages/rs-drive-abci/src/query/voting/contested_resource_identity_votes/v0/mod.rs`
around lines 316 - 365, The tests
test_query_contested_resource_identity_votes_limit_above_max_is_error and
test_query_contested_resource_identity_votes_limit_zero_is_error use fragile
Debug string matching on the returned error; change them to assert the actual
error variant instead by pattern-matching the result of
platform.query_contested_resource_identity_votes_v0(...) for the expected
drive::error::Error::Query(QuerySyntaxError::InvalidLimit(..)) (or using
matches! on that pattern) rather than checking format!("{:?}", err). This keeps
the assertion robust to message changes while still verifying the InvalidLimit
variant raised by GetContestedResourceIdentityVotesRequestV0 handling.
🤖 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-dpp/src/data_contract/config/mod.rs`:
- Around line 664-675: The test reads_booleans_from_map uses identical booleans
which masks key mix-ups; update the test to use distinct values (e.g., call
make_contract_map(true, false) and assert cfg.can_be_deleted() is true and
cfg.readonly() is false), and ideally add the opposite case
(make_contract_map(false, true)) to catch swapped-key bugs; locate the test
reads_booleans_from_map and the helper make_contract_map and change the input
boolean pairs and corresponding assertions for
DataContractConfig::get_contract_configuration_properties to validate both
fields separately.

In
`@packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_stored_info/mod.rs`:
- Around line 302-305: The current matches! invocation on
info.vote_poll_status_ref() with ContestedDocumentVotePollStatus::Started(_) is
evaluated but its result is discarded, so the expectation isn't enforced; change
it to assert!(matches!(info.vote_poll_status_ref(),
ContestedDocumentVotePollStatus::Started(_))) (or otherwise assert the match) so
the test actually fails when the status is not Started; locate the check around
vote_poll_status_ref() in contested_document_vote_poll_stored_info::mod.rs and
wrap the matches! call in an assert.
- Around line 229-236: The test currently calls matches!(...) on
ContestedDocumentVotePollStoredInfo::V0(v0) and discards the bool result, making
the check a no-op; change the statement to assert!(matches!(v0.vote_poll_status,
ContestedDocumentVotePollStatus::Started(_))) so the test actually fails when
the variant is different—update the code in the match arm handling
ContestedDocumentVotePollStoredInfo::V0 to use assert! around the matches!
expression referencing v0.vote_poll_status and
ContestedDocumentVotePollStatus::Started(_) .

In
`@packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_stored_info/v0/mod.rs`:
- Around line 373-381: The test currently discards the boolean returned by
matches!(err, ProtocolError::CorruptedCodeExecution(_)) so the error variant
isn't asserted; update the assertion that calls info.finalize_vote_poll(...) to
assert that the error matches ProtocolError::CorruptedCodeExecution(_) (use
assert!(matches!(err, ProtocolError::CorruptedCodeExecution(_)))) and, like the
sibling test around lines 358-363, optionally also inspect the inner
message/payload of the CorruptedCodeExecution error to ensure the expected text
when state is Locked; reference the finalize_vote_poll call, the err binding,
and ProtocolError::CorruptedCodeExecution for locating and changing the test.

In
`@packages/rs-drive-abci/src/query/voting/contested_resource_vote_state/v0/mod.rs`:
- Around line 348-400: The two tests
(test_query_contested_resource_vote_state_count_zero_rejected and
test_query_contested_resource_vote_state_count_out_of_bounds_u16) never reach
the count validation because contract_id: vec![0; 8] fails earlier; either (A)
keep the current invalid-contract_id intent but rename the tests to indicate
they pin validation ordering and tighten the second test's assertion to expect
the same InvalidArgument about contract_id (match
QueryError::InvalidArgument(msg) if msg.contains("contract_id must be a valid
identifier")), or (B) change both tests to supply a valid 32-byte contract_id
and ensure a fixture contract exists in the test state so the request passes
contract_id.try_into() and then assert the actual count validation messages from
query_contested_resource_vote_state_v0 (for count = Some(0) assert errors
contains InvalidArgument with "limit out of bounds" or similar; for count >
u16::MAX assert errors contains "out of bounds of" / "limit out of bounds"). Use
the structs GetContestedResourceVoteStateRequestV0 and function
query_contested_resource_vote_state_v0 to locate where to modify the test inputs
and assertions.

In `@packages/rs-drive/src/drive/document/delete/mod.rs`:
- Around line 1422-1448: The test
test_delete_nonexistent_document_without_apply_estimation_costs currently
discards the result of drive.delete_document_for_contract; instead assert the
dry-run fails by checking the Result is an error (e.g.,
assert!(result.is_err())), so the estimation-only branch exercised by
delete_document_for_contract with apply=false is actually protected; keep the
existing call parameters and replace the unused binding with an assertion on
result.is_err() referencing delete_document_for_contract and the test name.

In `@packages/rs-drive/src/util/object_size_info/drive_key_info.rs`:
- Around line 219-231: The tests currently call matches! on the result of
DriveKeyInfo::KeyRef(...).add_fixed_size_path(path) and
DriveKeyInfo::KeySize(...).add_fixed_size_path(path) but ignore the boolean
result; change those standalone matches! calls to assert!(matches!(...)) so the
test will fail when the returned PathKeyInfo variant is incorrect (do the same
for the other similar blocks where add_fixed_size_path is used and matched
against PathFixedSizeKeyRef and PathKeySize).

In `@packages/rs-drive/src/util/object_size_info/path_key_element_info.rs`:
- Around line 128-138: The tests call matches!(...) but ignore its boolean
result; update each standalone matches! usage (e.g., inside fn
from_path_info_vec_with_key_element_produces_ref_element and the other test
blocks covering lines ~169-190, 192-219, 221-231, 246-292) to
assert!(matches!(...)) so the test fails when the variant is wrong; specifically
wrap the matches!(res, PathKeyRefElement(_)) and similar variant checks after
PathKeyElementInfo::from_path_info_and_key_element (and other calls returning
PathKeyElementInfo) with assert! to ensure the boolean is asserted.

---

Nitpick comments:
In
`@packages/rs-drive-abci/src/query/voting/contested_resource_identity_votes/v0/mod.rs`:
- Around line 316-365: The tests
test_query_contested_resource_identity_votes_limit_above_max_is_error and
test_query_contested_resource_identity_votes_limit_zero_is_error use fragile
Debug string matching on the returned error; change them to assert the actual
error variant instead by pattern-matching the result of
platform.query_contested_resource_identity_votes_v0(...) for the expected
drive::error::Error::Query(QuerySyntaxError::InvalidLimit(..)) (or using
matches! on that pattern) rather than checking format!("{:?}", err). This keeps
the assertion robust to message changes while still verifying the InvalidLimit
variant raised by GetContestedResourceIdentityVotesRequestV0 handling.

In
`@packages/rs-drive-abci/src/query/voting/contested_resource_voters_for_identity/v0/mod.rs`:
- Around line 365-393: The test test_query_voters_count_zero_rejected is
misleading because it asserts a DataContractNotFound error (contract lookup runs
before count validation); either rename the test to reflect that behavior (e.g.,
test_query_voters_count_zero_hidden_by_contract_lookup_order) or modify the
fixture so count validation actually runs: use setup_platform to provide a real
contract/valid contract_id (or set contract_id to a known existing id) so that
calling query_contested_resource_voters_for_identity_v0 with
GetContestedResourceVotersForIdentityRequestV0 and count: Some(0) triggers the
out-of-bounds/count validation branch instead of DataContractNotFound; update
the assertion accordingly.
🪄 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: f87c70a9-87af-4915-9681-0be88fe66b21

📥 Commits

Reviewing files that changed from the base of the PR and between c9cc329 and 716e79a.

📒 Files selected for processing (30)
  • packages/rs-dpp/src/data_contract/config/mod.rs
  • packages/rs-dpp/src/voting/contender_structs/mod.rs
  • packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_stored_info/mod.rs
  • packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_stored_info/v0/mod.rs
  • packages/rs-dpp/src/voting/vote_info_storage/contested_document_vote_poll_winner_info/mod.rs
  • packages/rs-drive-abci/src/platform_types/platform/mod.rs
  • packages/rs-drive-abci/src/query/system/finalized_epoch_infos/v0/mod.rs
  • packages/rs-drive-abci/src/query/system/path_elements/v0/mod.rs
  • packages/rs-drive-abci/src/query/token_queries/token_pre_programmed_distributions/v0/mod.rs
  • packages/rs-drive-abci/src/query/voting/contested_resource_identity_votes/v0/mod.rs
  • packages/rs-drive-abci/src/query/voting/contested_resource_vote_state/v0/mod.rs
  • packages/rs-drive-abci/src/query/voting/contested_resource_voters_for_identity/v0/mod.rs
  • packages/rs-drive-abci/src/query/voting/contested_resources/v0/mod.rs
  • packages/rs-drive-abci/src/query/voting/vote_polls_by_end_date_query/v0/mod.rs
  • packages/rs-drive/src/drive/balances/mod.rs
  • packages/rs-drive/src/drive/document/delete/mod.rs
  • packages/rs-drive/src/drive/document/insert/mod.rs
  • packages/rs-drive/src/drive/document/update/mod.rs
  • packages/rs-drive/src/drive/votes/mod.rs
  • packages/rs-drive/src/drive/votes/resolved/vote_polls/contested_document_resource_vote_poll/mod.rs
  • packages/rs-drive/src/drive/votes/storage_form/contested_document_resource_storage_form/mod.rs
  • packages/rs-drive/src/drive/votes/storage_form/vote_storage_form/mod.rs
  • packages/rs-drive/src/state_transition_action/identity/identity_create_from_addresses/v0/transformer.rs
  • packages/rs-drive/src/state_transition_action/identity/identity_topup_from_addresses/v0/transformer.rs
  • packages/rs-drive/src/util/object_size_info/contract_info.rs
  • packages/rs-drive/src/util/object_size_info/drive_key_info.rs
  • packages/rs-drive/src/util/object_size_info/key_value_info.rs
  • packages/rs-drive/src/util/object_size_info/path_info.rs
  • packages/rs-drive/src/util/object_size_info/path_key_element_info.rs
  • packages/rs-drive/src/util/object_size_info/path_key_info.rs

Comment thread packages/rs-dpp/src/data_contract/config/mod.rs
Comment on lines +1422 to +1448
#[test]
fn test_delete_nonexistent_document_without_apply_estimation_costs() {
// Delete a nonexistent document with apply=false to exercise the
// estimation-costs branch (different control flow than the apply=true
// branch already covered).
let (drive, contract) = setup_dashpay("delete-nonexist-estimate", true);
let platform_version = PlatformVersion::latest();

let document_id = Identifier::random();

// With apply=false the code takes the estimated_costs_only_with_layer_info
// = Some(HashMap::new()) branch. The document does not exist, so we
// expect an error, but a different one than the stateful path.
let result = drive.delete_document_for_contract(
document_id,
&contract,
"profile",
BlockInfo::default(),
false,
None,
platform_version,
Some(&EPOCH_CHANGE_FEE_VERSION_TEST),
);

// Either succeeds (estimation path can be more permissive) or errors;
// whichever happens, it exercises the previously-uncovered branch.
let _ = result;
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 | 🟡 Minor

Assert the expected dry-run failure instead of discarding the result.

Line 1448 makes this test pass whether delete_document_for_contract succeeds or fails, despite the comment saying the nonexistent document should error. Add an assertion so the test protects the branch it covers.

Proposed test assertion
         let result = drive.delete_document_for_contract(
             document_id,
             &contract,
             "profile",
@@
             platform_version,
             Some(&EPOCH_CHANGE_FEE_VERSION_TEST),
         );
 
-        // Either succeeds (estimation path can be more permissive) or errors;
-        // whichever happens, it exercises the previously-uncovered branch.
-        let _ = result;
+        assert!(
+            result.is_err(),
+            "expected dry-run delete of nonexistent document to fail, got {result:?}"
+        );
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn test_delete_nonexistent_document_without_apply_estimation_costs() {
// Delete a nonexistent document with apply=false to exercise the
// estimation-costs branch (different control flow than the apply=true
// branch already covered).
let (drive, contract) = setup_dashpay("delete-nonexist-estimate", true);
let platform_version = PlatformVersion::latest();
let document_id = Identifier::random();
// With apply=false the code takes the estimated_costs_only_with_layer_info
// = Some(HashMap::new()) branch. The document does not exist, so we
// expect an error, but a different one than the stateful path.
let result = drive.delete_document_for_contract(
document_id,
&contract,
"profile",
BlockInfo::default(),
false,
None,
platform_version,
Some(&EPOCH_CHANGE_FEE_VERSION_TEST),
);
// Either succeeds (estimation path can be more permissive) or errors;
// whichever happens, it exercises the previously-uncovered branch.
let _ = result;
#[test]
fn test_delete_nonexistent_document_without_apply_estimation_costs() {
// Delete a nonexistent document with apply=false to exercise the
// estimation-costs branch (different control flow than the apply=true
// branch already covered).
let (drive, contract) = setup_dashpay("delete-nonexist-estimate", true);
let platform_version = PlatformVersion::latest();
let document_id = Identifier::random();
// With apply=false the code takes the estimated_costs_only_with_layer_info
// = Some(HashMap::new()) branch. The document does not exist, so we
// expect an error, but a different one than the stateful path.
let result = drive.delete_document_for_contract(
document_id,
&contract,
"profile",
BlockInfo::default(),
false,
None,
platform_version,
Some(&EPOCH_CHANGE_FEE_VERSION_TEST),
);
assert!(
result.is_err(),
"expected dry-run delete of nonexistent document to fail, got {result:?}"
);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-drive/src/drive/document/delete/mod.rs` around lines 1422 - 1448,
The test test_delete_nonexistent_document_without_apply_estimation_costs
currently discards the result of drive.delete_document_for_contract; instead
assert the dry-run fails by checking the Result is an error (e.g.,
assert!(result.is_err())), so the estimation-only branch exercised by
delete_document_for_contract with apply=false is actually protected; keep the
existing call parameters and replace the unused binding with an assertion on
result.is_err() referencing delete_document_for_contract and the test name.

Comment thread packages/rs-drive/src/util/object_size_info/drive_key_info.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 95.97969% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.04%. Comparing base (c9cc329) to head (4da56df).
⚠️ Report is 1 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...rm/contested_document_resource_storage_form/mod.rs 88.81% 16 Missing ⚠️
.../drive/votes/storage_form/vote_storage_form/mod.rs 82.22% 16 Missing ⚠️
packages/rs-drive/src/drive/document/update/mod.rs 93.60% 8 Missing ⚠️
...polls/contested_document_resource_vote_poll/mod.rs 92.15% 8 Missing ⚠️
packages/rs-drive/src/drive/document/delete/mod.rs 93.75% 5 Missing ⚠️
...y/identity_create_from_addresses/v0/transformer.rs 94.38% 5 Missing ⚠️
packages/rs-drive/src/drive/votes/mod.rs 95.87% 4 Missing ⚠️
...-drive/src/util/object_size_info/drive_key_info.rs 96.26% 4 Missing ⚠️
...es/rs-drive/src/util/object_size_info/path_info.rs 95.55% 4 Missing ⚠️
...contested_document_vote_poll_stored_info/v0/mod.rs 98.82% 3 Missing ⚠️
... and 10 more
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3513      +/-   ##
============================================
+ Coverage     86.77%   87.04%   +0.26%     
============================================
  Files          2474     2474              
  Lines        281241   283604    +2363     
============================================
+ Hits         244048   246863    +2815     
+ Misses        37193    36741     -452     
Components Coverage Δ
dpp 86.23% <99.12%> (+0.32%) ⬆️
drive 86.22% <94.10%> (+0.38%) ⬆️
drive-abci 89.02% <97.84%> (+0.12%) ⬆️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.10% <ø> (ø)
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.

Tighten 8 test assertions per CodeRabbit feedback:

- data_contract/config/mod.rs reads_booleans_from_map: iterate over
  (true,false)/(false,true) pairs so a key mix-up (reading readonly
  from can_be_deleted's key, or vice versa) would fail the test.
- voting/vote_info_storage/.../mod.rs (2 sites) and v0/mod.rs:
  wrap bare `matches!(...)` in `assert!(matches!(...))`. The bare
  form returns a discarded bool so the tests were no-ops — they
  would pass with any variant.
- drive/document/delete test_delete_nonexistent_document_without_
  apply_estimation_costs: the estimation branch actually succeeds
  for nonexistent documents (uses fake cost estimates instead of
  real grove ops). Assert that success + non-zero fee estimate
  rather than ignoring the result.
- util/object_size_info/drive_key_info.rs + path_key_element_info
  .rs: same `matches!` → `assert!(matches!(..))` fix across ~13
  call sites that were silently passing.
- query/voting/contested_resource_vote_state v0: the two `count_*`
  tests both used a short (8-byte) contract_id which fails
  validation before the count branch. Renamed them to reflect
  what they actually test (validation ORDERING — contract_id check
  runs before count), and tightened the second test's assertion
  from `!errors.is_empty()` to the same specific `InvalidArgument
  ("contract_id must be a valid identifier")` match.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer merged commit 3eaf388 into v3.1-dev Apr 23, 2026
103 of 108 checks passed
@QuantumExplorer QuantumExplorer deleted the test/coverage-drive-document-votes-and-misc branch April 23, 2026 03:39
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