Skip to content

test(drive-abci): add happy path tests for token burn, freeze, emergency action, and destroy frozen funds#3459

Merged
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/drive-abci-token-transitions
Apr 9, 2026
Merged

test(drive-abci): add happy path tests for token burn, freeze, emergency action, and destroy frozen funds#3459
QuantumExplorer merged 2 commits into
v3.1-devfrom
test/drive-abci-token-transitions

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Apr 8, 2026

Summary

Adds 5 happy-path tests for token transition actions that previously only had error-path coverage.

File New Tests What's covered
emergency_action/mod.rs 2 Pause token successfully, resume paused token
destroy_frozen_funds/mod.rs 1 Freeze + destroy frozen funds, verify balance = 0
burn/mod.rs 1 Burn entire balance, verify balance = 0
freeze/mod.rs 1 Freeze → verify transfer fails → unfreeze → verify transfer succeeds

These tests exercise the full state transition pipeline including the transformer code in rs-drive, improving coverage for token_burn_transition_action, token_freeze/unfreeze_transition_action, token_emergency_action_transition_action, and token_destroy_frozen_funds_transition_action.

Test plan

  • All 25 token tests pass (20 existing + 5 new)
  • cargo fmt --all clean
  • CI

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Tests
    • Added test coverage for complete token burn scenarios, including burning entire account balance
    • Added test validation for frozen fund destruction operations
    • Added test cases for token emergency pause and resume functionality
    • Added test coverage for token account freezing and unfreezing with transaction validation

…ncy action, and destroy frozen funds

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

📝 Walkthrough

Walkthrough

Test-only additions across four token test modules: new tests for complete token burn scenarios, frozen fund destruction, emergency token pause/resume actions, and token unfreeze operations. No changes to production code or public API declarations.

Changes

Cohort / File(s) Summary
Token Operation Tests
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/burn/mod.rs, destroy_frozen_funds/mod.rs, emergency_action/mod.rs, freeze/mod.rs
Added comprehensive test coverage for token operations: complete balance burn scenario, frozen fund destruction with balance verification, emergency pause/resume actions with status assertions, and unfreeze with transfer validation. Tests exercise transition creation, serialization, processing, and state assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Four tests hopped in to play,
Burning tokens, froze then thawed away,
Emergency pauses, funds frozen and destroyed,
Token transitions—beautifully employed! ✨

🚥 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 change: adding happy path tests for four specific token operations (burn, freeze, emergency action, destroy frozen funds) across multiple test modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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/drive-abci-token-transitions

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 complete (commit 452498c)

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.

🧹 Nitpick comments (3)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/burn/mod.rs (1)

118-125: Avoid coupling this test to the default initial supply literal.

Using 100000 directly makes this brittle if test fixture defaults change. Consider burning the fetched pre-burn balance instead.

