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

refactor(evm): embeds #1984

Merged
merged 17 commits into from
Aug 6, 2024
Merged

refactor(evm): embeds #1984

merged 17 commits into from
Aug 6, 2024

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Aug 1, 2024

Purpose / Abstract

  • Refactor x/evm/embeds for simpler embedding and contract reading

Summary by CodeRabbit

  • Documentation

    • Revised the CHANGELOG for enhanced clarity and readability.
  • Refactor

    • Simplified contract loading logic by removing unnecessary error checks in tests and contract initialization.
    • Updated various smart contract ABI references for consistency and clarity.
  • Bug Fixes

    • Corrected contract initialization and ABI handling to improve reliability in tests and contract interactions.
  • Chores

    • Optimized test suite configurations for more efficient setups and validations.

Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This update streamlines contract management and enhances error handling across various files. Key modifications include removing redundant error checks during contract loading, adopting consistent ABI naming conventions, and refining test setups for improved clarity. The changes aim to boost the maintainability and robustness of the codebase while ensuring comprehensive test coverage.

Changes

Files Change Summary
CHANGELOG.md Minor formatting adjustments; added entry for PR #1984 regarding evm module refactor.
eth/rpc/rpcapi/eth_api_test.go Simplified contractData initialization by removing error handling, raising concerns about subsequent test validity.
x/evm/evmmodule/genesis_test.go Changed contract initialization method, removing the need for MustLoad() in test setup.
x/evm/evmtest/tx.go Altered contract parameter type from SmartContractFixture to CompiledEvmContract, streamlining data access and simplifying contract handling.
x/evm/keeper/erc20_test.go Changed ABI reference in tests from Contract_ERC20Minter to SmartContract_ERC20Minter.
x/evm/keeper/grpc_query_test.go Simplified contract loading; altered response validation logic in tests, potentially reducing robustness.
x/evm/keeper/msg_ethereum_tx_test.go Increased gas limit in transaction tests; simplified contract loading with direct assignment.
x/evm/keeper/msg_server.go Updated ABI reference from Contract_ERC20Minter to SmartContract_ERC20Minter.
x/evm/precompile/funtoken_test.go Updated ABI references for FunToken precompile tests to reflect a shift in naming conventions for better clarity.

Poem

🐇 In the meadow where we play,
Changes hop in bright array.
Contracts gleam, a smarter way,
With pointers swift, they dance and sway.
Oh, what joy, this code's ballet! 🌼
Let's celebrate the leap today!


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.

@k-yang k-yang self-assigned this Aug 1, 2024
@k-yang k-yang added the x: evm Relates to Nibiru EVM or the EVM Module label Aug 1, 2024
@k-yang k-yang marked this pull request as ready for review August 1, 2024 22:29
@k-yang k-yang requested a review from a team as a code owner August 1, 2024 22:29
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: 4

Outside diff range, codebase verification and nitpick comments (2)
x/evm/precompile/funtoken_test.go (1)

106-106: Discrepancy Found: ABI Reference

The function FunToken_HappyPath uses embeds.SmartContract_FunToken.ABI instead of embeds.SmartContract_ERC20Minter.ABI as mentioned in the review comment.

  • Line 108: abi := embeds.SmartContract_FunToken.ABI

Please verify if this is the intended ABI reference or if it should be updated to embeds.SmartContract_ERC20Minter.ABI.

Analysis chain

LGTM! But verify the usage of the updated ABI reference.

The code changes are approved.

However, ensure that the updated reference to embeds.SmartContract_ERC20Minter.ABI is correctly used throughout the function.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated ABI reference in `FunToken_HappyPath`.

# Test: Search for the function usage. Expect: Correct usage of the updated ABI reference.
rg --type go -A 5 $'FunToken_HappyPath'

Length of output: 856

x/evm/evmtest/tx.go (1)

142-142: Update function calls to match the new signature

The DeployContract function has been updated to use embeds.CompiledEvmContract instead of embeds.SmartContractFixture. However, several function calls still use the old signature. Please update the following locations to match the new signature:

  • x/evm/evmtest/tx.go: deployResp, err := DeployContract(deps, embeds.SmartContract_TestERC20, t)
  • x/evm/keeper/msg_ethereum_tx_test.go: deployResp, err := evmtest.DeployContract(&deps, embeds.SmartContract_TestERC20, s.T())
  • x/evm/keeper/erc20_test.go: deployResp, err := evmtest.DeployContract(&deps, embeds.SmartContract_ERC20Minter, s.T(), metadata.Name, metadata.Symbol, metadata.Decimals)
  • x/evm/evmmodule/genesis_test.go: deployResp, err := evmtest.DeployContract(&deps, erc20Contract, s.T())
