-
Notifications
You must be signed in to change notification settings - Fork 902
chore(tests): reduce code in files for 'test' build #2935
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
Conversation
WalkthroughThe pull request includes significant changes to the Ethereum Virtual Machine (EVM) codebase. Key modifications involve the removal of build constraints in Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Outside diff range and nitpick comments (3)
x/evm/types/denom.go (3)
17-26
: LGTM: Constants and Decimals type are well-defined.The constants and Decimals type are appropriately defined. However, consider adding a brief comment explaining why these specific decimal values (6 and 18) are chosen, as it might not be immediately clear to all developers why these are the supported options.
28-54
: Approve Validate method, suggest improvement for ConversionFactor.The Validate method is well-implemented. For the ConversionFactor method:
- Consider removing the default case and replacing it with a panic, as unsupported decimals should never reach this point due to prior validation.
- Add error handling to catch potential overflow when calculating large conversion factors.
Here's a suggested improvement for ConversionFactor:
func (d Decimals) ConversionFactor() (math.Int, error) { switch d { case SixDecimals: return math.NewInt(1e12), nil case EighteenDecimals: return math.NewInt(1), nil default: return math.Int{}, fmt.Errorf("unsupported decimals: %d", d) } }This change ensures that the method only handles valid Decimal values and provides proper error handling.
64-83
: LGTM: ChainsCoinInfo provides good initialization options.The ChainsCoinInfo map is well-structured and provides a clear way to initialize different coin configurations based on chain ID.
Consider the following architectural improvement for future scalability:
Instead of hardcoding the ChainsCoinInfo map, consider implementing a more flexible configuration system. This could involve reading from a configuration file or using a database, allowing for easier addition or modification of chain configurations without code changes.
Implement a function to dynamically add or update chain configurations at runtime, which could be useful for testing or dynamic chain management.
Example:
func AddChainCoinInfo(chainID string, info EvmCoinInfo) { ChainsCoinInfo[chainID] = info }These changes would make the system more adaptable to future requirements and easier to maintain.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
- x/evm/core/vm/custom_eip.go (0 hunks)
- x/evm/core/vm/custom_eip_testing.go (0 hunks)
- x/evm/types/config.go (1 hunks)
- x/evm/types/config_testing.go (1 hunks)
- x/evm/types/configurator.go (0 hunks)
- x/evm/types/denom.go (1 hunks)
- x/evm/types/denom_config.go (0 hunks)
- x/evm/types/denom_config_testing.go (2 hunks)
💤 Files with no reviewable changes (4)
- x/evm/core/vm/custom_eip.go
- x/evm/core/vm/custom_eip_testing.go
- x/evm/types/configurator.go
- x/evm/types/denom_config.go
🧰 Additional context used
📓 Learnings (1)
x/evm/types/denom_config_testing.go (3)
Learnt from: GAtom22 PR: evmos/evmos#2898 File: app/ante/testutils/testutils.go:0-0 Timestamp: 2024-10-08T18:06:02.188Z Learning: In `app/ante/testutils/testutils.go`, the variables `denom` and `decimals` must be retained and used when resetting the chain config to prevent nil pointer errors. Removing these variables can lead to issues because they are required by `WithEVMCoinInfo(denom, decimals)` during configuration.
Learnt from: GAtom22 PR: evmos/evmos#2898 File: app/ante/testutils/testutils.go:0-0 Timestamp: 2024-10-01T21:37:36.764Z Learning: In `app/ante/testutils/testutils.go`, the variables `denom` and `decimals` must be retained and used when resetting the chain config to prevent nil pointer errors. Removing these variables can lead to issues because they are required by `WithEVMCoinInfo(denom, decimals)` during configuration.
Learnt from: GAtom22 PR: evmos/evmos#2898 File: app/ante/testutils/testutils.go:0-0 Timestamp: 2024-10-08T18:05:59.749Z Learning: In `app/ante/testutils/testutils.go`, the variables `denom` and `decimals` must be retained and used when resetting the chain config to prevent nil pointer errors. Removing these variables can lead to issues because they are required by `WithEVMCoinInfo(denom, decimals)` during configuration.
🔇 Additional comments (5)
x/evm/types/denom.go (2)
1-15
: LGTM: Package declaration and imports are appropriate.The package name and imports are well-suited for the file's purpose and location within the project structure.
56-62
: LGTM: EvmCoinInfo struct is well-defined.The EvmCoinInfo struct is appropriately designed with clear and relevant fields for representing EVM denom information.
x/evm/types/config_testing.go (3)
40-41
:⚠️ Potential issuePotential undefined field
extendedDefaultExtraEIPs
The code references
ec.extendedDefaultExtraEIPs
, but according to the AI-generated summary, theextendedDefaultExtraEIPs
field has been removed from theEVMConfigurator
struct. This may cause a compilation error due to an undefined field. Please confirm whetherextendedDefaultExtraEIPs
is still a field ofEVMConfigurator
.Run the following script to verify if
extendedDefaultExtraEIPs
is defined withinEVMConfigurator
:
44-45
:⚠️ Potential issuePotential undefined field
extendedEIPs
The code references
ec.extendedEIPs
, but according to the AI-generated summary, theextendedEIPs
field has been removed from theEVMConfigurator
struct. This could lead to a compilation error due to an undefined field. Please check whetherextendedEIPs
is still part ofEVMConfigurator
.Run the following script to verify if
extendedEIPs
is defined withinEVMConfigurator
:
36-37
:⚠️ Potential issuePotential undefined field
evmCoinInfo
The code references
ec.evmCoinInfo
, but according to the AI-generated summary, theevmCoinInfo
field has been removed from theEVMConfigurator
struct. This may result in a compilation error due to an undefined field. Please verify whetherevmCoinInfo
is still part ofEVMConfigurator
.Run the following script to verify if
evmCoinInfo
is defined withinEVMConfigurator
:
Is not something modified with this PR, but:
Is a bit confusing since the ChainConfig is only one of the 3 variables are set. I would call it just ResetTestConfig to avoid confusion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, very nice refactoring! 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (6)
app/config_testing.go (1)
Line range hint
1-94
: Overall assessment: LGTM with minor improvement.The change in this file is minimal but valuable. It improves the clarity of the code by more accurately describing the function's purpose. The rest of the file remains unchanged, and the modification doesn't introduce any new functionality or alter existing behavior.
To further enhance the code:
- Consider updating the comments for the
InitializeAppConfiguration
function to reflect the use ofResetTestConfig()
instead ofResetTestChainConfig()
.- If there are any documentation or test files referencing the old method name, ensure they are updated as well.
x/evm/keeper/setup_test.go (1)
Line range hint
102-103
: Consider addressing commented-out lines with nolint directives.There are two lines with
nolint:staticcheck
comments:denom := evmtypes.GetEVMCoinDenom() //nolint:staticcheck decimals := evmtypes.GetEVMCoinDecimals() //nolint:staticcheckThese nolint directives might be masking potential issues or indicating outdated code. Consider investigating if these can be addressed or updated to remove the need for the nolint comments.
x/evm/types/msg_test.go (4)
Line range hint
71-80
: Consider Removing or Restoring Commented-Out AssertionsIn the
TestMsgEthereumTx_Constructor
function, there are several commented-out assertion lines. If these assertions are still relevant, consider uncommenting them to ensure they are executed during tests. If they are no longer needed, it's cleaner to remove them from the code.
Line range hint
319-320
: Use Specificnolint
Directives Instead of//nolint:all
The directive
//nolint:all
suppresses all linter warnings, which might inadvertently hide other important issues. It's better to specify the exact linter you intend to disable for clearer intent and to prevent suppressing unexpected warnings.Consider specifying the linter, for example:
//nolint:staticcheck // Reason for disabling the linter
Line range hint
694-695
: Simplify the Initialization ofexp_10_80
The multiplication by
big.NewInt(1)
is redundant when initializingexp_10_80
. You can simplify the expression by removing the unnecessary multiplication.Apply this diff to simplify the initialization:
-exp_10_80 := new(big.Int).Mul(big.NewInt(1), new(big.Int).Exp(big.NewInt(10), big.NewInt(80), nil)) +exp_10_80 := new(big.Int).Exp(big.NewInt(10), big.NewInt(80), nil)
Line range hint
749-758
: Handle Errors Explicitly inencodeDecodeBinary
FunctionIn the
encodeDecodeBinary
function, consider handling errors explicitly rather than returning them directly. This can improve readability and maintain consistency in error handling throughout the codebase.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (11)
- app/ante/testutils/testutils.go (1 hunks)
- app/config_testing.go (1 hunks)
- x/evm/core/vm/custom_eip_testing.go (1 hunks)
- x/evm/keeper/grpc_query_test.go (2 hunks)
- x/evm/keeper/setup_test.go (1 hunks)
- x/evm/types/config.go (1 hunks)
- x/evm/types/config_testing.go (2 hunks)
- x/evm/types/configurator_test.go (2 hunks)
- x/evm/types/denom_config_testing.go (2 hunks)
- x/evm/types/msg_test.go (1 hunks)
- x/evm/types/scaling_test.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- x/evm/types/config.go
- x/evm/types/denom_config_testing.go
🧰 Additional context used
🔇 Additional comments (18)
x/evm/types/config_testing.go (3)
36-37
: Verify the usage ofevmCoinInfo
The change from
ec.evmDenom
toec.evmCoinInfo
suggests a modification in how EVM coin information is managed. Please confirm thatevmCoinInfo
contains all necessary information previously held inevmDenom
.Could you provide more details about the structure of
evmCoinInfo
to ensure this change is correct and complete?
55-55
: Approved: Method rename improves clarityThe renaming of
ResetTestChainConfig
toResetTestConfig
is a good improvement. It better reflects the method's functionality, as it resets multiple configurations, not just the chain config. This change addresses the feedback provided by user 0xstepit in the PR comments.
63-63
: Approved: Error message updated consistentlyThe error message in
setTestChainConfig
has been correctly updated to reference the new method nameResetTestConfig
. This change is consistent with the method rename and provides clear instructions to users.app/config_testing.go (1)
42-42
: Approve the method renaming for improved clarity.The change from
ResetTestChainConfig()
toResetTestConfig()
aligns with the feedback provided by user 0xstepit. This new name more accurately reflects the function's purpose, as it resets multiple configuration aspects, not just the chain config.To ensure this change is consistent across the codebase, let's verify the method definition and any other calls to this method:
✅ Verification successful
Method renaming verified successfully.
The method
ResetTestConfig()
has been consistently renamed across the codebase. No remaining references toResetTestChainConfig()
were found.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the method renaming across the codebase # Test 1: Check for the new method name definition echo "Checking for the new method name definition:" ast-grep --lang go --pattern 'func ($$_) ResetTestConfig() { $$$ }' # Test 2: Check for any remaining occurrences of the old method name echo "Checking for any remaining occurrences of the old method name:" rg --type go 'ResetTestChainConfig' # Test 3: Check for other occurrences of the new method name echo "Checking for other occurrences of the new method name:" rg --type go 'ResetTestConfig'Length of output: 2337
x/evm/keeper/setup_test.go (1)
106-106
: Method name change aligns with the suggested improvement.The change from
ResetTestChainConfig()
toResetTestConfig()
aligns with the suggestion made by user 0xstepit in the PR comments. This new name better reflects the function's purpose of resetting multiple configuration variables, not just the ChainConfig.To ensure this change is consistent across the codebase, let's verify the method definition and its usage:
✅ Verification successful
Method renaming successfully verified.
All instances of
ResetTestChainConfig
have been removed and replaced withResetTestConfig
across the codebase. The new method is defined correctly and used consistently in all relevant test files.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the method name change and its usage # Test 1: Check if the method is defined correctly in the types package ast-grep --lang go --pattern 'func (configurator *EVMConfigurator) ResetTestConfig() { $$$ }' # Test 2: Search for any remaining usage of the old method name rg --type go 'ResetTestChainConfig' # Test 3: Confirm the usage of the new method name rg --type go 'ResetTestConfig'Length of output: 1480
x/evm/types/configurator_test.go (3)
59-59
: Approved: Function renaming improves clarityThe change from
ResetTestChainConfig()
toResetTestConfig()
aligns with the feedback provided by user 0xstepit. This renaming improves clarity by accurately reflecting the function's purpose, which is to reset multiple configuration aspects, not just the chain config.
141-141
: Approved: Consistent function renamingThe change from
ResetTestChainConfig()
toResetTestConfig()
on this line maintains consistency with the previous change. This ensures that the new function name is used consistently throughout the test file.
Line range hint
1-155
: Overall assessment: Changes improve code clarityThe modifications in this file are minimal and focused, consisting of renaming
ResetTestChainConfig()
toResetTestConfig()
in two locations. These changes improve code clarity by more accurately describing the function's purpose, as suggested in the PR comments. The updates are consistent throughout the file and do not alter the test logic or functionality. No additional issues or potential improvements were identified in the changed code.app/ante/testutils/testutils.go (1)
109-109
: Approve the method renaming and suggest verification.The change from
ResetTestChainConfig
toResetTestConfig
aligns with the feedback provided in the PR comments. This new name is more general and potentially more accurate if the function resets more than just the chain configuration.To ensure this change doesn't introduce any issues, please run the following script to check for any remaining occurrences of
ResetTestChainConfig
in the codebase:If the script returns any results, those occurrences should be updated to use the new method name
ResetTestConfig
.x/evm/types/scaling_test.go (6)
146-146
: Consistent application of renamed reset method.The change from
ResetTestChainConfig()
toResetTestConfig()
is consistently applied here as well.
206-206
: Consistent application of renamed reset method.The change from
ResetTestChainConfig()
toResetTestConfig()
is consistently applied in this test case as well.
260-260
: Consistent application of renamed reset method.The change from
ResetTestChainConfig()
toResetTestConfig()
is consistently applied in this test case as well.
312-312
: Consistent application of renamed reset method.The change from
ResetTestChainConfig()
toResetTestConfig()
is consistently applied in this final test case as well.
Line range hint
1-324
: Summary: Consistent renaming of reset method across all testsThe changes in this file consistently rename
ResetTestChainConfig()
toResetTestConfig()
across all test functions. This change aligns with the feedback provided in the PR comments and improves the clarity of the code by using a more accurate function name. The modification doesn't affect the logic or structure of the tests.To ensure completeness of the change:
- Verify that the
ResetTestConfig()
method in theEVMConfigurator
struct correctly resets all necessary configurations, not just the chain config.- Update any relevant documentation or comments that might still reference the old method name.
To ensure this change is complete, please run the following commands:
#!/bin/bash # Search for any remaining instances of ResetTestChainConfig in Go files rg "ResetTestChainConfig" --type go # Search for any mentions of ResetTestChainConfig in comments or documentation rg "ResetTestChainConfig" --type md --type txt
80-80
: Consistent renaming of reset method.The change from
ResetTestChainConfig()
toResetTestConfig()
is consistent with the feedback provided in the PR comments. This new name is more generic and likely more accurate if the function resets more than just the chain config.To ensure this change is consistent throughout the codebase, please run the following command:
✅ Verification successful
No remaining instances of
ResetTestChainConfig
found.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining instances of ResetTestChainConfig rg "ResetTestChainConfig" --type goLength of output: 82
Script:
#!/bin/bash # Search for any remaining instances of ResetTestChainConfig in all file types rg "ResetTestChainConfig"Length of output: 25
x/evm/core/vm/custom_eip_testing.go (2)
7-11
: Good addition: Enhances code clarity with explanatory commentsThe added comments provide clear context about the purpose of this file and why certain functions are included only for testing. This improves the readability and maintainability of the code.
17-25
:⚠️ Potential issueHandle potential errors from
GetActivatorsEipNames()
If
GetActivatorsEipNames()
can return an error, it's important to handle it appropriately to prevent unexpected issues during initialization.Consider modifying the
init()
function to handle possible errors:func init() { - keys := GetActivatorsEipNames() + keys, err := GetActivatorsEipNames() + if err != nil { + // Handle the error, e.g., log it or fail initialization + panic(fmt.Sprintf("failed to get activator EIP names: %v", err)) + } originalActivators = make(map[string]func(*JumpTable), len(keys)) for _, k := range keys { originalActivators[k] = activators[k] } }If
GetActivatorsEipNames()
does not return an error, consider clarifying this by updating its function signature or adding comments to indicate that it is safe and cannot fail.To verify whether
GetActivatorsEipNames()
handles errors, you can run:x/evm/types/msg_test.go (1)
122-122
: Ensure All References to Renamed Method Are UpdatedThe method
ResetTestChainConfig()
has been renamed toResetTestConfig()
. Please verify that all references to the old method name have been updated throughout the codebase to prevent potential issues.You can run the following script to confirm that there are no remaining references:
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...
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...
Unreleased
section inCHANGELOG.md
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores
Tests