10000 chore(evm): move wrappers utils to types pkg by GAtom22 · Pull Request #2905 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(evm): move wrappers utils to types pkg #2905

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

Merged
merged 3 commits into from
Oct 2, 2024
Merged

Conversation

GAtom22
Copy link
Contributor
@GAtom22 GAtom22 commented Oct 2, 2024

Description

Closes: #XXXX


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

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the correct branch (see PR Targeting)

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

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

Summary by CodeRabbit

  • New Features

    • Enhanced clarity and maintainability by standardizing the use of conversion functions from the types package across various methods in the BankWrapper struct.
  • Refactor

    • Simplified function calls for EVM coin denomination and decimal values by removing package prefixes.
    • Updated test cases to reflect changes in package naming and function calls.
  • Bug Fixes

    • Improved handling of balance adjustments by replacing outdated function references.

Copy link
Contributor
coderabbitai bot commented Oct 2, 2024

Walkthrough

The changes in this pull request primarily involve the refactoring of function calls related to EVM coin denomination and balance adjustments. The wrappers package has been replaced with the types package across several files, including state_object.go, scaling.go, and scaling_test.go. This refactoring updates method calls to ensure they reference the new package structure while maintaining the existing functionality. The overall structure of the affected classes and test cases remains unchanged.

Changes

File Path Change Summary
x/evm/statedb/state_object.go Replaced wrappers.AdjustExtraDecimalsBigInt with types.AdjustExtraDecimalsBigInt in AddBalance and SubBalance methods.
x/evm/types/scaling.go Renamed package from wrappers to types. Updated functions to call GetEVMCoinDenom() and GetEVMCoinDecimals() directly from types.
x/evm/types/scaling_test.go Renamed package from wrappers_test to types_test. Updated function calls to use evmtypes directly instead of wrappers.
x/evm/wrappers/bank.go Updated method calls in BankWrapper to use functions from the types package for conversions.

Possibly related PRs

  • chore(evm): adjust extra decimals on stateDB methods #2897: This PR adjusts the handling of extra decimals in the stateObject methods, specifically modifying the AddBalance and SubBalance methods, which are also the focus of the main PR's changes in the state_object.go file.
  • chore(evm): move chain_config to types #2898: This PR involves moving chain configuration to the types section, which may relate to the overall structure and organization of the codebase, including the handling of types used in balance adjustments in the main PR.

Suggested labels

proto, build, CLI, precompile

Suggested reviewers

  • hanchon
  • fedekunze
  • ramacarlucho

🐇 In the code where coins do dance,
A shift of types gives them a chance.
From wrappers to types, they leap and twirl,
Adjusting balances in a digital whirl.
With every call, the logic stays bright,
Hopping along, 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.

@github-actions github-actions bot added the tests label Oct 2, 2024
@GAtom22 GAtom22 marked this pull request as ready for review October 2, 2024 13:07
@GAtom22 GAtom22 requested a review from a team as a code owner October 2, 2024 13:07
@GAtom22 GAtom22 requested review from hanchon and MalteHerrmann and removed request for a team October 2, 2024 13:07
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 UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 926fce6 and 42f1371.

📒 Files selected for processing (4)
  • x/evm/statedb/state_object.go (2 hunks)
  • x/evm/types/scaling.go (4 hunks)
  • x/evm/types/scaling_test.go (5 hunks)
  • x/evm/wrappers/bank.go (4 hunks)
🔇 Additional comments (18)
x/evm/types/scaling.go (4)

30-31: Changes in ConvertEvmCoinFrom18Decimals are consistent and correct.

The modifications in this function align with the changes made in the previous function, maintaining consistency throughout the file. The error message has been appropriately updated to reflect the new method call.

Also applies to: 34-34


43-43: Changes in ConvertCoinsFrom18Decimals are consistent and correct.

The modifications in this function maintain consistency with the changes made in the previous functions. The overall logic of the function remains intact, ensuring that only the EVM coin's amount is converted while preserving other coins in the collection.

Also applies to: 48-48


17-18: Function updates look good, verify new method accessibility.

The changes to MustConvertEvmCoinTo18Decimals simplify the function calls by removing the evmtypes package prefix. This aligns with the move to the types package.

To ensure the new methods are properly defined and accessible, run the following script:

#!/bin/bash
# Description: Verify the existence and accessibility of GetEVMCoinDenom() and GetEVMCoinDecimals() methods.

# Test 1: Check for the definition of GetEVMCoinDenom()
echo "Checking for GetEVMCoinDenom() definition:"
rg --type go 'func GetEVMCoinDenom\(\)' x/evm/types/

# Test 2: Check for the definition of GetEVMCoinDecimals()
echo "Checking for GetEVMCoinDecimals() definition:"
rg --type go 'func GetEVMCoinDecimals\(\)' x/evm/types/

Also applies to: 21-21


4-4: Package name change looks good.

The package name change from wrappers to types aligns with the PR objective of moving wrapper utils to the types package.

To ensure this change doesn't break existing imports, run the following script:

✅ Verification successful

Package name change verified.

No remaining imports of the wrappers package found, and no naming conflicts detected in the types package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining imports of the old package name and verify no naming conflicts in the types package.

# Test 1: Search for any remaining imports of the old package name
echo "Checking for remaining imports of 'wrappers' package:"
rg --type go 'import.*".*evm/types/wrappers"'

# Test 2: Check for potential naming conflicts in the types package
echo "Checking for potential naming conflicts in the types package:"
rg --type go '^type \w+ struct {' x/evm/types/

Length of output: 692


Script:

#!/bin/bash
# Description: Check for any remaining imports of the old package name and verify no naming conflicts in the types package.

# Test 1: Search for any remaining imports of the old package name
echo "Checking for remaining imports of 'wrappers' package:"
rg --type go 'import.*".*evm/types/wrappers"'

# Test 2: Check for potential naming conflicts in the types package
echo "Checking for potential naming conflicts in the types package:"
rg --type go '^type \w+ struct {' x/evm/types/

Length of output: 452


Script:

#!/bin/bash
# Description: Check for any remaining imports of the old package name and verify no naming conflicts in the types package.

# Test 1: Search for any remaining imports of the old package name
echo "Checking for remaining imports of 'wrappers' package:"
rg --type go 'import.*".*evm/types/wrappers"'

# Test 2: Check for potential naming conflicts in the types package
echo "Checking for potential naming conflicts in the types package:"
rg --type go '^type \w+ struct \{' x/evm/types/

Length of output: 4246

x/evm/wrappers/bank.go (5)

44-44: LGTM: Consistent use of types package

The change to use types.ConvertEvmCoinFrom18Decimals is consistent with the PR objective and improves code clarity by explicitly showing where the function is defined.


62-62: LGTM: Consistent modification

The change to use types.ConvertEvmCoinFrom18Decimals is consistent with the PR objective and the previous modification, maintaining consistency throughout the file.


92-92: LGTM: Consistent modification

The change to use types.ConvertCoinsFrom18Decimals is consistent with the PR objective and previous modifications, maintaining consistency throughout the file.


101-101: LGTM: Consistent modification and overall improvement

The change to use types.ConvertCoinsFrom18Decimals is consistent with the PR objective and previous modifications. This final change completes the set of modifications in this file, resulting in a consistent use of the types package for all conversion functions.

Overall, these changes improve code clarity and organization by explicitly showing where these functions are defined. The modifications align well with the PR objective of moving wrapper utils to the types package.


85-85: LGTM with a suggestion: Verify error handling

The change to use types.MustConvertEvmCoinTo18Decimals is consistent with the PR objective. However, the use of a "Must" function implies that this function will panic if an error occurs.

Please verify that potential panics are properly handled in the calling code. Run the following script to check for proper error handling:

x/evm/statedb/state_object.go (3)

113-113: LGTM. Consistent with the change in AddBalance.

The change from wrappers.AdjustExtraDecimalsBigInt to types.AdjustExtraDecimalsBigInt in the SubBalance method is consistent with the similar change made in the AddBalance method. This consistency is good for maintaining a uniform codebase.


Line range hint 1-265: Overall assessment: Changes are consistent and align with PR objectives.

The modifications in this file are part of the larger effort to move wrapper utils to the types package. The functionality of the stateObject remains unchanged, which is good.

To ensure consistency across the codebase:

  1. Check other files in the PR for similar changes from wrappers to types.
  2. Update any relevant documentation or comments that might reference the old wrappers package.
  3. Consider updating any tests that might be affected by this change.

Please run the following script to check for similar changes in other files:

#!/bin/bash
# Description: Check for similar changes from wrappers to types in other files

# Search for files with changes from wrappers to types
echo "Files with changes from wrappers to types:"
rg --type go -e 'wrappers\.(\w+)' -e 'types\.\1' --stats

# List files that still use the wrappers package
echo "Files still using the wrappers package:"
rg --type go 'import\s+.*"github\.com/evmos/evmos/v\d+/x/evm/wrappers"' -l

103-103: LGTM. Verify imports and usage across the codebase.