Analysis chain

LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to DeployContract match the new signature.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `DeployContract` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'DeployContract'

Length of output: 3174

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3c73f03 and 12b3e40.

Files ignored due to path filters (1)
  • x/evm/embeds/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (24)
  • CHANGELOG.md (1 hunks)
  • eth/rpc/rpcapi/eth_api_test.go (1 hunks)
  • x/evm/embeds/.gitignore (1 hunks)
  • x/evm/embeds/README.md (1 hunks)
  • x/evm/embeds/artifacts/contracts/ERC20Minter.sol/ERC20Minter.json (5 hunks)
  • x/evm/embeds/artifacts/contracts/TestERC20.sol/TestERC20.json (1 hunks)
  • x/evm/embeds/contracts/ERC20Minter.sol (1 hunks)
  • x/evm/embeds/contracts/TestERC20.sol (1 hunks)
  • x/evm/embeds/embeds.go (1 hunks)
  • x/evm/embeds/embeds_test.go (1 hunks)
  • x/evm/embeds/hardhat.config.js (1 hunks)
  • x/evm/evmmodule/genesis_test.go (2 hunks)
  • x/evm/evmtest/smart_contract.go (1 hunks)
  • x/evm/evmtest/tx.go (2 hunks)
  • x/evm/keeper/erc20.go (5 hunks)
  • x/evm/keeper/erc20_test.go (1 hunks)
  • x/evm/keeper/funtoken_from_coin.go (1 hunks)
  • x/evm/keeper/funtoken_from_erc20.go (1 hunks)
  • x/evm/keeper/grpc_query_test.go (6 hunks)
  • x/evm/keeper/msg_ethereum_tx_test.go (2 hunks)
  • x/evm/keeper/msg_server.go (1 hunks)
  • x/evm/precompile/funtoken.go (1 hunks)
  • x/evm/precompile/funtoken_test.go (4 hunks)
  • x/evm/precompile/precompile.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • x/evm/embeds/.gitignore
  • x/evm/embeds/contracts/ERC20Minter.sol
  • x/evm/keeper/msg_server.go
Additional comments not posted (44)
x/evm/embeds/README.md (1)

1-5: LGTM! The documentation changes improve clarity and focus.

The updated README file now provides a more concise and targeted guide for users working with Nibiru Contract Embeds by eliminating unnecessary information.

x/evm/embeds/hardhat.config.js (1)

5-5: LGTM! Verify compatibility with existing contracts.

The Solidity compiler version has been updated from 0.8.19 to 0.8.24. Ensure that this update does not introduce any breaking changes or compatibility issues with existing contracts.

Verification successful

Compatibility verified with existing contracts.

The Solidity compiler version update to 0.8.24 is compatible with the existing contracts, as all relevant Solidity version pragmas are either explicitly set to ^0.8.24 or are compatible with >=0.8.19.

  • x/evm/embeds/contracts/TestERC20.sol: pragma solidity ^0.8.24;
  • x/evm/embeds/contracts/IFunToken.sol: pragma solidity >=0.8.19;
  • x/evm/embeds/contracts/ERC20Minter.sol: pragma solidity >=0.8.19;
  • e2e/evm/contracts/TestERC20.sol: pragma solidity ^0.8.24;
  • e2e/evm/contracts/SendReceiveNibi.sol: pragma solidity ^0.8.24;
  • e2e/evm/contracts/InfiniteLoopGas.sol: pragma solidity ^0.8.24;
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility of Solidity compiler version update with existing contracts.

# Test: Compile all contracts using the updated compiler version. Expect: Successful compilation without errors.
npx hardhat compile

Length of output: 92


Script:

#!/bin/bash
# Description: Verify compatibility of Solidity compiler version update with existing contracts.

# Search for Solidity version pragmas in all Solidity files.
rg --glob '*.sol' 'pragma solidity' -A 1

Length of output: 657

x/evm/embeds/embeds_test.go (3)

