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

feat(evm): add simple validation for fun token fee in set params #2091

Merged
merged 5 commits into from
Oct 24, 2024

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Oct 24, 2024

@matthiasmatt matthiasmatt requested a review from a team as a code owner October 24, 2024 09:29
Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Walkthrough

The pull request introduces significant updates to the CHANGELOG.md, enhancing its structure and content to categorize changes clearly. It includes modifications across various modules, emphasizing state machine breaking changes, new features, improvements, and bug fixes. Additionally, it enhances error handling in the SetParams and UpdateParams methods within the keeper package, ensuring invalid parameters are flagged appropriately. New test cases are added to validate these changes, particularly focusing on parameter validation.

Changes

File Path Change Summary
CHANGELOG.md Updated format and content; added categories for changes; included references to GitHub issues.
app/evmante/evmante_validate_basic_test.go Added a test case for invalid parameters in TestEthValidateBasicDecorator; improved error handling.
x/evm/keeper/evm_state.go Updated SetParams method to include error handling for negative fees; modified method signature.
x/evm/keeper/msg_update_params.go Enhanced error handling in UpdateParams method; wrapped errors from SetParams.
x/evm/evmmodule/genesis.go Improved error handling in InitGenesis function for setting parameters and token mappings.
x/evm/keeper/grpc_query_test.go Added error handling in TestQueryParams and expanded test cases for various scenarios.

Possibly related PRs

Poem

🐇 In the changelog, we hop and bound,
With features new and fixes found.
Errors caught, and tests so bright,
The EVM dances in the light!
Hooray for changes, one and all,
A joyful leap, we heed the call! 🌟


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.

@matthiasmatt matthiasmatt enabled auto-merge (squash) October 24, 2024 09:30
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 64.45%. Comparing base (056edb3) to head (15904a4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
x/evm/keeper/msg_update_params.go 0.00% 4 Missing ⚠️
x/evm/keeper/evm_state.go 40.00% 2 Missing and 1 partial ⚠️
x/evm/evmmodule/genesis.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2091      +/-   ##
==========================================
- Coverage   64.48%   64.45%   -0.03%     
==========================================
  Files         270      270              
  Lines       21185    21190       +5     
==========================================
- Hits        13662    13659       -3     
- Misses       6573     6579       +6     
- Partials      950      952       +2     
Files with missing lines Coverage Δ
x/evm/evmmodule/genesis.go 76.62% <33.33%> (-3.13%) ⬇️
x/evm/keeper/evm_state.go 82.41% <40.00%> (-2.64%) ⬇️
x/evm/keeper/msg_update_params.go 0.00% <0.00%> (ø)

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

🧹 Outside diff range and nitpick comments (3)
app/evmante/evmante_validate_basic_test.go (2)

39-50: LGTM! Consider adding more test cases.

The test case effectively validates the negative fee scenario. Consider expanding test coverage with additional cases:

  • Zero value for CreateFuntokenFee
  • Maximum allowed value
  • Other invalid scenarios (if any)

210-218: LGTM! Consider using idiomatic error declaration.

The error handling is correct, but could be more idiomatic:

-			var err error
-			if tc.paramsSetup != nil {
-				err = deps.EvmKeeper.SetParams(deps.Ctx, tc.paramsSetup(&deps))
-			}
+			err := error(nil)
+			if tc.paramsSetup != nil {
+				err = deps.EvmKeeper.SetParams(deps.Ctx, tc.paramsSetup(&deps))
+			}
CHANGELOG.md (1)

139-139: Consider expanding the changelog entry to be more descriptive.

The current entry "feat(evm): add fun token creation fee validation" could be enhanced to provide more context about what validation was added and why. Consider expanding it to something like:

-feat(evm): add fun token creation fee validation
+feat(evm): add validation for fun token creation fee in SetParams to ensure valid fee configuration and prevent potential issues with token creation
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dd27f4b and 9b5bf02.

📒 Files selected for processing (4)
  • CHANGELOG.md (2 hunks)
  • app/evmante/evmante_validate_basic_test.go (2 hunks)
  • x/evm/keeper/evm_state.go (2 hunks)
  • x/evm/keeper/msg_update_params.go (1 hunks)
🔇 Additional comments (3)
x/evm/keeper/msg_update_params.go (1)

21-24: LGTM! Proper error handling implementation.

The enhanced error handling correctly propagates and wraps errors from SetParams, providing clear context about parameter validation failures. This improvement aligns with Go's best practices for error handling.

Let's verify the error handling implementation in the SetParams method:

✅ Verification successful

Let me try a different approach to verify the error handling implementation.


Based on the search results, I can now generate the final response as we have found the implementation of SetParams in x/evm/keeper/evm_state.go which shows the validation logic for the fun token fee.

Verified: Error handling and validation are properly implemented

The error handling in UpdateParams correctly propagates errors from SetParams, which includes validation of the CreateFuntokenFee parameter. The implementation in SetParams shows that:

  • It validates that CreateFuntokenFee is not negative
  • Returns a descriptive error message if validation fails
  • The error is properly wrapped in UpdateParams for clear error context
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the SetParams implementation to ensure it validates the fun token fee
# Expected: Find the SetParams implementation with validation logic

ast-grep --pattern 'func (k *Keeper) SetParams($_, $_) error {
  $$$
}'

Length of output: 73


Script:

#!/bin/bash
# Search for SetParams function using ripgrep for better context
rg "SetParams" -A 10 --type go

Length of output: 6646

x/evm/keeper/evm_state.go (2)

5-5: LGTM: Import addition is appropriate.

The fmt package import is correctly added to support the new error handling in SetParams.


120-126: LGTM: Basic validation implemented correctly.

The implementation correctly validates that CreateFuntokenFee is not negative and returns a clear error message. The error handling follows Go idioms.

x/evm/keeper/evm_state.go Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (2)
x/evm/evmmodule/genesis.go (1)

26-29: Consider enhancing error context for parameter validation failures.

The error handling implementation is correct and appropriate for genesis-time validation. However, consider adding more context to help diagnose which parameter failed validation.

Apply this diff to improve error reporting:

 err := k.SetParams(ctx, genState.Params)
 if err != nil {
+    ctx.Logger().Error("failed to set EVM module params", "params", genState.Params, "error", err)
     panic(fmt.Errorf("failed to set params during EVM genesis: %w", err))
 }
CHANGELOG.md (1)

71-71: Consider expanding the changelog entry with more details.

The current entry "feat(evm): add fun token creation fee validation" is quite brief. Consider adding more context about:

-- [#2091](https://github.com/NibiruChain/nibiru/pull/2091) - feat(evm): add fun token creation fee validation
+- [#2091](https://github.com/NibiruChain/nibiru/pull/2091) - feat(evm): add fun token creation fee validation to prevent negative fees during FunToken creation, addressing [code-423n4/2024-10-nibiru-zenith#33](https://github.com/code-423n4/2024-10-nibiru-zenith/issues/33)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9b5bf02 and 15904a4.

📒 Files selected for processing (3)
  • CHANGELOG.md (3 hunks)
  • x/evm/evmmodule/genesis.go (1 hunks)
  • x/evm/keeper/grpc_query_test.go (2 hunks)
🔇 Additional comments (2)
x/evm/keeper/grpc_query_test.go (2)

450-451: LGTM: Error handling added for SetParams

The addition of error checking for SetParams aligns with the PR objective of implementing parameter validation.


463-464: LGTM: Consistent error handling pattern

The error handling pattern is consistently applied to the second SetParams call, maintaining code quality and reliability.

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.

2 participants