test(drive-abci): add happy path tests for token burn, freeze, emergency action, and destroy frozen funds#3459
Conversation
…ncy action, and destroy frozen funds Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughTest-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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 complete (commit 452498c) |
There was a problem hiding this comment.
🧹 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
100000directly 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
📒 Files selected for processing (4)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/burn/mod.rspackages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/destroy_frozen_funds/mod.rspackages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/emergency_action/mod.rspackages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/freeze/mod.rs
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
thepastaclaw
left a comment
There was a problem hiding this comment.
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
Summary
Adds 5 happy-path tests for token transition actions that previously only had error-path coverage.
emergency_action/mod.rsdestroy_frozen_funds/mod.rsburn/mod.rsfreeze/mod.rsThese 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
cargo fmt --allclean🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes