Skip to content

test: cover drive contract/tokens, rs-dpp document, drive-abci platform_events#3523

Merged
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/coverage-contract-tokens-document-events-v2
Apr 23, 2026
Merged

test: cover drive contract/tokens, rs-dpp document, drive-abci platform_events#3523
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/coverage-contract-tokens-document-events-v2

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Ninth PR in the push toward 90% global coverage. After #3503#3516 we're at 87.30%. This PR targets ~3,500 missed lines across 4 focus areas (lowest-coverage modules still remaining), applying the lesson from prior PRs that error-path tests move Codecov where accessor tests don't.

What was done?

119 new unit tests across 37 files.

Target Prev cov Missed Tests added
rs-drive/drive/contract/insert 67% 399 12
rs-drive/drive/contract/update 73% 278 12
rs-drive/drive/tokens/balance 81% 414 8
rs-drive/drive/tokens/system 82% 304 7
rs-dpp/document/v0 78% 532 19
rs-dpp/document/extended_document 78% 307 13
rs-dpp/state_transition/mod.rs 81% 287 22
rs-drive-abci/execution/platform_events/withdrawals 82% 219 9
rs-drive-abci/execution/platform_events/protocol_upgrade 86% 290 3
rs-drive-abci/execution/platform_events/core_chain_lock 75% 212 3
rs-drive-abci/execution/platform_events/state_transition_processing 81% 258 11

Highlighted coverage wins

drive/contract/insert (+12 tests)insert_contract_v1 base_supply > i64::MAX guard returning CriticalCorruptedCreditsCodeExecution; token/group/keyword/description estimation branches via apply=false; multi-token insertion loop with distinct token ids; add_contract_to_storage_v0 history + estimate + first_insert combinations.

drive/contract/update (+12 tests)UpdatingReadOnlyImmutableContract (distinct from ChangingContractToReadOnly); apply=false delegates to insert; new-document-type creation branch; update_contract_v1 token/group addition via update; keywords/description deltas via update_contract (not the dedicated APIs); update_keywords identical-keywords no-op; partial add+remove with overlap.

drive/tokens/balance (+8 tests)add_to_previous_token_balance i64::MAX+1 overflow guard on insert + replace paths; checked_add on large existing; remove_from_identity_token_balance drain-to-zero + IdentityInsufficientBalance underflow + missing-entry CorruptedCodeExecution; fetch_identity_token_balance PathKeyNotFound → None, unknown-identity Ok(None), stateless mode returns Some(0); fetch_identities_token_balances aggregated mixed-balances.

drive/tokens/system (+7 tests) — estimation-mode HashMap population across add_to_token_total_supply / remove_from_token_total_supply / fetch_token_total_supply / fetch_token_total_aggregated_identity_balances; allow_first_mint insert path; multi-token independence across a single contract; prove_token_total_supply_and_aggregated_identity_balances supply-without-balances mismatch detection + matched-supply after multiple mint/add pairs.

rs-dpp/document/v0 (+19 tests)Display properties-iteration with multiple keys + mixed optional fields; DocumentHashV0Method::hash_v0 determinism and inequality; full PartialEq per-field arm coverage; bump_revision zero-increment + MAX saturation; complete Getters/Setters round-trip; Debug format invariants.

rs-dpp/document/extended_document (+13 tests)token_payment_info Some(_) branches in to_map_value, into_map_value, to_pretty_json, from_document_with_additional_info; set_untrusted binary-path replace + non-byte-value to_identifier_bytes()? error; hash / to_pretty_json / can_be_modified error paths through document_type()? with unknown type; from_trusted_platform_value data_contract_id override vs fallback; non-map-value rejection via into_btree_string_map().

rs-dpp/state_transition/mod.rs (+22 tests)IdentityCreditWithdrawalV1 full surface + platform serialize through enum + transaction_id distinctness from V0 + required_asset_lock_balance Err; IdentityCreditTransferToAddresses full surface + is_identity_signed = true + inputs = None + active_version_range = 11..=LATEST; AddressCreditWithdrawal set_signature false arm + Some-inputs combo; ShieldFromAssetLock optional_asset_lock_proof Some arm + required_asset_lock_balance Ok; Batch V1 with TokenTransfer inner producing "DocumentsBatch([TokenTransfer])" name.

rs-drive-abci/execution/platform_events (+26 tests across 4 submodules)

  • withdrawals: early-return guards (quorum-not-in-validator-set, empty-queue, within-expiration); build_unsigned_transaction invalid-bytes error; fetch_transactions_block_inclusion_status map-keyed-by-index collection; cleanup_expired_locks_of_withdrawal_amounts zero-limit skip.
  • protocol_upgrade: zero-hpmns-zero-votes None; block-cache-overrides-global merge semantics; multi-version all-below-threshold None.
  • core_chain_lock: choose_quorum_v0 determinism + min-vs-max sort-order pin; make_sure_core_is_synced RPC-error propagation.
  • state_transition_processing: validate_fees_of_event 4 previously-uncovered event arms (PaidFromAssetLock sufficient/insufficient + balance + saturation); decode_raw_state_transitions empty-bytes-not-oversized + oversized-metadata; cleanup_recent_block_storage idempotency; store_address_balances empty-map.

How Has This Been Tested?

  • cargo test -p drive --lib 'drive::contract::insert' — 12 pass
  • cargo test -p drive --lib 'drive::contract::update' — 12 pass
  • cargo test -p drive --lib 'drive::tokens::balance' — 41 pass
  • cargo test -p drive --lib 'drive::tokens::system' — 32 pass
  • cargo test -p dpp --lib 'document::v0' — 117 pass
  • cargo test -p dpp --lib 'document::extended_document' — 60 pass
  • cargo test -p dpp --lib 'state_transition::tests' — 92 pass
  • cargo test -p drive-abci --lib 'execution::platform_events' — 158 pass
  • cargo check --tests -p dpp -p drive -p drive-abci — clean
  • cargo fmt -p dpp -p drive -p drive-abci — clean

No new production bugs surfaced. The chain-lock underflow bug (packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/make_sure_core_is_synced_to_chain_lock/v0/mod.rs:26-27) surfaced in #3516 is being fixed separately; tests in this PR deliberately avoid that line.

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

…rm_events

Add 119 new unit tests across 4 focus areas, all targeting error
paths and edge cases that integration tests don't exercise (per
the lesson from prior coverage PRs that accessor tests move
Codecov very little).

Per-target breakdown:

- rs-drive/drive/contract/insert + update (67–73% → covered,
  24 tests): insert_contract_v1 base_supply > i64::MAX guard
  (CriticalCorruptedCreditsCodeExecution), token/group/keyword/
  description estimation branches, multi-token insertion loop;
  update_contract_v0 UpdatingReadOnlyImmutableContract distinct
  from ChangingContractToReadOnly, apply=false delegates to
  insert, new-document-type creation branch; update_contract_v1
  token/group addition via update, keywords/description deltas
  via update_contract (not the dedicated APIs); update_keywords
  identical-keywords no-op, partial add+remove with overlap.

- rs-drive/drive/tokens/balance + system (81–82% → covered,
  15 tests): add_to_previous_token_balance i64::MAX+1 overflow
  guard both insert + replace paths, checked_add on large existing,
  stateless/estimation cost-only; remove_from_identity_token
  _balance drain-to-zero, underflow IdentityInsufficientBalance,
  missing-entry CorruptedCodeExecution; fetch_* PathKeyNotFound→
  None, unknown-identity Ok(None), stateless Some(0); system
  estimation HashMap population for add/remove/fetch_total_supply/
  fetch_aggregated, multi-token independence, aggregation
  mismatch detection in prove helper.

- rs-dpp/document/v0 (78% → covered, 19 tests): Display
  properties-iteration with multiple keys, hash_v0 determinism +
  differing docs, PartialEq per-field arms, bump_revision zero-
  increment + MAX saturation, full Getters/Setters round-trip,
  Debug format.

- rs-dpp/document/extended_document (78% → covered, 13 tests):
  token_payment_info Some branches in to_map_value / into_map_
  value / to_pretty_json / from_document_with_additional_info;
  set_untrusted binary-path replace + non-byte-value error; hash/
  to_pretty_json/can_be_modified error paths on unknown document
  type; from_trusted_platform_value data_contract_id override vs
  fallback; non-map-value rejection.

- rs-dpp/state_transition/mod.rs (81% → covered, 22 tests):
  IdentityCreditWithdrawalV1 full surface + platform serialize
  through enum + transaction_id distinctness from V0 +
  required_asset_lock_balance Err; IdentityCreditTransferTo
  Addresses full surface + is_identity_signed + inputs None +
  active_version_range; AddressCreditWithdrawal set_signature
  false arm + Some-inputs combo; ShieldFromAssetLock optional_
  asset_lock_proof Some arm + required_asset_lock_balance Ok;
  Batch V1 with TokenTransfer inner producing
  "DocumentsBatch([TokenTransfer])" name.

- rs-drive-abci/execution/platform_events (75–86% → covered,
  26 tests):
  * withdrawals: pool/update/dequeue/rebroadcast/fetch/cleanup
    early-return and empty-queue guards; invalid-bytes
    build_unsigned_transaction error; map-keyed-by-index
    collection.
  * protocol_upgrade: zero-hpmns-zero-votes None, block-cache-
    overrides-global merge semantics, multi-version all-below-
    threshold returns None.
  * core_chain_lock: choose_quorum_v0 deterministic with
    multiple quorums, pins min-vs-max sort order contract;
    make_sure_core_is_synced propagates RPC errors (the
    line 26-27 underflow is being fixed separately).
  * state_transition_processing: validate_fees_of_event 4
    previously-uncovered event arms (PaidFromAssetLock sufficient/
    insufficient + balance + saturation); decode_raw_state_
    transitions empty-bytes not-oversized + oversized metadata;
    cleanup_recent_block_storage_* idempotency;
    store_address_balances empty-map.

