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

test(evm): Add tests for feemarket wrapper #66

Merged
merged 17 commits into from
Jan 6, 2025

Conversation

0xstepit
Copy link
Collaborator

@0xstepit 0xstepit commented Dec 23, 2024

Description

This PR add tests for the feemarket wrapper used in the x/evm module to perform custom decimals conversions.

THIS BRANCH HAS BEEN CREATED OUT OF #65

Summary by CodeRabbit

Release Notes

  • New Features

    • Added comprehensive test coverage for FeeMarket wrapper in EVM module
  • Bug Fixes

    • Improved error handling in GetParams method by adding nil check for BaseFee parameter
  • Tests

    • Introduced unit tests for GetBaseFee, CalculateBaseFee, and GetParams methods
    • Validated wrapper functionality under various scenarios including decimal conversions and edge cases

Copy link

coderabbitai bot commented Dec 23, 2024

Walkthrough

The pull request introduces comprehensive test coverage for the FeeMarketWrapper in the EVM module. A new test file feemarket_test.go has been added to validate the functionality of key methods like GetBaseFee, CalculateBaseFee, and GetParams. The changes include a minor enhancement to the GetParams method to improve nil parameter handling, ensuring more robust error prevention. The modifications aim to strengthen the reliability and predictability of fee market operations within the Evmos ecosystem.

Changes

File Change Summary
CHANGELOG.md Added entry: "Add tests for feemarket wrapper in EVM module with mock"
x/evm/wrappers/feemarket.go Added nil check before converting BaseFee parameter in GetParams method
x/evm/wrappers/feemarket_test.go New test file with comprehensive test cases for GetBaseFee, CalculateBaseFee, and GetParams methods

Sequence Diagram

sequenceDiagram
    participant Wrapper as FeeMarketWrapper
    participant Keeper as FeeMarketKeeper
    participant Context as SDK Context

    Wrapper->>Keeper: Request Parameters
    Keeper-->>Wrapper: Return Parameters
    Wrapper->>Wrapper: Check BaseFee Nil
    alt BaseFee Not Nil
        Wrapper->>Wrapper: Convert to 18 Decimals
    else BaseFee Nil
        Wrapper->>Wrapper: Handle Nil Case
    end
Loading

Poem

🐰 Hopping through the fee market's maze,
With tests that shine like diamond rays,
Nil checks dancing, decimals in flight,
Our wrapper now stands strong and bright!
Code quality hops with joyful grace 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 900a82d and d4ac2cd.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test-unit-cover
  • GitHub Check: Analyze (go)
  • GitHub Check: Run golangci-lint
  • GitHub Check: test-solidity
  • GitHub Check: run-lint
  • GitHub Check: Summary

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added the tests label Dec 23, 2024
@0xstepit 0xstepit marked this pull request as ready for review December 23, 2024 14:24
@0xstepit 0xstepit requested a review from a team as a code owner December 23, 2024 14:24
@0xstepit 0xstepit requested review from ramacarlucho and MalteHerrmann and removed request for a team December 23, 2024 14:24
Copy link

@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

🧹 Nitpick comments (7)
x/evm/wrappers/feemarket_test.go (1)

17-105: Encourage checks for negative/invalid base fees.
The table-driven tests cover many scenarios, such as zero and nil fee amounts, ensuring thorough testing. For completeness, consider adding a test case that explicitly checks how negative fees are handled, if those scenarios are expected or disallowed in your domain.

x/evm/types/scaling.go (1)

17-19: Improve clarity in the added comment.

The newly added comment clarifies the function contract but slightly repeats the same idea across lines 18 and 19. You can unify them into a single succinct sentence for better readability:

-// CONTRACT: The function should only be called when the coin denom is the EVM. This means that
-// should be called only when the code forces the denom to be the expected one.
+// CONTRACT: Only call this function when the coin denom is confirmed to be the EVM denom.
x/evm/wrappers/bank_test.go (4)

23-56: TestMintAmountToAccount: Confirm thorough negative coverage.

This test suite covers different decimal conversions and mint operations well. Consider adding a test case for negative amounts in the future to ensure that any invalid input is handled gracefully (even if your flow logically prevents negative amounts).


82-95: TestMintAmountToAccount: Provide additional error context.

When returning an error such as “failed to mint coins to account in bank wrapper,” it might be helpful to append contextual information (e.g., which address or token is involved) for easier debugging if the logs surface this error.


149-205: TestBurnAmountFromAccount: Verify partial burn scenarios.

The test covers integer-based full burns effectively. Consider verifying partial burn scenarios (e.g., turning 1.5 tokens into 0.5 tokens) to ensure correct decimal conversion in these intermediate conditions.


600-741: TestGetBalance: Potential large-amount boundary checks.

The test rightfully checks max int64. However, ensure that extremely large amounts formatted beyond int64 range (if ever possible in your domain) are either disallowed or handled properly.

CHANGELOG.md (1)

34-34: Reference PR #66 for consistency.

Consider adding a cross-reference to the new pull request #66 that builds upon #65, so readers know where to find the latest additions to the EVM bank wrapper tests.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa55561 and 900a82d.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • CHANGELOG.md (2 hunks)
  • go.mod (2 hunks)
  • x/erc20/keeper/msg_server_test.go (1 hunks)
  • x/erc20/types/mocks/BankKeeper.go (1 hunks)
  • x/evm/types/scaling.go (1 hunks)
  • x/evm/wrappers/bank_test.go (1 hunks)
  • x/evm/wrappers/feemarket.go (1 hunks)
  • x/evm/wrappers/feemarket_test.go (1 hunks)
  • x/evm/wrappers/testutil/mock.go (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • x/erc20/types/mocks/BankKeeper.go
  • x/evm/wrappers/testutil/mock.go
🔇 Additional comments (5)
x/evm/wrappers/feemarket.go (1)

55-57: Add a safeguard if negative base fees are invalid.
Currently, the code converts the base fee only if it is non-nil. If negative values are not expected, consider an additional defensive check or validation to prevent potential misconfigurations.

x/evm/wrappers/feemarket_test.go (1)

106-195: Great use of mocks and table-driven tests for CalculateBaseFee.
The structure is clean, uses a mock keeper, and covers various fee scenarios. This is a good approach to isolate and verify the wrapper's behavior.

x/erc20/keeper/msg_server_test.go (1)

19-19: Approve migration to go.uber.org/mock/gomock.

Switching from github.com/golang/mock to go.uber.org/mock is a recommended move as it aligns with best practices and ensures consistent usage with the rest of the codebase. No further changes needed.

x/evm/wrappers/bank_test.go (1)

272-306: TestSendCoinsFromModuleToAccount: Check coverage for zero or negative coins.

The suite already checks for zero conversions in one scenario (line 388). Consider verifying explicit negative amounts remain unreachable or cause errors. Properly documenting or testing such edge cases helps ensure clarity around what is and isn’t allowed.

go.mod (1)

50-50: LGTM! Appropriate migration to go.uber.org/mock

The change from github.com/golang/mock to go.uber.org/mock is correct as it's the new official home for gomock. The old package is correctly marked as indirect since it might still be required by other dependencies.

Let's verify that all gomock imports have been updated across the codebase:

Also applies to: 138-138

✅ Verification successful

Migration to go.uber.org/mock is complete and consistent

The verification shows:

  • No remaining imports of the old github.com/golang/mock/gomock package
  • All mock usages consistently use the new go.uber.org/mock/gomock package across:
    • x/evm/wrappers tests
    • x/erc20 tests and mocks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining direct usage of the old mock package
# This helps ensure the migration is complete

echo "Checking for any remaining direct imports of github.com/golang/mock..."
rg --type go "github.com/golang/mock/gomock"

echo "Verifying adoption of new mock package..."
rg --type go "go.uber.org/mock/gomock"

Length of output: 644

x/evm/wrappers/feemarket_test.go Show resolved Hide resolved
Copy link
Collaborator

@GAtom22 GAtom22 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @0xstepit!!

@0xstepit 0xstepit merged commit cd67b16 into main Jan 6, 2025
24 of 25 checks passed
@0xstepit 0xstepit deleted the stepit/feemarket-wrapper-test branch January 6, 2025 12:17
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.

4 participants