The change from wrappers.AdjustExtraDecimalsBigInt to types.AdjustExtraDecimalsBigInt aligns with the PR objective of moving wrapper utils to the types package. The functionality remains the same, which is good.

Please run the following script to ensure that all imports and usages have been updated correctly across the codebase:

✅ Verification successful

Import and usage migration verified successfully.

All instances of AdjustExtraDecimalsBigInt have been correctly migrated from the wrappers package to the types package. No remaining references to wrappers.AdjustExtraDecimalsBigInt were found, and existing usages are properly updated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify imports and usages of AdjustExtraDecimalsBigInt

# Check for any remaining imports of wrappers.AdjustExtraDecimalsBigInt
echo "Checking for remaining imports of wrappers.AdjustExtraDecimalsBigInt:"
rg --type go 'import\s+.*"github\.com/evmos/evmos/v\d+/x/evm/wrappers"'

# Check for any remaining usages of wrappers.AdjustExtraDecimalsBigInt
echo "Checking for remaining usages of wrappers.AdjustExtraDecimalsBigInt:"
rg --type go 'wrappers\.AdjustExtraDecimalsBigInt'

# Check for new imports of types.AdjustExtraDecimalsBigInt
echo "Checking for new imports of types.AdjustExtraDecimalsBigInt:"
rg --type go 'import\s+.*"github\.com/evmos/evmos/v\d+/x/evm/types"'

# Check for new usages of types.AdjustExtraDecimalsBigInt
echo "Checking for new usages of types.AdjustExtraDecimalsBigInt:"
rg --type go 'types\.AdjustExtraDecimalsBigInt'

Length of output: 630


Script:

#!/bin/bash
# Description: Verify imports and usages of AdjustExtraDecimalsBigInt

# Check for any remaining imports of wrappers.AdjustExtraDecimalsBigInt
echo "Checking for remaining imports of wrappers.AdjustExtraDecimalsBigInt:"
rg --type go 'import\s+.*"github\.com/evmos/evmos/v\d+/x/evm/wrappers"'

# Check for any remaining usages of wrappers.AdjustExtraDecimalsBigInt
echo "Checking for remaining usages of wrappers.AdjustExtraDecimalsBigInt:"
rg --type go 'wrappers\.AdjustExtraDecimalsBigInt'

# Check for new imports of types.AdjustExtraDecimalsBigInt
echo "Checking for new imports of types.AdjustExtraDecimalsBigInt:"
rg --type go 'import\s+.*"github\.com/evmos/evmos/v\d+/x/evm/types"'

# Check for new usages of types.AdjustExtraDecimalsBigInt
echo "Checking for new usages of types.AdjustExtraDecimalsBigInt:"
rg --type go 'types\.AdjustExtraDecimalsBigInt'

Length of output: 1045

x/evm/types/scaling_test.go (6)

4-4: LGTM: Package name change is appropriate.

The package name change from wrappers_test to types_test aligns with the PR objective of moving wrapper utils to the types package and is consistent with the file location.


83-83: LGTM: Function call updated correctly.

The change from wrappers.MustConvertEvmCoinTo18Decimals to evmtypes.MustConvertEvmCoinTo18Decimals is consistent with the PR objective. The function signature remains the same, ensuring that the test logic is unaffected.


149-149: LGTM: Function call updated appropriately.

The change from wrappers.ConvertEvmCoinFrom18Decimals to evmtypes.ConvertEvmCoinFrom18Decimals aligns with the PR objective. The function signature remains unchanged, preserving the test logic integrity.


209-209: LGTM: Function call updated correctly.

The modification from wrappers.ConvertCoinsFrom18Decimals to evmtypes.ConvertCoinsFrom18Decimals is in line with the PR objective. The function signature remains intact, ensuring that the test logic is preserved.


262-262: LGTM: Function call updated appropriately.

The change from wrappers.AdjustExtraDecimalsBigInt to evmtypes.AdjustExtraDecimalsBigInt is consistent with the PR objective. The function signature remains the same, ensuring that the test logic is unaffected.


Line range hint 1-269: Overall assessment: Changes are consistent and well-implemented.

The modifications in this file align perfectly with the PR objective of moving wrapper utils to the types package. All changes are limited to updating the package name from wrappers to evmtypes, which is a good practice for maintaining code organization. The test logic remains unchanged, ensuring that the existing functionality is preserved. These changes contribute to a more organized and maintainable codebase.

@GAtom22 GAtom22 merged commit d695ada into main Oct 2, 2024
50 of 53 checks passed
@GAtom22 GAtom22 deleted the GAtom22/move-utils branch October 2, 2024 13:47
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
0