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: prevent setting invalid before send hook #8535

Merged
merged 2 commits into from
Jul 24, 2024
Merged

Conversation

mattverse
Copy link
Member

Closes: #XXX

What is the purpose of the change

Blocks Setting invalid setting before send hooks

Testing and Verifying

This change added new etest

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@mattverse mattverse requested a review from PaddyMc July 23, 2024 06:59
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

This update enhances the "Before Send" hook functionality by implementing validation for contract addresses, preventing invalid configurations that could lead to runtime errors. The changes include a new validation logic in the setBeforeSendHook method and an accompanying test case to ensure robust error handling. Overall, these improvements strengthen the system's integrity when handling token transfers.

Changes

Files Summary
CHANGELOG.md Added an entry noting the introduction of a feature to validate "Before Send" hooks, enhancing system robustness.
x/tokenfactory/keeper/before_send.go Modified setBeforeSendHook method to include contract address validation and improved error handling for non-existent contracts.
x/tokenfactory/keeper/before_send_test.go Introduced TestInvalidSetBeforeSendHook to validate behavior when an invalid hook is set, ensuring no hooks are registered for new denominations.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ef9e43 and 0d1301a.

Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • x/tokenfactory/keeper/before_send.go (2 hunks)
  • x/tokenfactory/keeper/before_send_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
Additional comments not posted (10)
x/tokenfactory/keeper/before_send.go (5)

6-6: Import Justification: strings package.

The strings package is imported and is used for error handling and string manipulation in the updated error handling logic.


30-51: Enhanced Error Handling and Validation Logic.

The updated setBeforeSendHook method includes robust validation logic for contract addresses. The cache context, Bech32 address conversion, and Sudo call enhance the reliability of the function. Ensure that the error message "no such contract" is consistent across different environments and versions of dependencies.


33-33: Correct Usage of Cache Context.

The cache context is correctly created using ctx.CacheContext() to test the validity of the contract address without affecting the main context.


35-38: Address Conversion and Error Handling.

The Bech32 address conversion using sdk.AccAddressFromBech32 is correctly implemented. The error handling ensures that any invalid address is caught and reported.


40-51: Message Construction and Validation Logic.

The TrackBeforeSendSudoMsg is correctly constructed and marshaled into JSON. The Sudo function call on the contractKeeper ensures the validation of the contract address. The error handling for "no such contract" is appropriately implemented.

x/tokenfactory/keeper/before_send_test.go (5)

9-9: Import Justification: banktypes package.

The banktypes package is imported and is used for constructing MsgSend messages in the tests.


143-187: New Test Function: TestInvalidSetBeforeSendHook.

The new test function TestInvalidSetBeforeSendHook correctly validates the behavior when an invalid "before send" hook is set. It ensures that the system handles invalid configurations gracefully and does not register invalid hooks.


144-144: Correct Usage of SkipIfWSL.

The SkipIfWSL method is correctly called to ensure that the test is skipped if running on Windows Subsystem for Linux (WSL).


178-184: Validation of Invalid Address Handling.

The test correctly sets an invalid address as the "before send" hook and verifies that an error is returned. It also ensures that no hooks are registered for the denomination, validating the robustness of the system.


180-180: Correct Error Assertion.

The s.Require().Error(err) assertion correctly validates that an error is returned when an invalid address is set as the "before send" hook.


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.
    • @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 as 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.

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

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.

@mattverse mattverse added the V:state/breaking State machine breaking PR label Jul 23, 2024
@PaddyMc PaddyMc merged commit dfe91e0 into main Jul 24, 2024
1 check passed
@PaddyMc PaddyMc deleted the mattverse/aaaaaaa branch July 24, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/tokenfactory V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants