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

refactor(x/bank): check send enabled on coins #20343

Merged
merged 12 commits into from
May 13, 2024
Merged

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented May 10, 2024

Description

this was reported as an issue, while the path to get here would involve lots of overhead its worth adding the check


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features
    • Enhanced security by implementing a check to ensure that the denomination of each coin being sent is allowed at the time of the transaction.
  • Bug Fixes
    • Added a test to validate the error handling when sending coins from a module to an account with disabled coin sending.
  • Tests
    • Integration tests across various modules now include setting default parameters to ensure consistency and reliability in test environments.

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing parameter setting for bankKeeper across test suites and adding a validation step in keeper.go to check if coin denominations are enabled. This ensures robust testing and adherence to functionality when certain coin transactions are disabled.

Changes

Files Change Summary
x/bank/keeper/keeper.go Added IsSendEnabledDenom check before sending coins.
x/bank/keeper/keeper_test.go New test for disabled coin sending.
x/bank/keeper/genesis_test.go Imported banktypes and set default parameters in tests.
.../bank/keeper/deterministic_test.go Added default parameter setting in initDeterministicFixture.
.../distribution/keeper/msg_server_test.go Added bankKeeper.SetParams in initFixture.
.../evidence/keeper/infraction_test.go Added parameter setting in initFixture.
.../gov/keeper/keeper_test.go Introduced parameter setting in initFixture.
.../slashing/keeper/keeper_test.go Set default parameters before initializing services.
.../staking/keeper/common_test.go Default parameters set in initFixture.
.../staking/keeper/deterministic_test.go Added bankKeeper.SetParams with defaults in initDeterministicFixture.
.../types/pagination_test.go Added call to set default parameters in SetupTest.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@tac0turtle tac0turtle marked this pull request as ready for review May 10, 2024 12:52
@tac0turtle tac0turtle requested a review from a team as a code owner May 10, 2024 12:52
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: 1

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6a2618f and 65f3143.
Files selected for processing (2)
  • x/bank/keeper/keeper.go (1 hunks)
  • x/bank/keeper/keeper_test.go (1 hunks)
Additional Context Used
Path-based Instructions (2)
x/bank/keeper/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/bank/keeper/keeper_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Comment on lines 272 to 274
if err := k.IsSendEnabledCoins(ctx, amt...); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment explaining the purpose of the IsSendEnabledCoins check.

+  // Check if sending coins is enabled for the specified amounts

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := k.IsSendEnabledCoins(ctx, amt...); err != nil {
return err
}
if err := k.IsSendEnabledCoins(ctx, amt...); err != nil {
// Check if sending coins is enabled for the specified amounts
return err
}

@julienrbrt julienrbrt changed the title chore: check send enabled on coins refactor(x/bank): check send enabled on coins May 10, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Can we get a changelog?

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 65f3143 and 0da8332.
Files selected for processing (2)
  • x/bank/keeper/keeper.go (1 hunks)
  • x/bank/keeper/keeper_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/bank/keeper/keeper.go
  • x/bank/keeper/keeper_test.go

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0da8332 and 4539db5.
Files selected for processing (2)
  • baseapp/baseapp.go (1 hunks)
  • x/bank/keeper/keeper_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/bank/keeper/keeper_test.go
Additional Context Used
Path-based Instructions (1)
baseapp/baseapp.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (1)
baseapp/baseapp.go (1)

725-725: Change in function signature to ignore input parameter.

Verification successful

The review of the beginBlock function in baseapp/baseapp.go shows that the function signature correctly marks the parameter as unused with an underscore, and the function is called in baseapp/abci.go. There is no evidence from the current codebase that this change negatively impacts the functionality. It appears that the function signature change is handled appropriately, and the parameter is intentionally marked as unused.

  • Location of the function call: baseapp/abci.go
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the change in function signature of `beginBlock` does not affect its functionality.