4-4: LGTM! The import of the "embed" package is appropriate.

The inclusion of the _ "embed" package is necessary for embedding files in Go.


7-7: LGTM! The use of require improves test robustness.

Switching from assert to require ensures that the test fails immediately if a panic occurs, enhancing the robustness of the test.


13-17: LGTM! The refactored test structure simplifies contract loading.

The refactored test structure removes the loop and directly calls the MustLoad method for each smart contract, wrapped in a require.NotPanics assertion. This simplifies the test logic and ensures that contract loading is performed in a more controlled manner.

x/evm/embeds/contracts/TestERC20.sol (3)

1-6: LGTM!

The contract metadata and imports are standard and necessary for the contract functionality.


7-10: LGTM!

The contract declaration and state variables are defined correctly.


12-15: LGTM!

The constructor logic is correct and follows best practices for ERC20 token contracts.

x/evm/embeds/embeds.go (5)

Line range hint 1-10:
LGTM!

The package declaration and imports are necessary and relevant to the functionality of the file.


18-23: LGTM!

The embedded JSON variables are correctly defined and necessary for the contract management.


27-45: LGTM!

The smart contract variables are correctly defined and initialized with the embedded JSON data.


48-51: LGTM!

The init function ensures that the embedded JSON data is loaded correctly and panics if any data is missing.


54-86: LGTM!

The CompiledEvmContract structure and MustLoad method are correctly defined and follow best practices for contract management.

x/evm/keeper/funtoken_from_coin.go (1)

73-73: LGTM!

The variable renaming is consistent with the changes in the embeds.go file and does not affect the functionality of the function.

x/evm/evmtest/smart_contract.go (1)

51-51: Verify the safety of removing the Load() method.

Ensure that directly assigning embeds.SmartContract_TestERC20 without invoking the Load() method is safe and does not introduce any potential issues.

x/evm/precompile/precompile.go (2)

82-82: LGTM! Improved memory efficiency.

Returning a pointer to gethabi.ABI improves memory efficiency by avoiding unnecessary copying of the structure.


87-87: LGTM! Consistent use of pointers.

Changing the parameter type to *gethabi.ABI ensures consistency and improves memory efficiency.

x/evm/evmmodule/genesis_test.go (1)

38-38: Verify the safety of removing the MustLoad() method.

Ensure that directly assigning embeds.SmartContract_TestERC20 without invoking the MustLoad() method is safe and does not introduce any potential issues.

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

32-32: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to FindERC20Metadata correctly handle the new pointer type for the abi variable.


Line range hint 66-66:
Verify integration with FindERC20Metadata.

Ensure that the CreateFunTokenFromERC20 function correctly integrates with the changes made to the FindERC20Metadata function, particularly the new pointer type for the abi variable.

x/evm/precompile/funtoken_test.go (3)

74-74: LGTM! But verify the usage of the updated ABI reference.

The code changes are approved.

However, ensure that the updated reference to embeds.SmartContract_FunToken.ABI is correctly used throughout the function.

Verification successful

The updated ABI reference is correctly used in the FunToken_HappyPath function.

  • The abi variable is utilized correctly at line 133 to pack the method name and arguments.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated ABI reference in `FunToken_HappyPath`.

# Test: Search for the function usage. Expect: Correct usage of the updated ABI reference.
rg --type go -A 5 $'FunToken_HappyPath'

Length of output: 856


Script:

#!/bin/bash
# Description: Extract the entire FunToken_HappyPath function to verify the usage of the updated ABI reference.

# Extract the entire FunToken_HappyPath function
ast-grep --lang go --pattern $'func (s *Suite) FunToken_HappyPath() {
  $$$
}'

Length of output: 6076


36-36: LGTM! But verify the usage of the updated ABI reference.

The code changes are approved.

However, ensure that the updated reference to embeds.SmartContract_FunToken.ABI is correctly used throughout the function.

Verification successful

The updated ABI reference is correctly used in the FunToken_PrecompileExists function.

  • The reference to embeds.SmartContract_FunToken.ABI is correctly used to pack method arguments at line 53.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated ABI reference in `FunToken_PrecompileExists`.

# Test: Search for the function usage. Expect: Correct usage of the updated ABI reference.
rg --type go -A 5 $'FunToken_PrecompileExists'

Length of output: 876


