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

feat(fungible): add Gateway address in protocol contract list #2578

Merged
merged 9 commits into from
Jul 30, 2024

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Jul 29, 2024

Description

Closes: #2577

Add the gateway contract address in the SystemContract structure and add a message to update it.
Give admin permission for the message (shall be called almost never)

Unit tested the message
For the E2E tests, we'll have to make more progress in the new architecture environmment before testing all components

Summary by CodeRabbit

  • New Features

    • Introduced a command for updating the gateway contract address via the zetacored CLI.
    • Added a new message type MsgUpdateGatewayContract to facilitate gateway contract updates.
    • Enhanced OpenAPI specifications to include new response types related to contract updates.
  • Bug Fixes

    • Improved validation and authorization checks for updating the gateway contract.
  • Tests

    • Added comprehensive unit tests for the MsgUpdateGatewayContract functionality and the associated CLI command.
  • Documentation

    • Updated documentation to include details about the new command and its usage.

Copy link
Contributor

coderabbitai bot commented Jul 29, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The changes introduce significant enhancements to the ZetaChain protocol, focusing on the management of gateway contracts. A new command and message type allow users to update the gateway contract address through the CLI, while updates to various protocols and specifications ensure these changes are well-integrated. This functionality supports dynamic contract management and increases the operational flexibility of the ZetaChain ecosystem.

Changes

Files Change Summary
docs/cli/zetacored/zetacored_tx_fungible.md, docs/cli/zetacored/zetacored_tx_fungible_update-gateway-contract.md Added documentation for the command zetacored tx fungible update-gateway-contract to manage gateway contract updates.
docs/openapi/openapi.swagger.yaml Introduced new response types, including fungibleMsgUpdateGatewayContractResponse, and added a gateway property to enhance API capabilities.
docs/spec/fungible/messages.md Added the MsgUpdateGatewayContract message type, enabling updates to the gateway contract address.
proto/zetachain/zetacore/fungible/events.proto Defined a new event EventGatewayContractUpdated to track updates to gateway contracts, capturing relevant details.
proto/zetachain/zetacore/fungible/system_contract.proto Added a gateway field to the SystemContract message to store the gateway contract address.
proto/zetachain/zetacore/fungible/tx.proto Introduced the RPC method UpdateGatewayContract and related message types to facilitate gateway contract updates within the protocol.
x/authority/types/authorization_list.go Updated authorization list to include the new message type for gateway contract updates.
x/fungible/client/cli/tx.go, x/fungible/client/cli/tx_update_gateway_contract.go Implemented CmdUpdateGatewayContract CLI command for managing gateway contract updates.
x/fungible/keeper/msg_server_update_gateway_contract.go, x/fungible/keeper/msg_server_update_gateway_contract_test.go Implemented and tested the logic for updating the gateway contract, ensuring proper authorization and event emission.
x/fungible/types/codec.go, x/fungible/types/message_update_gateway_contract.go, x/fungible/types/message_update_gateway_contract_test.go Defined the MsgUpdateGatewayContract structure and added extensive tests to validate its functionality and ensure reliability in contract updates.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant MsgServer
    participant Keeper
    participant EventSystem

    User->>CLI: CmdUpdateGatewayContract(newAddress)
    CLI->>MsgServer: UpdateGatewayContract(msg)
    MsgServer->>Keeper: Update gateway contract state
    Keeper->>EventSystem: Emit EventGatewayContractUpdated
    EventSystem->>MsgServer: Confirmation of event
    MsgServer-->>CLI: Success response
    CLI-->>User: Update successful
Loading

Assessment against linked issues

