Skip to content

fix(drive): mint to self if allowed and no destination id set #2508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

pauldelucia
Copy link
Member

@pauldelucia pauldelucia commented Mar 19, 2025

Issue being fixed or feature implemented

When minting, in the case where no default destination identity is set, and no recipient is set, we should mint to self if allowed. However, we were preventing this and instead returning BasicError::DestinationIdentityForTokenMintingNotSetError, which actually is a useless error, because even if destination identities are allowed to be set, it isn't required.

What was done?

Mint to self if the contract allows that identity to mint, no recipient is set, and no default recipient is set.

How Has This Been Tested?

DET

Breaking Changes

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

Summary by CodeRabbit

  • Refactor

    • Streamlined token minting operations by simplifying the handling of identity checks, leading to a more efficient and cleaner process.
    • Removed unnecessary error handling related to destination identity for token minting, enhancing clarity and maintainability.
    • Updated error handling logic by removing specific error types and associated imports, resulting in a more straightforward error management system.
  • Tests

    • Updated token minting tests to validate successful execution instead of expecting errors, reflecting a shift in testing strategy.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

The pull request refactors the TokenMintTransitionActionV0 implementation by removing the error handling related to the absence of an identity_balance_holder_id. Instead of creating a BumpIdentityDataContractNonceAction and returning an error, the function now directly returns the owner_id. Additionally, the DestinationIdentityForTokenMintingNotSetError variant and its associated logic have been removed from the error handling, resulting in a simplified control flow for token minting.

Changes

File(s) Change Summary
packages/rs-drive/src/.../transformer.rs Simplified the control flow in TokenMintTransitionActionV0: removed error handling and action creation for a missing identity_balance_holder_id, now returns owner_id directly.
packages/rs-dpp/src/errors/consensus/basic/basic_error.rs Removed DestinationIdentityForTokenMintingNotSetError variant from BasicError enum, streamlining error handling for token minting.
packages/rs-dpp/src/errors/consensus/basic/token/destination_identity_for_token_minting_not_set_error.rs Deleted the file defining DestinationIdentityForTokenMintingNotSetError, including its struct and associated methods.
packages/rs-dpp/src/errors/consensus/basic/token/mod.rs Removed module and public use declaration for destination_identity_for_token_minting_not_set_error, eliminating its functionality from the module's interface.
packages/rs-dpp/src/errors/consensus/codes.rs Removed handling for DestinationIdentityForTokenMintingNotSetError in ErrorWithCode trait, renumbered subsequent error variants.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mod.rs Updated token minting tests to reflect changes in error handling, focusing on successful execution rather than error expectation.
packages/wasm-dpp/src/errors/consensus/consensus_error.rs Removed handling for DestinationIdentityForTokenMintingNotSetError in from_basic_error function, simplifying error handling logic.

Possibly related PRs

  • fix(dpp): invalid feature flag usage #2477: The changes in the main PR, which involve the removal of error handling related to the absence of an identity balance holder ID in token minting, are related to the retrieved PR, as both involve modifications to error handling and the removal of specific error types associated with token operations.

Suggested Reviewers

  • shumkov
  • QuantumExplorer

Poem

In the code garden, a change did bloom,
With fewer branches to chase in the room.
I'm a little rabbit, hopping with glee,
Returning owner_id with simplicity.
Bugs scurry off—hip, hop, code is free!
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/token_mint_transition_action/v0/transformer.rs (1)

5-5: Consider removing unused import

The DestinationIdentityForTokenMintingNotSetError import is now unused since the code no longer throws this error. Removing it would clean up the imports.

- use dpp::consensus::basic::token::{ChoosingTokenMintRecipientNotAllowedError, DestinationIdentityForTokenMintingNotSetError};
+ use dpp::consensus::basic::token::ChoosingTokenMintRecipientNotAllowedError;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3316b47 and af2666b.

📒 Files selected for processing (1)
  • packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/token_mint_transition_action/v0/transformer.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Formatting
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (3)
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/token_mint_transition_action/v0/transformer.rs (3)

146-161: Approved: Now allows fallback to self-minting when no destination is specified

This change properly implements the PR objective of allowing tokens to be minted to the owner (self) when no specific destination is set. By returning owner_id when no destination identity is found, the code eliminates the unnecessary error that was previously thrown.


301-316: Approved: Consistent implementation in the borrowed function variant

The same change has been correctly applied to the borrowed function variant, ensuring consistency across both implementations. This allows for self-minting when no destination identity is specified.


119-144:

❓ Verification inconclusive

Verification: Confirm error path is still properly covered by tests

The code still correctly prevents users from specifying a destination when not allowed by the token configuration. Since this PR changes related error handling, it's worth verifying that tests still cover this error path properly.


🏁 Script executed:

#!/bin/bash
# Search for tests that verify the ChoosingTokenMintRecipientNotAllowedError handling

echo "Searching for tests related to ChoosingTokenMintRecipientNotAllowedError..."
rg -A 5 "ChoosingTokenMintRecipientNotAllowedError" --glob "**/*test*"

Length of output: 231


Action Required: Confirm test coverage for error path

The code correctly returns a ChoosingTokenMintRecipientNotAllowedError when a destination is specified against token configuration rules. However, our automated search did not locate any test cases explicitly referencing ChoosingTokenMintRecipientNotAllowedError. Please manually verify that this error path is exercised in your tests. If tests are missing or incomplete, consider adding scenarios to cover this validation.

Copy link
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.

Actionable comments posted: 0

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

406-497: Test name no longer matches behavior

The test name test_token_mint_by_owner_no_destination_causes_error implies that an error is expected, but the implementation now checks for successful execution when no destination is provided. Consider renaming the test to better reflect its current behavior.

-fn test_token_mint_by_owner_no_destination_causes_error() {
+fn test_token_mint_by_owner_no_destination_mints_to_self() {

700-795: Test name no longer matches behavior

Similar to the previous test, this name test_token_mint_by_owned_id_no_destination_causes_error implies an error is expected, but the implementation now checks for successful execution.

-fn test_token_mint_by_owned_id_no_destination_causes_error() {
+fn test_token_mint_by_owned_id_no_destination_mints_to_self() {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb680d8 and c4f2d47.

📒 Files selected for processing (1)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mod.rs (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
🔇 Additional comments (6)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mod.rs (6)

430-431: Good addition to ensure accurate verification

Capturing the base supply before minting allows for precise verification of the token balances after the operation, ensuring the test properly validates the new self-minting behavior.


474-475: Successfully implements the intended behavior change

The assertion has been appropriately updated to check for successful execution instead of the previous error. This properly tests that token minting works when no destination ID is provided.


484-496: Good verification of token balance

This addition properly verifies that the token was minted to the owner's account when no destination was specified, confirming the new self-minting behavior works as expected.


728-729: Good addition to ensure accurate verification

Similar to the previous test case, capturing the base supply allows for precise verification of token balances after the minting operation.


772-773: Successfully implements the intended behavior change

The assertion has been appropriately updated to check for successful execution instead of the previous error, properly testing the new self-minting behavior.


782-796: Good verification of token balance

This addition properly verifies that the token was minted to the owner's account when no destination was specified in the no-recipient minting scenario, confirming the feature works across different configuration settings.

@pauldelucia pauldelucia deleted the fix/mint-to-self branch April 17, 2025 11:51
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.

1 participant