Suggested refactor
-        // Burn the entire balance of 100000 tokens
+        // Burn the entire current balance
+        let initial_balance = platform
+            .drive
+            .fetch_identity_token_balance(
+                token_id.to_buffer(),
+                identity.id().to_buffer(),
+                None,
+                platform_version,
+            )
+            .expect("expected to fetch token balance")
+            .expect("expected existing balance");
+
         let burn_transition = BatchTransition::new_token_burn_transition(
             token_id,
             identity.id(),
             contract.id(),
             0,
-            100000,
+            initial_balance,

Also applies to: 167-177

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

In
`@packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/burn/mod.rs`
around lines 118 - 125, The test is brittle because it uses the literal 100000
for the burn amount; instead query the pre-burn balance and use that value when
constructing the burn transition. Replace the literal in calls to
BatchTransition::new_token_burn_transition (and the similar case around the
second occurrence) with the fetched balance variable (e.g., call the method that
retrieves token balance before creating the transition and pass that variable as
the amount), keeping the same token_id, identity.id(), contract.id(), and other
arguments.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/emergency_action/mod.rs (1)

10-254: You could table-drive pause/resume cases to reduce duplication.

A shared helper for setup + execution + status assertion would keep these tests shorter without changing behavior.

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

In
`@packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/emergency_action/mod.rs`
around lines 10 - 254, Extract the duplicated setup/execution/assertion into a
helper (e.g. run_emergency_action_test or setup_and_execute_emergency_action)
that performs identity/contract creation (used in test_token_emergency_pause and
test_token_emergency_resume), builds and serializes a BatchTransition via
BatchTransition::new_token_emergency_action_transition, calls
platform.platform.process_raw_state_transitions and commits the grove
transaction, then fetches status with platform.drive.fetch_token_status and
asserts paused state; update the two tests to call this helper with the
appropriate TokenEmergencyAction (Pause/Resume), signer/key/sequence args (e.g.
sequence 2 then 3), and expected TokenStatus (paused true/false) to remove
duplicated code.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/freeze/mod.rs (1)

425-706: Consider extracting a local helper for submit/process/commit.

The repeated transition execution blocks make this test longer than needed; a small helper would improve readability and maintenance.

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

In
`@packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/freeze/mod.rs`
around lines 425 - 706, Extract a small helper (e.g.,
submit_and_commit_transition) that accepts a serialized transition bytes (from
BatchTransition::serialize_to_bytes), the platform_state, platform_version, and
optional expected result matcher, and inside it: start a transaction with
platform.drive.grove.start_transaction(), call
platform.platform.process_raw_state_transitions(...) with BlockInfo::default(),
assert the expected execution result (or return the processing_result), then
commit via platform.drive.grove.commit_transaction(transaction). Replace each
repeated block that builds a serialized transition, starts the transaction,
calls process_raw_state_transitions, asserts the result, and commits with calls
to this helper to reduce duplication and improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/burn/mod.rs`:
- Around line 118-125: The test is brittle because it uses the literal 100000
for the burn amount; instead query the pre-burn balance and use that value when
constructing the burn transition. Replace the literal in calls to
BatchTransition::new_token_burn_transition (and the similar case around the
second occurrence) with the fetched balance variable (e.g., call the method that
retrieves token balance before creating the transition and pass that variable as
the amount), keeping the same token_id, identity.id(), contract.id(), and other
arguments.

In
`@packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/emergency_action/mod.rs`:
- Around line 10-254: Extract the duplicated setup/execution/assertion into a
helper (e.g. run_emergency_action_test or setup_and_execute_emergency_action)
that performs identity/contract creation (used in test_token_emergency_pause and
test_token_emergency_resume), builds and serializes a BatchTransition via
BatchTransition::new_token_emergency_action_transition, calls
platform.platform.process_raw_state_transitions and commits the grove
transaction, then fetches status with platform.drive.fetch_token_status and
asserts paused state; update the two tests to call this helper with the
appropriate TokenEmergencyAction (Pause/Resume), signer/key/sequence args (e.g.
sequence 2 then 3), and expected TokenStatus (paused true/false) to remove
duplicated code.

In
`@packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/freeze/mod.rs`:
- Around line 425-706: Extract a small helper (e.g.,
submit_and_commit_transition) that accepts a serialized transition bytes (from
BatchTransition::serialize_to_bytes), the platform_state, platform_version, and
optional expected result matcher, and inside it: start a transaction with
platform.drive.grove.start_transaction(), call
platform.platform.process_raw_state_transitions(...) with BlockInfo::default(),
assert the expected execution result (or return the processing_result), then
commit via platform.drive.grove.commit_transaction(transaction). Replace each
repeated block that builds a serialized transition, starts the transaction,
calls process_raw_state_transitions, asserts the result, and commits with calls
to this helper to reduce duplication and improve readability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c68f840-2490-4468-afdb-d89f65494685

📥 Commits

Reviewing files that changed from the base of the PR and between 11d80f5 and 909a341.

📒 Files selected for processing (4)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/burn/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/destroy_frozen_funds/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/emergency_action/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/freeze/mod.rs

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.76%. Comparing base (46e037e) to head (452498c).
⚠️ Report is 2 commits behind head on v3.1-dev.

Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3459      +/-   ##
============================================
+ Coverage     84.12%   84.76%   +0.63%     
============================================
  Files          2601     2469     -132     
  Lines        271457   266394    -5063     
============================================
- Hits         228366   225798    -2568     
+ Misses        43091    40596    -2495     
Components Coverage Δ
dpp 81.79% <ø> (+2.43%) ⬆️
drive 84.19% <ø> (+<0.01%) ⬆️
drive-abci 87.39% <ø> (ø)
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.

Copy link
Copy Markdown
Collaborator

@thepastaclaw thepastaclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The diff is limited to new token batch-transition tests in rs-drive-abci, and the added assertions are consistent with the existing test style in this suite. I verified the flagged locations against the checked-out code and did not find a concrete defect in the new tests; the remaining suggestions were optional coverage expansions rather than issues that make the PR incorrect, so this should be approved as-is.

Reviewed commit: 452498c

@QuantumExplorer QuantumExplorer merged commit 153a02f into v3.1-dev Apr 9, 2026
37 checks passed
@QuantumExplorer QuantumExplorer deleted the test/drive-abci-token-transitions branch April 9, 2026 06:14
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