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): funtoken events, cli commands and queries #1968

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

onikonychev
Copy link
Contributor

@onikonychev onikonychev commented Jul 16, 2024

  1. Emitting event EventFunTokenCreated on any funtoken creation
  2. Renamed query TokenMapping -> FunToken
  3. Added cli query for FunToken

Summary by CodeRabbit

  • New Features

    • Introduced new CLI commands for querying and creating fun tokens in the EVM module.
    • Added functionality to create fun tokens from ERC20 contracts.
  • Refactor

    • Renamed token mapping-related functions and messages to fun token terminology.
    • Enhanced event handling for fun token creation with additional details.
  • Tests

    • Updated test cases to reflect changes in fun token terminology and added more specific assertions.

Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Walkthrough

The changes encompass a thorough refactoring of the EVM module, emphasizing the management of fungible token events, CLI commands, and queries. Key updates include renaming functions and messages for clarity, enhancing CLI command structures for better usability, and aligning tests with the new configurations. This refactoring seeks to enhance the overall interaction with fungible tokens within the system, making operations more intuitive and efficient.

Changes

Files Change Summary
CHANGELOG.md Added summary of changes regarding funtoken events, CLI commands, and queries in the EVM module.
eth/rpc/backend/mocks/evm_query_client.go Renamed TokenMapping to FunTokenMapping, updated request and response types accordingly.
proto/eth/evm/v1/events.proto Renamed EventFunTokenFromBankCoin to EventFunTokenCreated, added is_made_from_coin field.
proto/eth/evm/v1/query.proto Renamed RPC methods and message types to reflect fun token terminology.
x/evm/cli/query.go Introduced new CLI commands for querying fun token functionalities in the evm module.
x/evm/cli/tx.go Updated existing CLI commands and added new ones for creating and sending fungible tokens.
x/evm/keeper/erc20_test.go Updated tests to use Require assertions, added checks for specific events and attributes.
x/evm/keeper/grpc_query.go Renamed TokenMapping function to FunTokenMapping, updated input and return types.
x/evm/keeper/grpc_query_test.go Renamed TestQueryTokenMapping to TestQueryFunToken, updated types throughout the function.
x/evm/keeper/msg_server.go Updated event emission in CreateFunToken to emit EventFunTokenCreated with additional details.

Poem

In the code where tokens prance,
Refactor sings a joyful dance.
Funtoken events, freshly spun,
Queries sparkle, all in fun.
CLI commands, a breeze to wield,
A rabbit's cheer, a tech-filled field.
🌟✨🐇


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.