All 119 tests pass. No new production bugs surfaced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 22 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 43 minutes and 22 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: a8e198eb-b084-49cb-9cab-e5f487095d71

📥 Commits

Reviewing files that changed from the base of the PR and between d2c33d6 and 45badc0.

📒 Files selected for processing (37)
  • packages/rs-dpp/src/document/extended_document/v0/mod.rs
  • packages/rs-dpp/src/document/v0/mod.rs
  • packages/rs-dpp/src/state_transition/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/choose_quorum/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/core_chain_lock/make_sure_core_is_synced_to_chain_lock/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/check_for_desired_protocol_upgrade/v1/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/cleanup_recent_block_storage_address_balances/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/cleanup_recent_block_storage_nullifiers/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/decode_raw_state_transitions/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/store_address_balances_to_recent_block_storage/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/state_transition_processing/validate_fees_of_event/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/cleanup_expired_locks_of_withdrawal_amounts/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/dequeue_and_build_unsigned_withdrawal_transactions/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/fetch_transactions_block_inclusion_status/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v0/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v1/mod.rs
  • packages/rs-drive-abci/src/execution/platform_events/withdrawals/update_broadcasted_withdrawal_statuses/v0/mod.rs
  • packages/rs-drive/src/drive/contract/insert/add_contract_to_storage/v0/mod.rs
  • packages/rs-drive/src/drive/contract/insert/add_description/v0/mod.rs
  • packages/rs-drive/src/drive/contract/insert/add_new_keywords/v0/mod.rs
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v1/mod.rs
  • packages/rs-drive/src/drive/contract/update/update_contract/v0/mod.rs
  • packages/rs-drive/src/drive/contract/update/update_contract/v1/mod.rs
  • packages/rs-drive/src/drive/contract/update/update_description/v0/mod.rs
  • packages/rs-drive/src/drive/contract/update/update_keywords/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/balance/add_to_previous_token_balance/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/balance/fetch_identities_token_balances/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/balance/fetch_identity_token_balance/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/balance/fetch_identity_token_balances/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/balance/remove_from_identity_token_balance/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/system/add_to_token_total_supply/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/system/create_token_trees/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/system/fetch_token_total_aggregated_identity_balances/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/system/fetch_token_total_supply/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/system/prove_token_total_supply_and_aggregated_identity_balances/v0/mod.rs
  • packages/rs-drive/src/drive/tokens/system/remove_from_token_total_supply/v0/mod.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/coverage-contract-tokens-document-events-v2

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.

@github-actions github-actions Bot added this to the v3.1.0 milestone Apr 23, 2026
@thepastaclaw
Copy link
Copy Markdown
Collaborator

thepastaclaw commented Apr 23, 2026

Review Gate

Commit: 45badc07

  • Debounce: 18m ago (need 30m)

  • CI checks: builds passed, 0/2 tests passed

  • CodeRabbit review: comment found

  • Off-peak hours: off-peak (12:22 AM PT Thursday)

  • Run review now (check to override)

@QuantumExplorer
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 98.22465% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.55%. Comparing base (e0867b5) to head (45badc0).
⚠️ Report is 7 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...es/rs-dpp/src/document/extended_document/v0/mod.rs 96.37% 7 Missing ⚠️
..._processing/decode_raw_state_transitions/v0/mod.rs 85.36% 6 Missing ⚠️
...sition_processing/validate_fees_of_event/v0/mod.rs 95.72% 5 Missing ⚠️
...rc/drive/contract/insert/insert_contract/v1/mod.rs 95.50% 4 Missing ⚠️
...rc/drive/contract/update/update_contract/v0/mod.rs 96.29% 4 Missing ⚠️
...ns/balance/add_to_previous_token_balance/v0/mod.rs 97.67% 4 Missing ⚠️
packages/rs-dpp/src/state_transition/mod.rs 99.20% 2 Missing ⚠️
...orm_events/core_chain_lock/choose_quorum/v0/mod.rs 97.59% 2 Missing ⚠️
...d_build_unsigned_withdrawal_transactions/v0/mod.rs 93.75% 2 Missing ⚠️
...rc/drive/contract/insert/add_description/v0/mod.rs 96.55% 2 Missing ⚠️
... and 12 more
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3523      +/-   ##
============================================
+ Coverage     87.29%   87.55%   +0.25%     
============================================
  Files          2476     2474       -2     
  Lines        285752   288732    +2980     
============================================
+ Hits         249454   252805    +3351     
+ Misses        36298    35927     -371     
Components Coverage Δ
dpp 86.49% <97.30%> (+0.23%) ⬆️
drive 87.00% <98.51%> (+0.38%) ⬆️
drive-abci 89.48% <97.39%> (+0.15%) ⬆️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.13% <ø> (+0.03%) ⬆️
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.

@QuantumExplorer QuantumExplorer merged commit 62f2066 into v3.1-dev Apr 23, 2026
38 checks passed
@QuantumExplorer QuantumExplorer deleted the test/coverage-contract-tokens-document-events-v2 branch April 23, 2026 07:25
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