Script:

#!/bin/bash
# Description: Extract the full implementation of the `FunToken_PrecompileExists` function to verify the correct usage of the updated ABI reference.

# Search for the full function implementation. 
ast-grep --lang go --pattern $'func (s *Suite) FunToken_PrecompileExists() {
  $$$
}'

Length of output: 2622


96-96: LGTM! But verify the usage of the updated ABI reference.

The code changes are approved.

However, ensure that the updated reference to embeds.SmartContract_ERC20Minter.ABI is correctly used throughout the function.

Verification successful

The updated reference to embeds.SmartContract_ERC20Minter.ABI is correctly used throughout the FunToken_HappyPath function.

  • The ABI reference is used in the context of minting tokens.
  • Appropriate error handling and balance assertions are included.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the updated ABI reference in `FunToken_HappyPath`.

# Test: Search for the function usage. Expect: Correct usage of the updated ABI reference.
rg --type go -A 5 $'FunToken_HappyPath'

Length of output: 856


Script:

#!/bin/bash
# Description: Search for the usage of `embeds.SmartContract_ERC20Minter.ABI` in `x/evm/precompile/funtoken_test.go`.

# Test: Search for the term `embeds.SmartContract_ERC20Minter.ABI` in the specified file.
rg --type go 'embeds.SmartContract_ERC20Minter.ABI' x/evm/precompile/funtoken_test.go

Length of output: 265


Script:

#!/bin/bash
# Description: Search for the usage of `embeds.SmartContract_ERC20Minter.ABI` in `x/evm/precompile/funtoken_test.go` with additional context lines.

# Test: Search for the term `embeds.SmartContract_ERC20Minter.ABI` in the specified file with 10 context lines.
rg --type go -A 10 'embeds.SmartContract_ERC20Minter.ABI' x/evm/precompile/funtoken_test.go

Length of output: 826

x/evm/keeper/msg_ethereum_tx_test.go (1)

45-45: LGTM! But verify the appropriateness of the increased gas limit.

The code changes are approved.

However, ensure that the increased gas limit to 1,500,000 is appropriate for the function's requirements.

Verification successful

The increased gas limit to 1,500,000 in TestMsgEthereumTx_CreateContract is appropriate.

The test case demonstrates that the increased gas limit ensures successful contract deployment and validates the transaction correctly.

  • Location: x/evm/keeper/msg_ethereum_tx_test.go at line 45
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the appropriateness of the increased gas limit in `TestMsgEthereumTx_CreateContract`.

# Test: Search for the function usage. Expect: Correct usage of the increased gas limit.
rg --type go -A 5 $'TestMsgEthereumTx_CreateContract'

Length of output: 396


Script:

#!/bin/bash
# Description: Extract the full implementation of the TestMsgEthereumTx_CreateContract function to verify the appropriateness of the increased gas limit.

# Extract the full implementation of the function
ast-grep --lang go --pattern $'func (s *Suite) TestMsgEthereumTx_CreateContract() {
  $$$
}' 

Length of output: 6255

x/evm/evmtest/tx.go (2)

147-152: Efficient access to contract data.

The direct access to ABI and Bytecode properties of the contract parameter improves efficiency by eliminating the need for intermediate data loading.


172-172: Consistent return type.

Returning the contract directly as ContractData maintains consistency with the updated parameter type.

x/evm/precompile/funtoken.go (1)

87-88: LGTM! But verify the ABI usage in the codebase.

The code changes are approved.

However, ensure that all references to the ABI method handle the new pointer type correctly.

Verification successful

All references to the ABI method handle the new pointer type correctly.

The changes to the ABI method return type and its usage across the codebase have been verified. All references correctly handle the new pointer type (*gethabi.ABI), ensuring proper dereferencing and method calls.

  • eth/rpc/rpcapi/eth_api_test.go
  • x/evm/evmtest/tx.go
  • x/evm/precompile/precompile.go
  • x/evm/keeper/erc20.go
  • x/evm/keeper/funtoken_from_erc20.go
  • x/evm/keeper/funtoken_from_coin.go
  • x/evm/evmmodule/genesis_test.go
  • x/evm/keeper/msg_ethereum_tx_test.go

No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the `ABI` method handle the new pointer type correctly.

# Test: Search for the method usage. Expect: Only occurrences of the new pointer type.
rg --type go -A 5 $'ABI()'

Length of output: 17285


Script:

#!/bin/bash
# Extract and review the relevant lines of code around the `ABI` method calls in the identified files.

# Files and lines where `ABI` method is referenced.
declare -A files_and_lines=(
    ["eth/rpc/rpcapi/eth_api_test.go"]="input, err := s.contractData.ABI.Pack"
    ["x/evm/evmtest/tx.go"]="packedArgs, err := contract.ABI.Pack"
    ["x/evm/precompile/precompile.go"]="abi := p.ABI()"
    ["x/evm/keeper/erc20.go"]="ABI *gethabi.ABI"
    ["x/evm/keeper/funtoken_from_erc20.go"]="var abi *gethabi.ABI = embeds.SmartContract_ERC20Minter.ABI"
    ["x/evm/keeper/funtoken_from_coin.go"]="packedArgs, err := erc20Embed.ABI.Pack"
    ["x/evm/evmmodule/genesis_test.go"]="deps.Ctx, erc20Contract.ABI"
    ["x/evm/keeper/msg_ethereum_tx_test.go"]="input, err := testContract.ABI.Pack"
)

# Loop through the files and lines to extract the relevant context.
for file in "${!files_and_lines[@]}"; do
    pattern="${files_and_lines[$file]}"
    echo "File: $file"
    rg --type go -A 5 "$pattern" "$file"
    echo
done

Length of output: 4085

x/evm/keeper/erc20.go (6)

294-294: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to LoadERC20String handle the new pointer type correctly.

Verification successful

Verified: Function usage of LoadERC20String handles the new pointer type correctly.

The code changes are approved, and all function calls to LoadERC20String correctly handle the new pointer type *gethabi.ABI.

  • LoadERC20Name
  • LoadERC20Symbol
  • LoadERC20Decimals
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `LoadERC20String` handle the new pointer type correctly.

# Test: Search for the function usage. Expect: Only occurrences of the new pointer type.
rg --type go -A 5 $'LoadERC20String'

Length of output: 949


27-33: LGTM! But verify the struct usage in the codebase.

The code changes are approved.

However, ensure that all references to the erc20Calls struct handle the new pointer type correctly.


131-131: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to CallContract handle the new pointer type correctly.


275-275: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to LoadERC20Name handle the new pointer type correctly.

Verification successful

LGTM! The function usage of LoadERC20Name correctly handles the new pointer type.

The abi parameter in x/evm/keeper/funtoken_from_erc20.go is defined as *gethabi.ABI, which is consistent with the updated function signature.

  • x/evm/keeper/funtoken_from_erc20.go: var abi *gethabi.ABI = embeds.SmartContract_ERC20Minter.ABI
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `LoadERC20Name` handle the new pointer type correctly.

# Test: Search for the function usage. Expect: Only occurrences of the new pointer type.
rg --type go -A 5 $'LoadERC20Name'

Length of output: 799


Script:

#!/bin/bash
# Description: Verify the type of `abi` passed to `LoadERC20Name` in `x/evm/keeper/funtoken_from_erc20.go`.

# Search for the definition and type of `abi` in the file.
rg --type go -A 10 'abi' x/evm/keeper/funtoken_from_erc20.go

Length of output: 942


287-287: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to LoadERC20Decimals handle the new pointer type correctly.

Verification successful

Let's verify the type of the abi variable in x/evm/keeper/funtoken_from_erc20.go to ensure it is a pointer of type *gethabi.ABI.


Verified: The function usage is correct.

The abi variable in x/evm/keeper/funtoken_from_erc20.go is correctly declared as a pointer of type *gethabi.ABI, ensuring compatibility with the updated function signature of LoadERC20Decimals.

  • The abi variable is declared as *gethabi.ABI.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `LoadERC20Decimals` handle the new pointer type correctly.

# Test: Search for the function usage. Expect: Only occurrences of the new pointer type.
rg --type go -A 5 $'LoadERC20Decimals'

Length of output: 771


Script:

#!/bin/bash
# Description: Verify the type of the `abi` variable in `x/evm/keeper/funtoken_from_erc20.go`.

# Test: Search for the declaration of `abi` in `x/evm/keeper/funtoken_from_erc20.go`.
rg --type go -A 5 'abi' x/evm/keeper/funtoken_from_erc20.go

Length of output: 762


281-281: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to LoadERC20Symbol handle the new pointer type correctly.

Verification successful

LGTM! But verify the function usage in the codebase.

The code changes are approved.

All function calls to LoadERC20Symbol correctly handle the new pointer type.

  • x/evm/keeper/funtoken_from_erc20.go: The abi variable is correctly declared as *gethabi.ABI.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `LoadERC20Symbol` handle the new pointer type correctly.

# Test: Search for the function usage. Expect: Only occurrences of the new pointer type.
rg --type go -A 5 $'LoadERC20Symbol'

Length of output: 767


Script:

#!/bin/bash
# Description: Verify the type of the `abi` parameter passed to `LoadERC20Symbol` in `x/evm/keeper/funtoken_from_erc20.go`.

# Test: Search for the declaration and type of the `abi` variable in `x/evm/keeper/funtoken_from_erc20.go`.
rg --type go -A 5 'abi' x/evm/keeper/funtoken_from_erc20.go

Length of output: 762

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

407-407: Verify the impact of ABI reference change.

The ABI reference for the ERC20 contract was updated from Contract_ERC20Minter.ABI to SmartContract_ERC20Minter.ABI. Ensure that all interactions with the contract are correctly handled with the new ABI reference.


399-399: Verify the impact of ABI reference change.

The ABI reference for the ERC20 contract was updated from Contract_ERC20Minter.ABI to SmartContract_ERC20Minter.ABI. Ensure that all interactions with the contract are correctly handled with the new ABI reference.

Verification successful

The ABI reference change has been correctly propagated.

The ABI reference for the ERC20 contract has been updated from Contract_ERC20Minter.ABI to SmartContract_ERC20Minter.ABI consistently across the codebase. No old references were found.

  • x/evm/keeper/funtoken_from_erc20.go
  • x/evm/keeper/erc20.go
  • x/evm/keeper/msg_server.go
  • x/evm/keeper/erc20_test.go
  • x/evm/precompile/funtoken_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of the old ABI reference and ensure they are updated to the new reference.

# Test: Search for the old ABI reference. Expect: No occurrences of the old reference.
rg --type go 'Contract_ERC20Minter\.ABI'

Length of output: 680

x/evm/keeper/grpc_query_test.go (1)

894-907: Re-enable response validation logic.

Commenting out the response validation logic reduces the effectiveness of the test in ensuring that the output matches expectations. Investigate the inconsistencies and re-enable the validation logic.

x/evm/embeds/artifacts/contracts/TestERC20.sol/TestERC20.json (4)

1-4: Metadata section looks good!

The metadata section follows the standard format and is correct.


281-283: Bytecode section looks good!

The bytecode section matches the expected format for a compiled contract.


284-286: Link references section looks good!

The link references section is empty, indicating no external libraries are linked, and follows the standard format.


5-280: ABI section looks good, but verify correctness.

The ABI section is well-structured and includes necessary events and functions for an ERC20 token. Ensure that all functions and events are correctly defined and align with the contract's implementation.

x/evm/embeds/artifacts/contracts/ERC20Minter.sol/ERC20Minter.json (4)

Line range hint 1-4:
Metadata section looks good!

The metadata section follows the standard format and is correct.


418-418: Bytecode section looks good!

The bytecode section matches the expected format for a compiled contract.


419-421: Link references section looks good!

The link references section is empty, indicating no external libraries are linked, and follows the standard format.


Line range hint 5-417:
ABI section looks good, but verify correctness and integration.

The ABI section is well-structured but the renaming of function parameters and altering function names could lead to integration issues. Ensure that all functions and events are correctly defined and the changes do not break existing integrations.


s.contractData, err = embeds.SmartContract_TestERC20.Load()
s.Require().NoError(err)
s.contractData = embeds.SmartContract_TestERC20
Copy link
Contributor

Choose a reason for hiding this comment

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

Reintroduce error handling for contract data initialization.

Removing the error handling for contractData initialization can lead to potential issues if the contract data fails to load correctly. Ensure that the contract data is valid before it is used in subsequent tests.

-  s.contractData = embeds.SmartContract_TestERC20
+  var err error
+  s.contractData, err = embeds.SmartContract_TestERC20.Load()
+  s.Require().NoError(err)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
s.contractData = embeds.SmartContract_TestERC20
var err error
s.contractData, err = embeds.SmartContract_TestERC20.Load()
s.Require().NoError(err)

@@ -497,8 +495,7 @@ func (s *Suite) TestQueryEthCall() {
{
name: "happy: eth call for erc20 token transfer",
scenario: func(deps *evmtest.TestDeps) (req In, wantResp Out) {
fungibleTokenContract, err := embeds.SmartContract_TestERC20.Load()
s.Require().NoError(err)
fungibleTokenContract := embeds.SmartContract_ERC20Minter
Copy link
Contributor

Choose a reason for hiding this comment

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

Reintroduce error handling for contract initialization.

Removing the error handling for fungibleTokenContract initialization can lead to potential issues if the contract data fails to load correctly. Ensure that the contract data is valid before it is used in the test.

-  fungibleTokenContract := embeds.SmartContract_ERC20Minter
+  fungibleTokenContract, err := embeds.SmartContract_ERC20Minter.Load()
+  s.Require().NoError(err)

Committable suggestion was skipped due to low confidence.

Comment on lines +814 to +828
// // Replace spaces in want resp
// re := regexp.MustCompile(`[\s\n\r]+`)
// wantResp = re.ReplaceAllString(wantResp, "")
// actualResp := string(gotResp.Data)
// if len(actualResp) > 1000 {
// actualResp = actualResp[:len(wantResp)]
// }
// // FIXME: Why does this trace sometimes have gas 35050 and sometimes 35062?
// // s.Equal(wantResp, actualResp)
// replaceTimes := 1
// hackedWantResp := strings.Replace(wantResp, "35062", "35050", replaceTimes)
// s.True(
// wantResp == actualResp || hackedWantResp == actualResp,
// "got \"%s\", want \"%s\"", actualResp, wantResp,
// )
Copy link
Contributor

Choose a reason for hiding this comment

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

Re-enable response validation logic.

Commenting out the response validation logic reduces the effectiveness of the test in ensuring that the output matches expectations. Investigate the inconsistencies and re-enable the validation logic.

-  // Replace spaces in want resp
-  // re := regexp.MustCompile(`[\s\n\r]+`)
-  // wantResp = re.ReplaceAllString(wantResp, "")
-  // actualResp := string(gotResp.Data)
-  // if len(actualResp) > 1000 {
-  //  actualResp = actualResp[:len(wantResp)]
-  // }
-  // FIXME: Why does this trace sometimes have gas 35050 and sometimes 35062?
-  // s.Equal(wantResp, actualResp)
-  // replaceTimes := 1
-  // hackedWantResp := strings.Replace(wantResp, "35062", "35050", replaceTimes)
-  // s.True(
-  //  wantResp == actualResp || hackedWantResp == actualResp,
-  //  "got \"%s\", want \"%s\"", actualResp, wantResp,
-  // )
+  // Replace spaces in want resp
+  re := regexp.MustCompile(`[\s\n\r]+`)
+  wantResp = re.ReplaceAllString(wantResp, "")
+  actualResp := string(gotResp.Data)
+  if len(actualResp) > 1000 {
+    actualResp = actualResp[:len(wantResp)]
+  }
+  // FIXME: Why does this trace sometimes have gas 35050 and sometimes 35062?
+  s.Equal(wantResp, actualResp)
+  replaceTimes := 1
+  hackedWantResp := strings.Replace(wantResp, "35062", "35050", replaceTimes)
+  s.True(
+    wantResp == actualResp || hackedWantResp == actualResp,
+    "got \"%s\", want \"%s\"", actualResp, wantResp,
+  )
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// // Replace spaces in want resp
// re := regexp.MustCompile(`[\s\n\r]+`)
// wantResp = re.ReplaceAllString(wantResp, "")
// actualResp := string(gotResp.Data)
// if len(actualResp) > 1000 {
// actualResp = actualResp[:len(wantResp)]
// }
// // FIXME: Why does this trace sometimes have gas 35050 and sometimes 35062?
// // s.Equal(wantResp, actualResp)
// replaceTimes := 1
// hackedWantResp := strings.Replace(wantResp, "35062", "35050", replaceTimes)
// s.True(
// wantResp == actualResp || hackedWantResp == actualResp,
// "got \"%s\", want \"%s\"", actualResp, wantResp,
// )
// Replace spaces in want resp
re := regexp.MustCompile(`[\s\n\r]+`)
wantResp = re.ReplaceAllString(wantResp, "")
actualResp := string(gotResp.Data)
if len(actualResp) > 1000 {
actualResp = actualResp[:len(wantResp)]
}
// FIXME: Why does this trace sometimes have gas 35050 and sometimes 35062?
s.Equal(wantResp, actualResp)
replaceTimes := 1
hackedWantResp := strings.Replace(wantResp, "35062", "35050", replaceTimes)
s.True(
wantResp == actualResp || hackedWantResp == actualResp,
"got \"%s\", want \"%s\"", actualResp, wantResp,
)

@@ -129,8 +129,7 @@ func (s *Suite) TestMsgEthereumTx_ExecuteContract() {
)
s.Require().NoError(err)
contractAddr := deployResp.ContractAddr
testContract, err := embeds.SmartContract_TestERC20.Load()
s.Require().NoError(err)
testContract := embeds.SmartContract_TestERC20
Copy link
Contributor

Choose a reason for hiding this comment

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

Re-add the error check when loading the smart contract.

The removal of the error check when loading the smart contract may affect the reliability of the function. Consider re-adding the error check to ensure the contract is properly initialized.

- testContract := embeds.SmartContract_TestERC20
+ testContract, err := embeds.SmartContract_TestERC20
+ s.Require().NoError(err)

Committable suggestion was skipped due to low confidence.

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 65.68%. Comparing base (946bfbf) to head (12b3e40).
Report is 2 commits behind head on main.

Files Patch % Lines
x/evm/embeds/embeds.go 76.47% 3 Missing and 1 partial ⚠️
x/evm/evmtest/tx.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1984   +/-   ##
=======================================
  Coverage   65.68%   65.68%           
=======================================
  Files         262      262           
  Lines       16511    16457   -54     
=======================================
- Hits        10845    10810   -35     
+ Misses       4852     4839   -13     
+ Partials      814      808    -6     
Files Coverage Δ
x/evm/evmtest/smart_contract.go 87.23% <100.00%> (+3.56%) ⬆️
x/evm/keeper/erc20.go 82.05% <100.00%> (ø)
x/evm/keeper/funtoken_from_coin.go 75.51% <100.00%> (ø)
x/evm/keeper/funtoken_from_erc20.go 86.88% <100.00%> (ø)
x/evm/keeper/msg_server.go 72.38% <100.00%> (ø)
x/evm/precompile/funtoken.go 54.83% <100.00%> (ø)
x/evm/precompile/precompile.go 76.00% <100.00%> (ø)
x/evm/evmtest/tx.go 0.00% <0.00%> (ø)
x/evm/embeds/embeds.go 61.90% <76.47%> (-5.71%) ⬇️

@Unique-Divine Unique-Divine enabled auto-merge (squash) August 6, 2024 21:13
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12b3e40 and 944715c.

Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • eth/rpc/rpcapi/eth_api_test.go (1 hunks)
  • x/evm/evmmodule/genesis_test.go (2 hunks)
  • x/evm/evmtest/tx.go (2 hunks)
  • x/evm/keeper/erc20_test.go (1 hunks)
  • x/evm/keeper/grpc_query_test.go (6 hunks)
  • x/evm/keeper/msg_ethereum_tx_test.go (2 hunks)
  • x/evm/keeper/msg_server.go (1 hunks)
  • x/evm/precompile/funtoken_test.go (4 hunks)
Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • x/evm/evmmodule/genesis_test.go
  • x/evm/keeper/msg_server.go
  • x/evm/precompile/funtoken_test.go
Files skipped from review as they are similar to previous changes (5)
  • eth/rpc/rpcapi/eth_api_test.go
  • x/evm/evmtest/tx.go
  • x/evm/keeper/erc20_test.go
  • x/evm/keeper/grpc_query_test.go
  • x/evm/keeper/msg_ethereum_tx_test.go

@Unique-Divine Unique-Divine enabled auto-merge (squash) August 6, 2024 23:35
@Unique-Divine Unique-Divine merged commit d71d67d into main Aug 6, 2024
13 checks passed
@Unique-Divine Unique-Divine deleted the refactor/evm/embeds branch August 6, 2024 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x: evm Relates to Nibiru EVM or the EVM Module
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

3 participants