Objective Addressed Explanation
Add ZEVM Gateway in SystemContract (#[2577])
Add a message MsgUpdateGateway for gateway address update (#[2577])

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.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 90.19608% with 5 lines in your changes missing coverage. Please review.

Project coverage is 71.62%. Comparing base (76de4b7) to head (d1c9c32).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2578      +/-   ##
===========================================
+ Coverage    71.57%   71.62%   +0.05%     
===========================================
  Files          327      329       +2     
  Lines        17798    17849      +51     
===========================================
+ Hits         12739    12785      +46     
- Misses        4490     4493       +3     
- Partials       569      571       +2     
Files Coverage Δ
x/authority/types/authorization_list.go 100.00% <ø> (ø)
.../fungible/types/message_update_gateway_contract.go 100.00% <100.00%> (ø)
...gible/keeper/msg_server_update_gateway_contract.go 79.16% <79.16%> (ø)

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 (8)
x/fungible/client/cli/tx_update_gateway_contract.go (1)

12-34: Remove the extra space in the command usage string.

The usage string has an extra space at the end.

-		Use:   "update-gateway-contract [contract-address] ",
+		Use:   "update-gateway-contract [contract-address]",
docs/cli/zetacored/zetacored_tx_fungible.md (1)

35-35: Fix the hard tabs issue.

Replace hard tabs with spaces to adhere to Markdownlint rules.

-	* [zetacored tx fungible update-gateway-contract](zetacored_tx_fungible_update-gateway-contract.md)	 - Broadcast message UpdateGatewayContract to update the gateway contract address
+  * [zetacored tx fungible update-gateway-contract](zetacored_tx_fungible_update-gateway-contract.md) - Broadcast message UpdateGatewayContract to update the gateway contract address
Tools
Markdownlint

35-35: Column: 100
Hard tabs

(MD010, no-hard-tabs)

docs/spec/fungible/messages.md (1)

143-152: Clear and accurate documentation for MsgUpdateGatewayContract.

The documentation for the new message type MsgUpdateGatewayContract is clear and accurate, describing its purpose and fields. However, there are hard tab issues that need to be fixed.

message MsgUpdateGatewayContract {
-	string creator = 1;
-	string new_gateway_contract_address = 2;
+  string creator = 1;
+  string new_gateway_contract_address = 2;
}
Tools
Markdownlint

149-149: Column: 1
Hard tabs

(MD010, no-hard-tabs)


150-150: Column: 1
Hard tabs

(MD010, no-hard-tabs)

docs/cli/zetacored/zetacored_tx_fungible_update-gateway-contract.md (5)

1-1: Fix the heading level.

The heading level should start from ## instead of # to maintain consistency with the documentation hierarchy.

-# tx fungible update-gateway-contract
+## tx fungible update-gateway-contract

5-5: Specify the language for the fenced code block.

Fenced code blocks should have a language specified for proper syntax highlighting.

-```
+```shell
Tools
Markdownlint

5-5: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


11-11: Specify the language for the fenced code block.

Fenced code blocks should have a language specified for proper syntax highlighting.

-```
+```shell
Tools
Markdownlint

11-11: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


42-42: Specify the language for the fenced code block.

Fenced code blocks should have a language specified for proper syntax highlighting.

-```
+```shell
Tools
Markdownlint

42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


52-52: Avoid using hard tabs.

Replace hard tabs with spaces for consistency and to avoid formatting issues.

-* [zetacored tx fungible](zetacored_tx_fungible.md)	 - fungible transactions subcommands
+* [zetacored tx fungible](zetacored_tx_fungible.md) - fungible transactions subcommands
Tools
Markdownlint

52-52: Column: 52
Hard tabs

(MD010, no-hard-tabs)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9faeb15 and 14dcdfa.

Files ignored due to path filters (6)
  • typescript/zetachain/zetacore/fungible/events_pb.d.ts is excluded by !**/*_pb.d.ts
  • typescript/zetachain/zetacore/fungible/system_contract_pb.d.ts is excluded by !**/*_pb.d.ts
  • typescript/zetachain/zetacore/fungible/tx_pb.d.ts is excluded by !**/*_pb.d.ts
  • x/fungible/types/events.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/fungible/types/system_contract.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/fungible/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (16)
  • docs/cli/zetacored/zetacored_tx_fungible.md (1 hunks)
  • docs/cli/zetacored/zetacored_tx_fungible_update-gateway-contract.md (1 hunks)
  • docs/openapi/openapi.swagger.yaml (2 hunks)
  • docs/spec/fungible/messages.md (1 hunks)
  • proto/zetachain/zetacore/fungible/events.proto (1 hunks)
  • proto/zetachain/zetacore/fungible/system_contract.proto (1 hunks)
  • proto/zetachain/zetacore/fungible/tx.proto (2 hunks)
  • x/authority/types/authorization_list.go (1 hunks)
  • x/authority/types/authorization_list_test.go (1 hunks)
  • x/fungible/client/cli/tx.go (1 hunks)
  • x/fungible/client/cli/tx_update_gateway_contract.go (1 hunks)
  • x/fungible/keeper/msg_server_update_gateway_contract.go (1 hunks)
  • x/fungible/keeper/msg_server_update_gateway_contract_test.go (1 hunks)
  • x/fungible/types/codec.go (2 hunks)
  • x/fungible/types/message_update_gateway_contract.go (1 hunks)
  • x/fungible/types/message_update_gateway_contract_test.go (1 hunks)
Additional context used
Path-based instructions (12)
proto/zetachain/zetacore/fungible/system_contract.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

x/fungible/client/cli/tx.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/client/cli/tx_update_gateway_contract.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/types/codec.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

proto/zetachain/zetacore/fungible/events.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

x/fungible/types/message_update_gateway_contract.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/keeper/msg_server_update_gateway_contract.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/types/message_update_gateway_contract_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

proto/zetachain/zetacore/fungible/tx.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

x/fungible/keeper/msg_server_update_gateway_contract_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/authority/types/authorization_list.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/authority/types/authorization_list_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Markdownlint
docs/cli/zetacored/zetacored_tx_fungible.md

35-35: Column: 100
Hard tabs

(MD010, no-hard-tabs)

docs/spec/fungible/messages.md

149-149: Column: 1
Hard tabs

(MD010, no-hard-tabs)


150-150: Column: 1
Hard tabs

(MD010, no-hard-tabs)

docs/cli/zetacored/zetacored_tx_fungible_update-gateway-contract.md

9-9: Expected: h2; Actual: h3
Heading levels should only increment by one level at a time

(MD001, heading-increment)


52-52: Column: 52
Hard tabs

(MD010, no-hard-tabs)


5-5: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


11-11: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


42-42: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

GitHub Check: codecov/patch
x/fungible/keeper/msg_server_update_gateway_contract.go

[warning] 21-21: x/fungible/keeper/msg_server_update_gateway_contract.go#L21
Added line #L21 was not covered by tests


[warning] 48-49: x/fungible/keeper/msg_server_update_gateway_contract.go#L48-L49
Added lines #L48 - L49 were not covered by tests

Additional comments not posted (30)
docs/openapi/openapi.swagger.yaml (2)

Line range hint 1-1:
Addition of fungibleMsgUpdateGatewayContractResponse looks good.

The new response type is well-defined and enhances the API's ability to handle gateway contract updates.


Line range hint 1-1:
Addition of gateway property looks good.

The new property enhances the API's ability to convey information related to the gateway.

proto/zetachain/zetacore/fungible/system_contract.proto (1)

11-11: Addition of gateway field looks good.

The new field enhances the SystemContract message by allowing it to store information related to the gateway.

x/fungible/client/cli/tx.go (1)

32-32: Addition of CmdUpdateGatewayContract command looks good.

The new command enhances the CLI by allowing users to update the gateway contract.

x/fungible/client/cli/tx_update_gateway_contract.go (3)

1-10: Imports and package declaration are appropriate.

The package and imports are correctly defined and necessary for the functionality.


12-34: Function implementation is correct.

The function correctly creates the transaction context, constructs the message, validates it, and broadcasts it.


32-34: Transaction flags are correctly added.

Adding transaction flags to the command is necessary for its correct functionality.

x/fungible/types/codec.go (2)

20-20: New message type is correctly registered.

The new message type MsgUpdateGatewayContract is correctly registered with the codec.


34-34: New message type is correctly registered with the interface registry.

The new message type MsgUpdateGatewayContract is correctly registered with the interface registry.

proto/zetachain/zetacore/fungible/events.proto (1)

71-76: New message definition is appropriate.

The new message EventGatewayContractUpdated is correctly defined to capture the necessary information for gateway contract updates.

x/fungible/types/message_update_gateway_contract.go (6)

14-19: LGTM!

The method correctly initializes the MsgUpdateGatewayContract message.


21-23: LGTM!

The method correctly returns the router key.


25-27: LGTM!

The method correctly returns the message type.


29-35: LGTM!

The method correctly retrieves the signers and handles the error appropriately.


37-40: LGTM!

The method correctly marshals the message to JSON and sorts it.


42-56: LGTM!

The method correctly validates the creator address and the gateway contract address. Proper error handling is in place.

x/fungible/keeper/msg_server_update_gateway_contract.go (1)

13-53: LGTM!

The method correctly handles authorization, updates the state, and emits events.

Tools
GitHub Check: codecov/patch

[warning] 21-21: x/fungible/keeper/msg_server_update_gateway_contract.go#L21
Added line #L21 was not covered by tests


[warning] 48-49: x/fungible/keeper/msg_server_update_gateway_contract.go#L48-L49
Added lines #L48 - L49 were not covered by tests

x/fungible/types/message_update_gateway_contract_test.go (5)

14-44: Comprehensive test coverage for ValidateBasic.

The test cases effectively cover invalid and valid addresses for the ValidateBasic method. Consider adding edge cases, such as empty strings or excessively long addresses, to ensure robustness.


47-81: Effective test coverage for GetSigners.

The test cases appropriately handle scenarios with valid and invalid signers, ensuring the method's robustness.


84-89: Correct verification of message type.

The test case accurately verifies the Type method's return value.


91-96: Correct verification of router key.

The test case accurately verifies the Route method's return value.


98-105: Ensuring GetSignBytes does not panic.

The test case effectively ensures that the GetSignBytes method does not cause a panic.

proto/zetachain/zetacore/fungible/tx.proto (3)

27-28: Correct addition of UpdateGatewayContract RPC method.

The new RPC method UpdateGatewayContract is correctly defined and integrated, allowing for updates to the gateway contract address.


116-119: Correct definition of MsgUpdateGatewayContract message.

The new message type MsgUpdateGatewayContract is correctly defined with fields for the creator and the new gateway contract address.


121-121: Correct definition of MsgUpdateGatewayContractResponse message.

The new message type MsgUpdateGatewayContractResponse is correctly defined as an empty message.

x/fungible/keeper/msg_server_update_gateway_contract_test.go (3)

14-54: Good test case structure.

The test case can update the gateway contract address stored in the module is well-structured with clear arrangement, act, and assert phases.


56-93: Comprehensive test coverage.

The test case can update and overwrite the gateway contract if system contract state variable not found covers an important edge case where the system contract state variable is not found.


95-116: Correctly handles unauthorized access.

The test case should prevent update the gateway contract if not admin correctly handles the scenario where an unauthorized user attempts to update the gateway contract.

x/authority/types/authorization_list.go (1)

31-31: New message type added correctly.

The new message type "/zetachain.zetacore.fungible.MsgUpdateGatewayContract" is correctly added to the AdminPolicyMessages list.

x/authority/types/authorization_list_test.go (1)

423-423: Confirm the correct integration of the new message type.

The addition of sdk.MsgTypeURL(&fungibletypes.MsgUpdateGatewayContract{}) to the AdminPolicyMessageList appears correct. Ensure that this message type is properly defined and integrated within the system.

Verification successful

The new message type MsgUpdateGatewayContract is correctly integrated.

The addition of sdk.MsgTypeURL(&fungibletypes.MsgUpdateGatewayContract{}) to the AdminPolicyMessageList is appropriate and well-supported by the existing codebase. The message type is properly defined and integrated within the system.

  • Definition found in x/fungible/types/tx.pb.go.
  • Usage confirmed across multiple files, including x/fungible/keeper/msg_server_update_gateway_contract.go and various test files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and integration of MsgUpdateGatewayContract.

# Test: Search for the definition of MsgUpdateGatewayContract. Expect: Definition should exist.
rg --type go 'type MsgUpdateGatewayContract' -A 10

# Test: Search for the usage of MsgUpdateGatewayContract. Expect: Proper integration within the system.
rg --type go 'MsgUpdateGatewayContract'

Length of output: 11643

Copy link
Contributor

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

Left some non-blocking comments

Co-authored-by: Dmitry S <11892559+swift1337@users.noreply.github.com>
@lumtis lumtis added this pull request to the merge queue Jul 30, 2024
Merged via the queue into develop with commit 5771df3 Jul 30, 2024
28 checks passed
@lumtis lumtis deleted the feat/gateway-address branch July 30, 2024 17:05
Copy link
Contributor

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add zevm Gateway contract as part of the SystemContract structure
4 participants