test: cover drive contract/tokens, rs-dpp document, drive-abci platform_events#3523
Conversation
…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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (37)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Review GateCommit:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Codecov Report❌ Patch coverage is 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
🚀 New features to boost your workflow:
|
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.
Highlighted coverage wins
drive/contract/insert (+12 tests) —
insert_contract_v1base_supply > i64::MAXguard returningCriticalCorruptedCreditsCodeExecution; token/group/keyword/description estimation branches viaapply=false; multi-token insertion loop with distinct token ids;add_contract_to_storage_v0history + estimate + first_insert combinations.drive/contract/update (+12 tests) —
UpdatingReadOnlyImmutableContract(distinct fromChangingContractToReadOnly);apply=falsedelegates to insert; new-document-type creation branch;update_contract_v1token/group addition via update; keywords/description deltas viaupdate_contract(not the dedicated APIs);update_keywordsidentical-keywords no-op; partial add+remove with overlap.drive/tokens/balance (+8 tests) —
add_to_previous_token_balancei64::MAX+1overflow guard on insert + replace paths;checked_addon large existing;remove_from_identity_token_balancedrain-to-zero +IdentityInsufficientBalanceunderflow + missing-entryCorruptedCodeExecution;fetch_identity_token_balancePathKeyNotFound → None, unknown-identityOk(None), stateless mode returnsSome(0);fetch_identities_token_balancesaggregated mixed-balances.drive/tokens/system (+7 tests) — estimation-mode
HashMappopulation acrossadd_to_token_total_supply/remove_from_token_total_supply/fetch_token_total_supply/fetch_token_total_aggregated_identity_balances;allow_first_mintinsert path; multi-token independence across a single contract;prove_token_total_supply_and_aggregated_identity_balancessupply-without-balances mismatch detection + matched-supply after multiple mint/add pairs.rs-dpp/document/v0 (+19 tests) —
Displayproperties-iteration with multiple keys + mixed optional fields;DocumentHashV0Method::hash_v0determinism and inequality; fullPartialEqper-field arm coverage;bump_revisionzero-increment + MAX saturation; completeGetters/Settersround-trip;Debugformat invariants.rs-dpp/document/extended_document (+13 tests) —
token_payment_infoSome(_)branches into_map_value,into_map_value,to_pretty_json,from_document_with_additional_info;set_untrustedbinary-path replace + non-byte-valueto_identifier_bytes()?error;hash/to_pretty_json/can_be_modifiederror paths throughdocument_type()?with unknown type;from_trusted_platform_valuedata_contract_idoverride vs fallback; non-map-value rejection viainto_btree_string_map().rs-dpp/state_transition/mod.rs (+22 tests) —
IdentityCreditWithdrawalV1full surface + platform serialize through enum + transaction_id distinctness from V0 +required_asset_lock_balanceErr;IdentityCreditTransferToAddressesfull surface +is_identity_signed = true+inputs = None+active_version_range = 11..=LATEST;AddressCreditWithdrawalset_signaturefalsearm +Some-inputs combo;ShieldFromAssetLockoptional_asset_lock_proofSomearm +required_asset_lock_balanceOk;BatchV1 withTokenTransferinner producing"DocumentsBatch([TokenTransfer])"name.rs-drive-abci/execution/platform_events (+26 tests across 4 submodules) —
build_unsigned_transactioninvalid-bytes error;fetch_transactions_block_inclusion_statusmap-keyed-by-index collection;cleanup_expired_locks_of_withdrawal_amountszero-limit skip.None; block-cache-overrides-global merge semantics; multi-version all-below-thresholdNone.choose_quorum_v0determinism + min-vs-max sort-order pin;make_sure_core_is_syncedRPC-error propagation.validate_fees_of_event4 previously-uncovered event arms (PaidFromAssetLock sufficient/insufficient + balance + saturation);decode_raw_state_transitionsempty-bytes-not-oversized + oversized-metadata; cleanup_recent_block_storage idempotency;store_address_balancesempty-map.How Has This Been Tested?
cargo test -p drive --lib 'drive::contract::insert'— 12 passcargo test -p drive --lib 'drive::contract::update'— 12 passcargo test -p drive --lib 'drive::tokens::balance'— 41 passcargo test -p drive --lib 'drive::tokens::system'— 32 passcargo test -p dpp --lib 'document::v0'— 117 passcargo test -p dpp --lib 'document::extended_document'— 60 passcargo test -p dpp --lib 'state_transition::tests'— 92 passcargo test -p drive-abci --lib 'execution::platform_events'— 158 passcargo check --tests -p dpp -p drive -p drive-abci— cleancargo fmt -p dpp -p drive -p drive-abci— cleanNo 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
For repository code-owners and collaborators only