# Test: Search for usage of `beginBlock` in the codebase. Expect: No direct usage of the parameter.
rg --type go $'func \\(.*BaseApp\\) beginBlock\\(_ \\*abci.FinalizeBlockRequest\\)'

Length of output: 185



Script:

#!/bin/bash
# Description: Search for calls to `beginBlock` within the codebase to understand its usage context.

# Search for calls to `beginBlock` and analyze the context in which it is used.
rg --type go 'app.beginBlock\('

Length of output: 89

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4539db5 and e673249.
Files selected for processing (2)
  • x/bank/keeper/genesis_test.go (2 hunks)
  • x/bank/keeper/keeper_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/bank/keeper/keeper_test.go
Additional Context Used
Path-based Instructions (1)
x/bank/keeper/genesis_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (1)
x/bank/keeper/genesis_test.go (1)

24-26: The changes to set default send parameters align with the PR's objectives to enhance checks on coin sending. Ensure integration with other modules is verified.

Verification successful

The review of the integration of the DefaultSendEnabled parameter across various modules and components within the Cosmos SDK's bank module indicates a thorough and consistent implementation. The parameter is actively used and tested across multiple layers, including simulation, keeper logic, and API responses, ensuring its functionality is integral to the module's operations.

  • Genesis and Simulation Tests: The parameter is tested under various scenarios to ensure its default and modified states behave as expected.
  • Keeper and API Layers: Critical for transaction permissions, the parameter's value is consistently retrieved and used in transaction validations and API responses.

This comprehensive integration aligns with the PR's objectives to enhance checks on coin sending, confirming the changes are correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of default send parameters with other modules.

# Test: Search for usage of `DefaultSendEnabled` in other modules. Expect: Proper integration.
rg --type go $'DefaultSendEnabled'

Length of output: 5449

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: 1

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between e673249 and df01254.
Files selected for processing (1)
  • x/bank/CHANGELOG.md (1 hunks)
Additional Context Used
LanguageTool (11)
x/bank/CHANGELOG.md (11)