@onikonychev onikonychev marked this pull request as ready for review July 16, 2024 16:55
@onikonychev onikonychev requested a review from a team as a code owner July 16, 2024 16:55
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.95%. Comparing base (f898bae) to head (777ab3a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1968   +/-   ##
=======================================
  Coverage   65.95%   65.95%           
=======================================
  Files         258      258           
  Lines       16384    16384           
=======================================
  Hits        10806    10806           
  Misses       4772     4772           
  Partials      806      806           
Files Coverage Δ
x/evm/keeper/grpc_query.go 83.76% <100.00%> (ø)
x/evm/keeper/msg_server.go 71.57% <100.00%> (ø)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
x/evm/keeper/grpc_query.go (1)

Line range hint 744-763: Review of the FunToken function

The FunToken function has been successfully updated to handle the new QueryFunTokenRequest and return a QueryFunTokenResponse. The logic within the function appears to handle two types of token lookups: by cosmos denom and by ERC20 address, which is a good practice for flexibility.

Suggestions:

  1. Error Handling: Ensure that the error message returned when no token mapping is found is clear and helpful for debugging.
  2. Performance: Consider the implications of the ExactMatch and Collect calls on performance, especially in scenarios with large datasets.
  3. Testing: It's crucial to add unit tests for this function to cover both paths (lookup by denom and ERC20 address) and the error scenario.

Would you like assistance in writing comprehensive unit tests for this function?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a666e08 and b6aa6cd.

Files ignored due to path filters (3)
  • x/evm/events.pb.go is excluded by !**/*.pb.go
  • x/evm/query.pb.go is excluded by !**/*.pb.go
  • x/evm/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (10)
  • CHANGELOG.md (1 hunks)
  • eth/rpc/backend/mocks/evm_query_client.go (2 hunks)
  • proto/eth/evm/v1/events.proto (1 hunks)
  • proto/eth/evm/v1/query.proto (2 hunks)
  • x/evm/cli/query.go (1 hunks)
  • x/evm/cli/tx.go (4 hunks)
  • x/evm/keeper/erc20_test.go (11 hunks)
  • x/evm/keeper/grpc_query.go (2 hunks)
  • x/evm/keeper/grpc_query_test.go (4 hunks)
  • x/evm/keeper/msg_server.go (2 hunks)
Additional context used
Learnings (1)
x/evm/cli/query.go (1)
Learnt from: Unique-Divine
PR: NibiruChain/nibiru#1869
File: x/evm/cli/cli.go:44-47
Timestamp: 2024-05-10T14:23:51.765Z
Learning: The loop in `GetQueryCmd` function of `x/evm/cli/cli.go` is a placeholder for future subcommands.
Gitleaks
x/evm/keeper/grpc_query_test.go

969-969: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (13)
proto/eth/evm/v1/events.proto (1)

50-55: Renaming and Field Addition in Protobuf Message

The renaming of EventFunTokenFromBankCoin to EventFunTokenCreated and the addition of the field is_made_from_coin are consistent with the PR objectives to enhance event clarity. The field addition is properly defined with a standard scalar type (bool), which is appropriate for the intended usage.

x/evm/cli/query.go (2)

15-34: New CLI Command Structure

The GetQueryCmd function properly sets up a new CLI command for querying the module. The use of cobra.Command is standard and the function is well-structured with clear separation of concerns. The inclusion of the new GetCmdFunToken command is correctly implemented.


36-71: Implementation of GetCmdFunToken Command

The GetCmdFunToken command is well-implemented with appropriate command usage, description, and argument handling. The function's error handling is robust, ensuring that any issues with the client context or query execution are properly returned. The use of clientCtx.PrintProto to print the response is a good practice, ensuring that the output is formatted according to the protobuf definition.

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

Line range hint 29-67: Updated and New Commands for Token Creation

The modifications to CmdCreateFunTokenFromBankCoin and the addition of CmdCreateFunTokenFromERC20 are correctly implemented. The changes in command usage and description are consistent with the PR objectives. The error handling and transaction broadcasting logic are robust and follow best practices.


105-106: Modification to SendFunTokenToEvm Command

The changes to the SendFunTokenToEvm command, including the updated command usage and description, are appropriate and align with the PR objectives. The implementation ensures that the command correctly handles the transaction process, including error handling and broadcasting.

proto/eth/evm/v1/query.proto (2)

79-80: Renaming of RPC Method

The renaming of the RPC method from TokenMapping to FunToken is correctly implemented, with the appropriate HTTP GET path updated. This change enhances clarity and aligns with the renaming strategy described in the PR.


309-323: Renaming of Request and Response Messages

The renaming of QueryTokenMappingRequest and QueryTokenMappingResponse to QueryFunTokenRequest and QueryFunTokenResponse, respectively, is correctly implemented. The field definitions and options within these messages are appropriate and consistent with the intended functionality.

eth/rpc/backend/mocks/evm_query_client.go (1)

Line range hint 380-401: Renamed function signature and parameters are correctly implemented.

The function TokenMapping has been correctly renamed to FunToken, and the input and output types have been updated from QueryTokenMappingRequest to QueryFunTokenRequest and from QueryTokenMappingResponse to QueryFunTokenResponse respectively. This change is consistent with the PR's objectives to refactor token-related functionalities.

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

14-14: Added import for enhanced testing utilities.

The import github.com/NibiruChain/nibiru/x/common/testutil has been added to utilize additional testing utilities. This is a positive change as it likely provides more robust testing functions which are utilized in the test cases.


44-44: Enhanced assertions and event checks in test cases.

The replacement of s.NoError with s.Require().NoError in various test cases is a good practice as it ensures that the tests will halt immediately if an error is encountered, which is crucial for critical operations. Additionally, the checks for specific event attributes ensure that the system's event emissions are as expected, enhancing test reliability.

Also applies to: 63-63, 78-78, 97-97, 110-110, 124-124, 182-182, 244-244, 260-260, 274-274

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

510-515: Correct implementation of new event emission in CreateFunToken.

The new event EventFunTokenCreated is correctly implemented with additional details such as Creator, BankDenom, Erc20ContractAddress, and IsMadeFromCoin. This change enhances the detail available in event logs, aiding in better monitoring and debugging processes.

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

Line range hint 915-992: Renamed Test Function and Associated Types

The test function TestQueryTokenMapping has been renamed to TestQueryFunToken, and the associated request and response types have been updated accordingly. This change aligns with the PR's objective to focus on FunToken.

  • The renaming of the function and types is consistent and correctly implemented across the test cases.
  • The method call deps.K.TokenMapping has been updated to deps.K.FunToken which is correct and consistent with the renaming.
CHANGELOG.md (1)

88-88: Review of Changelog Entry

The entry under "State Machine Breaking" for the Nibiru EVM section is well-placed and follows the established format of the changelog. It's important to ensure that the linked PR provides a detailed description of the changes and their impact, as this entry will be crucial for users understanding the changes in the system.

proto/eth/evm/v1/query.proto Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b6aa6cd and 777ab3a.

Files ignored due to path filters (2)
  • x/evm/query.pb.go is excluded by !**/*.pb.go
  • x/evm/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (5)
  • eth/rpc/backend/mocks/evm_query_client.go (2 hunks)
  • proto/eth/evm/v1/query.proto (2 hunks)
  • x/evm/cli/query.go (1 hunks)
  • x/evm/keeper/grpc_query.go (2 hunks)
  • x/evm/keeper/grpc_query_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (3)
  • eth/rpc/backend/mocks/evm_query_client.go
  • x/evm/cli/query.go
  • x/evm/keeper/grpc_query.go
Additional context used
Gitleaks
x/evm/keeper/grpc_query_test.go

969-969: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (6)
proto/eth/evm/v1/query.proto (3)

317-323: Ensure consistency of renamed message type.

The message type QueryTokenMappingResponse has been renamed to QueryFunTokenMappingResponse. Verify that this new message type name is consistently used throughout the codebase.

Verification successful

The message type QueryFunTokenMappingResponse is used consistently throughout the codebase.

The search results confirm that the new message type name has been applied correctly, with no remaining instances of the old name QueryTokenMappingResponse.

  • Verified in files such as x/evm/query.pb.go, proto/eth/evm/v1/query.proto, eth/rpc/backend/mocks/evm_query_client.go, x/evm/keeper/grpc_query_test.go, and x/evm/keeper/grpc_query.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new message type name `QueryFunTokenMappingResponse` is used consistently.

# Test: Search for the old and new message type names. Expect: Only occurrences of the new message type name.
rg --type proto $'QueryTokenMappingResponse'
rg --type proto $'QueryFunTokenMappingResponse'

Length of output: 150


Script:

#!/bin/bash
# Description: Verify that the new message type name `QueryFunTokenMappingResponse` is used consistently.

# Test: Search for the old and new message type names. Expect: Only occurrences of the new message type name.
rg 'QueryTokenMappingResponse'
rg 'QueryFunTokenMappingResponse'

Length of output: 4106


79-80: Ensure consistency of renamed RPC method.

The RPC method TokenMapping has been renamed to FunTokenMapping. Verify that this new method name is consistently used throughout the codebase.

Verification successful

Ensure consistency of renamed RPC method.

The RPC method TokenMapping has been renamed to FunTokenMapping. Verify that this new method name is consistently used throughout the codebase.


Renamed RPC method verified successfully.

The RPC method TokenMapping has been renamed to FunTokenMapping and the new method name is consistently used throughout the codebase.

  • Verified in multiple files including query.pb.gw.go, query.pb.go, grpc_query.go, grpc_query_test.go, query.proto, and evm_query_client.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new RPC method name `FunTokenMapping` is used consistently.

# Test: Search for the old and new method names. Expect: Only occurrences of the new method name.
rg --type proto $'TokenMapping'
rg --type proto $'FunTokenMapping'

Length of output: 124


Script:

#!/bin/bash
# Description: Verify that the new RPC method name `FunTokenMapping` is used consistently.

# Test: Search for the old and new method names. Expect: Only occurrences of the new method name.
rg 'TokenMapping'
rg 'FunTokenMapping'

Length of output: 20107


309-312: Ensure consistency of renamed message type.

The message type QueryTokenMappingRequest has been renamed to QueryFunTokenMappingRequest. Verify that this new message type name is consistently used throughout the codebase.

Verification successful

The new message type name QueryFunTokenMappingRequest is used consistently.

The old message type name QueryTokenMappingRequest was not found, and the new message type name QueryFunTokenMappingRequest is used in relevant places in the codebase.

  • rpc FunTokenMapping(QueryFunTokenMappingRequest) returns (QueryFunTokenMappingResponse) {
  • message QueryFunTokenMappingRequest {
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new message type name `QueryFunTokenMappingRequest` is used consistently.

# Test: Search for the old and new message type names. Expect: Only occurrences of the new message type name.
rg --type proto $'QueryTokenMappingRequest'
rg --type proto $'QueryFunTokenMappingRequest'

Length of output: 148


Script:

#!/bin/bash
# Description: Verify that the new message type name `QueryFunTokenMappingRequest` is used consistently.

# Find all .proto files and search for the old message type name
fd -e proto -x rg 'QueryTokenMappingRequest' {}

# Find all .proto files and search for the new message type name
fd -e proto -x rg 'QueryFunTokenMappingRequest' {}

Length of output: 232

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

915-915: Ensure consistency of renamed test function.

The test function TestQueryTokenMapping has been renamed to TestQueryFunToken. Verify that this new test function name is consistently used throughout the codebase.

Verification successful

Ensure consistency of renamed test function.

The test function TestQueryTokenMapping has been renamed to TestQueryFunToken. The search results confirm that the new test function name is used consistently throughout the codebase, and no references to the old name were found.

  • The new test function name TestQueryFunToken is present in x/evm/keeper/grpc_query_test.go.
  • No occurrences of the old test function name TestQueryTokenMapping were found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new test function name `TestQueryFunToken` is used consistently.

# Test: Search for the old and new test function names. Expect: Only occurrences of the new test function name.
rg --type go $'TestQueryTokenMapping'
rg --type go $'TestQueryFunToken'

Length of output: 139


Line range hint 917-971:
Ensure consistency of renamed response type.

The response type QueryTokenMappingResponse has been renamed to QueryFunTokenMappingResponse. Verify that this new response type name is consistently used throughout the codebase.

Verification successful

The response type QueryTokenMappingResponse has been consistently renamed to QueryFunTokenMappingResponse.

The new response type name is used consistently throughout the codebase, and there are no occurrences of the old response type name.

  • Verified in files:
    • x/evm/query.pb.go
    • x/evm/keeper/grpc_query_test.go
    • x/evm/keeper/grpc_query.go
    • eth/rpc/backend/mocks/evm_query_client.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new response type name `QueryFunTokenMappingResponse` is used consistently.

# Test: Search for the old and new response type names. Expect: Only occurrences of the new response type name.
rg --type go $'QueryTokenMappingResponse'
rg --type go $'QueryFunTokenMappingResponse'

Length of output: 3937


916-922: Ensure consistency of renamed request type.

The request type QueryTokenMappingRequest has been renamed to QueryFunTokenMappingRequest. Verify that this new request type name is consistently used throughout the codebase.

Verification successful

The new request type name QueryFunTokenMappingRequest is used consistently throughout the codebase.

The old request type name QueryTokenMappingRequest does not appear in the search results, indicating a complete and consistent renaming.

  • Files verified:
    • x/evm/keeper/grpc_query.go
    • x/evm/query.pb.go
    • x/evm/query.pb.gw.go
    • x/evm/keeper/grpc_query_test.go
    • eth/rpc/backend/mocks/evm_query_client.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new request type name `QueryFunTokenMappingRequest` is used consistently.

# Test: Search for the old and new request type names. Expect: Only occurrences of the new request type name.
rg --type go $'QueryTokenMappingRequest'
rg --type go $'QueryFunTokenMappingRequest'

Length of output: 4077

@@ -965,10 +965,10 @@ func (s *Suite) TestQueryTokenMapping() {
)
},
scenario: func(deps *evmtest.TestDeps) (req In, wantResp Out) {
req = &evm.QueryTokenMappingRequest{
req = &evm.QueryFunTokenMappingRequest{
Token: "0xAEf9437FF23D48D73271a41a8A094DEc9ac71477",
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential Security Issue: Detected Generic API Key

Static analysis has flagged a potential exposure of a generic API key. This could potentially lead to unauthorized access if the key is sensitive.

- "0xAEf9437FF23D48D73271a41a8A094DEc9ac71477"
+ "<REDACTED>"
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
Token: "0xAEf9437FF23D48D73271a41a8A094DEc9ac71477",
Token: "<REDACTED>",
Tools
Gitleaks

969-969: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

@k-yang k-yang merged commit afc7c0f into main Jul 23, 2024
16 of 17 checks passed
@k-yang k-yang deleted the on/refactor-evm-events branch July 23, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants