test(dpp): cover state transitions, token config, perpetual distribution#3512
Conversation
…stribution Add 363 new unit tests across 27 files targeting the largest remaining gaps in rs-dpp (token config methods, document batch transitions, identity transitions, shielded transitions, reward distribution types/moments). Per-target breakdown (previous coverage → now exercised): - state_transition/state_transitions/document/batch_transition (79% → covered, 33 tests): action-type TryFrom error messages across document + token enums, resolver match-arm coverage for BatchedTransition and BatchedTransitionRef (14 Document(_)=>None + 11 token => value arms per trait), find_duplicates_by_id fingerprint specificity + three-way collision pushes_pairs quirk, validate_basic_structure DocumentTransitionsAreAbsent + MaxDocumentsTransitionsExceeded + NonceOutOfBounds consensus errors. - data_contract/associated_token/token_configuration/methods (62% → covered, 60 tests across 4 submodules): every enum arm of apply_token_configuration_item (23 tests), authorized_action_takers special-case NoOne returns for TokenConfigurationNoChange + MainControlGroup (15 tests), can_apply_token_configuration_item allow/deny across all rule categories (15 tests), validate_token_configuration_groups_exist GroupPositionDoesNotExistError + MainGroupIsNotDefinedError paths (7 tests). - data_contract/associated_token/token_configuration_item.rs (54% → covered, 24 tests): payload_serialization byte layout for MaxSupply/MainControlGroup BE, Identity 32 bytes, MintingAllowChoosingDestination bool-as-u8, Conventions bincode roundtrip, tag-byte sharing across all 24 AuthorizedActionTakers variants, Display + equality per arm. - data_contract/associated_token/token_configuration/v0 (79% → covered, 38 tests): TokenConfigurationPreset default_* helpers across all 5 TokenConfigurationPresetFeatures variants, default_distribution_rules with direct-pricing on/off, default_most_restrictive, all_used_group_positions Group variant collection + MainGroup flag + main_control_group inclusion. - data_contract/associated_token/token_perpetual_distribution/ reward_distribution_moment (65% → covered, 41 tests): to_u64, same_type, cycle_start (aligned/unaligned/zero-step + type mismatch), Add<u64> (all variants + overflow + u16 rhs cap), Add<Self> (all variants + overflow + type mismatch), Div<u64> (zero rhs, over-u16, ok), Div<Self> (zero + type mismatch), PartialEq<u64/u32/u16/usize>, to_be_bytes_vec, Display, from_block_info, steps_till edge cases. - data_contract/associated_token/token_perpetual_distribution/ reward_distribution_type (56% → covered, 28 tests): moment_from_bytes 5 decode-error arms + 3 success arms, max_cycle_moment capped-by-current + non-fixed + epoch current-1 saturation, validate_structure_interval_v0 block-too-short Mainnet / Testnet / Regtest + time boundary + not-minute-aligned error paths. - state_transitions/identity/public_key_in_creation (84% → covered, 6 tests): StateTransitionValueConvert dispatch + version errors, canonical_object inserts $version, value_map roundtrip, default_versioned unknown-version, duplicate-keys witness invariant. - state_transitions/identity/identity_topup_from_addresses (69% → covered, 17 tests): full validate_structure branch coverage — no_inputs, witness_count_mismatch, output_is_input, fee_strategy_empty/duplicate/out_of_bounds, input_below_minimum, output_below_minimum, input_sum_less_than_required, overflow. - state_transitions/identity/identity_create_from_addresses (78% → covered, 16 tests): full validate_structure branch coverage — no_inputs, no_public_keys (MissingMasterPublicKey), too_many_public_keys (MaxIdentityPublicKeyLimit), input/witness mismatch, fee_strategy bounds, input/output below minimum, input_sum_less_than_required, overflow_on_input_sum. - state_transitions/identity/identity_create_transition (84% → covered, 7 tests): try_from_inner ChainAssetLockProof identity_id derivation, AssetLockProved::set_asset_lock_proof, accessors, dispatch, versioning. - state_transitions/identity/identity_credit_withdrawal_transition (89% → covered, 10 tests v0+v1): skip_signature removal across to_object / to_cleaned_object / to_canonical_cleaned_object, Pooling::Never vs Standard roundtrip, v1 None-output_script value_map roundtrip. - state_transitions/identity/identity_credit_transfer_transition + identity_credit_transfer_to_addresses (74/78% → covered, 8 tests): skip_signature path removal, modified_data_ids + unique_identifiers, validate_structure NoRecipients / too_many / recipient_below_minimum / single-valid. - state_transitions/shielded/* (68-74% → covered, 25 tests across shield_from_asset_lock / shielded_withdrawal / unshield / shielded_transfer): StateTransitionLike type/version/ modified_ids/unique_identifiers (base64 of asset lock or hex of nullifier), signature + FeatureVersioned + AssetLockProved accessors. - state_transitions/address_funds/address_funding_from_asset_lock (84% → covered, 11 tests): full StateTransitionLike surface, SingleSigned + WitnessSigned setters, UserFeeIncrease get/set, Signable shadow From conversion. All 363 tests pass. No production bugs surfaced. One design quirk noted in find_duplicates_by_id — three-way collisions push (existing, new) for each subsequent collision, producing 4 entries for a triple-duplicate; pinned by test for regression detection. 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 47 minutes and 5 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 (27)
✨ 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:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## v3.1-dev #3512 +/- ##
============================================
+ Coverage 86.37% 86.77% +0.39%
============================================
Files 2474 2474
Lines 277856 281241 +3385
============================================
+ Hits 240007 244048 +4041
+ Misses 37849 37193 -656
🚀 New features to boost your workflow:
|
Issue being fixed or feature implemented
Sixth PR in the push toward 90% global coverage. After #3503–#3511, we're at 86.38%. This PR targets ~2,550 missed lines across the largest remaining gaps in rs-dpp.
What was done?
363 new unit tests across 27 files.
Highlighted coverage wins
token_configuration/methods (+60 tests) — every enum arm of
apply_token_configuration_item,authorized_action_takersspecial-caseNoOnereturns forTokenConfigurationNoChange+MainControlGroup,can_applyallow/deny matrices across all rule categories,validate_token_configuration_groups_existGroupPositionDoesNotExistError+MainGroupIsNotDefinedErrorpaths.token_configuration_item.rs (+24 tests) — payload_serialization byte layout for MaxSupply/MainControlGroup BE, Identity 32 bytes, MintingAllowChoosingDestination bool-as-u8, Conventions bincode roundtrip, tag-byte sharing across all 24
AuthorizedActionTakersvariants.reward_distribution_moment (+41 tests) —
Add<u64>/Add<Self>/Div<u64>/Div<Self>full variant matrix including overflow, type-mismatchAddingDifferentTypes, u16 rhs cap, zero-divisorDivideByZero, epochfrom_block_info.reward_distribution_type (+28 tests) —
moment_from_bytes5 decode-error arms,max_cycle_momentnon-fixed path withMAX_DISTRIBUTION_CYCLES_PARAMvsmax_non_fixed_amount_cyclesand epoch current-1 saturation,validate_structure_interval_v0Mainnet/Testnet/Regtest block-too-short + time-not-minute-aligned error paths.batch_transition (+33 tests) — resolver match-arm coverage for
BatchedTransition+BatchedTransitionRef(14 Document→None + 11 token→value per trait), find_duplicates_by_id three-way collisionpushes_pairsquirk, validate_basic_structure consensus errors (DocumentTransitionsAreAbsent,MaxDocumentsTransitionsExceeded,NonceOutOfBounds).identity_topup_from_addresses (+17 tests) + identity_create_from_addresses (+16 tests) — full validate_structure branch coverage: no_inputs, witness/input mismatch, output_is_input, fee_strategy_empty/duplicate/out_of_bounds, input/output below minimum, input_sum_less_than_required, overflow, MissingMasterPublicKey, MaxIdentityPublicKeyLimitReached.
shielded transitions (+25 tests across 4 transitions) — StateTransitionLike surface (type/version/modified_ids/unique_identifiers via base64-of-asset-lock or hex-of-nullifier), signature setters, AssetLockProved accessor+setter, FeatureVersioned.
address_funding_from_asset_lock (+11 tests) — full StateTransitionLike + SingleSigned + WitnessSigned + UserFeeIncrease + Signable shadow From conversion.
How Has This Been Tested?
cargo test -p dpp --lib 'state_transitions::identity'— 272 passcargo test -p dpp --lib 'batch_transition'— 250 passcargo test -p dpp --lib 'token_configuration'— 157 passcargo test -p dpp --lib 'state_transitions::shielded'— 99 passcargo test -p dpp --lib 'token_perpetual_distribution'— 405 passcargo test -p dpp --lib 'state_transitions::address_funds'— 90 passcargo check --tests -p dpp— cleancargo fmt -p dpp— cleanNo production bugs surfaced. One design quirk pinned by test for regression detection:
find_duplicates_by_idthree-way collisions push(existing, new)for each subsequent collision, producing 4 entries for a triple-duplicate instead of 3.Breaking Changes
None. Tests only.
Checklist
For repository code-owners and collaborators only