Near line 30: Unpaired symbol: ‘[’ seems to be missing
Context: ...## [Unreleased] ### Features * [#17569](https://github.com/cosmos/cosmos-sdk/pu...


Near line 31: Unpaired symbol: ‘[’ seems to be missing
Context: ...ype, MsgBurn, to burn coins. * [#20014](https://github.com/cosmos/cosmos-sdk/pu...


Near line 35: Unpaired symbol: ‘[’ seems to be missing
Context: ...rictionFn`. ### Improvements * [#18636](https://github.com/cosmos/cosmos-sdk/pu...


Near line 35: The verb form ‘does’ does not seem to match the subject ‘accounts’.
Context: ...ead of panicking if any module accounts does not exist or unauthorized. ### API Bre...


Near line 39: Unpaired symbol: ‘[’ seems to be missing
Context: ...ed. ### API Breaking Changes * [#19954](https://github.com/cosmos/cosmos-sdk/pu...


Near line 44: Unpaired symbol: ‘[’ seems to be missing
Context: ...lances` also returns an error. * [#17569](https://github.com/cosmos/cosmos-sdk/pu...


Near line 45: Unpaired symbol: ‘[’ seems to be missing
Context: ...dress instead of a module name * [#19477](https://github.com/cosmos/cosmos-sdk/pu...


Near line 46: Unpaired symbol: ‘[’ seems to be missing
Context: ... is passed to bank NewKeeper * [#19627](https://github.com/cosmos/cosmos-sdk/pu...


Near line 47: Unpaired symbol: ‘[’ seems to be missing
Context: ... match appmodule.HasGenesis. * [#19740](https://github.com/cosmos/cosmos-sdk/pu...


Near line 51: Unpaired symbol: ‘[’ seems to be missing
Context: ...## Consensus Breaking Changes * [#19188](https://github.com/cosmos/cosmos-sdk/pu...


Near line 52: Unpaired symbol: ‘[’ seems to be missing
Context: ...an account that does not exist * [#20343](https://github.com/cosmos/cosmos-sdk/pu...

Path-based Instructions (1)
x/bank/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

@@ -49,3 +49,4 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Consensus Breaking Changes

* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist
* [#20343](https://github.com/cosmos/cosmos-sdk/pull/20343) Add a check in send moduleaccount to account to prevent module accounts from sending disabled tokens to accounts
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the grammatical error in the changelog entry.

- * [#20343](https://github.com/cosmos/cosmos-sdk/pull/20343) Add a check in send moduleaccount to account to prevent module accounts from sending disabled tokens to accounts
+ * [#20343](https://github.com/cosmos/cosmos-sdk/pull/20343) Add a check in send module account to account to prevent module accounts from sending disabled tokens to accounts

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* [#20343](https://github.com/cosmos/cosmos-sdk/pull/20343) Add a check in send moduleaccount to account to prevent module accounts from sending disabled tokens to accounts
* [#20343](https://github.com/cosmos/cosmos-sdk/pull/20343) Add a check in send module account to account to prevent module accounts from sending disabled tokens to accounts

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between df01254 and 10c1b38.
Files selected for processing (8)
  • tests/integration/bank/keeper/deterministic_test.go (1 hunks)
  • tests/integration/distribution/keeper/msg_server_test.go (1 hunks)
  • tests/integration/evidence/keeper/infraction_test.go (1 hunks)
  • tests/integration/gov/keeper/keeper_test.go (1 hunks)
  • tests/integration/slashing/keeper/keeper_test.go (1 hunks)
  • tests/integration/staking/keeper/common_test.go (1 hunks)
  • tests/integration/staking/keeper/deterministic_test.go (1 hunks)
  • tests/integration/types/pagination_test.go (1 hunks)
Files not reviewed due to errors (1)
  • tests/integration/staking/keeper/deterministic_test.go (no review received)
Additional Context Used
Path-based Instructions (8)
tests/integration/gov/keeper/keeper_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/staking/keeper/common_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/types/pagination_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/bank/keeper/deterministic_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/evidence/keeper/infraction_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/slashing/keeper/keeper_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/staking/keeper/deterministic_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/distribution/keeper/msg_server_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (6)
tests/integration/gov/keeper/keeper_test.go (1)

103-104: Setting default parameters for the bank keeper ensures consistent initial conditions for tests.

tests/integration/staking/keeper/common_test.go (1)

162-163: Setting default parameters for the bank keeper ensures consistent initial conditions for tests.

tests/integration/types/pagination_test.go (1)

87-88: Setting default parameters for the bank keeper ensures consistent initial conditions for tests.

tests/integration/bank/keeper/deterministic_test.go (1)

110-111: Setting default parameters for the bank keeper ensures consistent initial conditions for tests.

tests/integration/evidence/keeper/infraction_test.go (1)

140-140: Ensure consistent parameter setting across tests.

This line sets the default parameters for the bankKeeper, which aligns with the PR's objective to standardize test setups across modules by ensuring consistent financial conditions.

tests/integration/slashing/keeper/keeper_test.go (1)

109-109: Ensure consistent parameter setting across tests.

This line sets the default parameters for the bankKeeper, which is crucial for ensuring that all tests operate under consistent financial conditions. This change is part of the PR's broader goal to standardize test setups across different modules.

@tac0turtle tac0turtle enabled auto-merge May 13, 2024 11:11
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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 10c1b38 and f01a23a.
Files selected for processing (2)
  • tests/integration/staking/keeper/deterministic_test.go (2 hunks)
  • tests/integration/types/filtered_pagination_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • tests/integration/types/filtered_pagination_test.go
Files skipped from review as they are similar to previous changes (1)
  • tests/integration/staking/keeper/deterministic_test.go

@tac0turtle tac0turtle added this pull request to the merge queue May 13, 2024
Merged via the queue into main with commit 3a75071 May 13, 2024
65 of 68 checks passed
@tac0turtle tac0turtle deleted the marko/check_senden branch May 13, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants