Skip to content
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

fix: ensure we dont attempt to send funds from deposit to delegate after we refund user #1764

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

joe-bowman
Copy link
Contributor

@joe-bowman joe-bowman commented Dec 2, 2024

1. Summary

Fixes #1761

When we refund the user, ensure we don't attempt to also send a MsgSend to tranfer the same funds to the delegate account.

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for the asset minting and sending process, providing clearer success and error states.
    • Added a new test case to validate behavior under specific conditions for the asset minting function.
  • Bug Fixes

    • Improved the robustness of the MintAndSendQAsset function to handle different scenarios more effectively.
  • Tests

    • Updated existing tests to accommodate new return values and added assertions for success conditions.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request focus on the MintAndSendQAsset method within the Keeper struct in receipt.go, modifying its signature to return a boolean indicating success along with an error. This adjustment leads to refined error handling, where errors are logged instead of directly returned. Corresponding updates are made in the test suite in receipt_test.go, introducing new test cases and modifying existing ones to accommodate the new return type. The overall control flow and functionality remain intact, ensuring robust error handling in receipt transactions.

Changes

File Change Summary
x/interchainstaking/keeper/receipt.go Updated MintAndSendQAsset method signature to return (bool, error). Refined error handling and logging. Adjusted HandleReceiptTransaction method for new return type.
x/interchainstaking/keeper/receipt_test.go Added new test case for MintAndSendQAsset. Updated existing tests to handle new return values and assertions. Modified zone property in tests.

Assessment against linked issues

Objective Addressed Explanation
Ensure MsgSend is not sent if funds are returned to the user (#1761) The changes do not explicitly handle the case of returning funds without sending MsgSend.

🐰 In the land of code where rabbits play,
A method was changed, brightening the day.
With success and error, a tuple now shines,
Logging the troubles, as clarity aligns.
Tests were updated, new cases in sight,
Hopping through changes, everything feels right! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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: 2

🧹 Outside diff range and nitpick comments (1)
x/interchainstaking/keeper/receipt_test.go (1)

500-521: Consider adding error case assertions.

While the test case correctly verifies the success flag, consider adding assertions to validate any error messages or specific conditions that led to the refund scenario.

 	success, err := quicksilver.InterchainstakingKeeper.MintAndSendQAsset(ctx, sender, senderAddress, &zone, amount, false, nil)
 	suite.NoError(err)
 	suite.False(success)
+	// Verify no QAssets were minted
+	totalSupply := quicksilver.BankKeeper.GetSupply(ctx, zone.LocalDenom)
+	suite.Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), totalSupply)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fb33573 and 1a20583.

📒 Files selected for processing (2)
  • x/interchainstaking/keeper/receipt.go (6 hunks)
  • x/interchainstaking/keeper/receipt_test.go (7 hunks)
🔇 Additional comments (8)
x/interchainstaking/keeper/receipt_test.go (6)

400-402: LGTM! Test case properly validates the success flag.

The test case correctly verifies both the error and success flag for the 1:1 redemption rate scenario.


426-428: LGTM! Test case properly validates the success flag.

The test case correctly verifies both the error and success flag for the non-1:1 redemption rate scenario, including validation of the correct amount calculation.


452-454: LGTM! Test case properly validates the success flag.

The test case correctly verifies both the error and success flag for the sub-1:1 redemption rate scenario, including validation of the correct amount calculation.


470-470: LGTM! Test case properly validates non-118 zone with mapped account.

The test case correctly sets up a non-118 zone and verifies the success flag when a mapped account is provided.

Also applies to: 480-482


500-521: LGTM! New test case covers the refund scenario.

This new test case specifically addresses the PR objective by verifying that the function returns false when attempting to mint QAssets in a non-118 zone without a mapped account, which is the refund scenario mentioned in the PR description.


545-547: LGTM! Test case properly validates the success flag with transfer.

The test case correctly verifies both the error and success flag for the transfer scenario, including validation of the IBC escrow balance.

x/interchainstaking/keeper/receipt.go (2)

132-141: Avoid proceeding when success is false

The code inside the if success { ... } block for handling delegation and auto-claim assumes that success being true means qAssets were minted and sent. Ensure that this block is not executed when success is false, as it could lead to inconsistent states or errors.


Line range hint 213-274: Ensure consistent handling of success and error in MintAndSendQAsset

The function MintAndSendQAsset now returns a bool indicating success along with an error. Ensure that all return paths correctly represent the operation's outcome:

  • Line 215: Returns false and an error if the redemption rate is zero. ✅
  • Line 232: Returns false and the result of k.SubmitTx when refunding assets. Verify that k.SubmitTx returns an appropriate error if the refund fails. ⚠️
  • Line 241: Returns false and an error if minting coins fails. ✅
  • Line 265: Returns false and an error if transferring coins fails. ✅
  • Line 274: Returns true and nil when the operation is successful. ✅

Run the following script to check that k.SubmitTx correctly returns errors:

Consider adding comments to the function signature to clarify the meaning of the success boolean. This will improve code readability and maintainability.

Apply this diff to add a comment:

 func (k *Keeper) MintAndSendQAsset(ctx sdk.Context, sender sdk.AccAddress, senderAddress string, zone *types.Zone, assets sdk.Coins, memoRTS bool, mappedAddress sdk.AccAddress) (bool, error) {
+    // Returns:
+    // - success: true if qAssets were minted and sent successfully.
+    // - error: non-nil if an error occurred during the process.
     if zone.RedemptionRate.IsZero() {
         return false, errors.New("zero redemption rate")
     }

x/interchainstaking/keeper/receipt.go Show resolved Hide resolved
x/interchainstaking/keeper/receipt.go Show resolved Hide resolved
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 27.77778% with 13 lines in your changes missing coverage. Please review.

Project coverage is 61.45%. Comparing base (1bd45ff) to head (c38272f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
x/interchainstaking/keeper/receipt.go 27.77% 10 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1764      +/-   ##
==========================================
+ Coverage   61.40%   61.45%   +0.05%     
==========================================
  Files         196      196              
  Lines       17075    17077       +2     
==========================================
+ Hits        10485    10495      +10     
+ Misses       5742     5735       -7     
+ Partials      848      847       -1     
Flag Coverage Δ
unittests 61.45% <27.77%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
x/interchainstaking/keeper/receipt.go 80.25% <27.77%> (+2.64%) ⬆️

@joe-bowman joe-bowman merged commit cd581bc into main Dec 2, 2024
20 of 21 checks passed
@joe-bowman joe-bowman deleted the 1761-dont-transfer-to-delegate-after-refund branch December 2, 2024 18:25
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.

Unfulfillable MsgSend to delegate is sent, if we return funds to user
2 participants