Skip to content

refactor(e2e): load EVM addresses dynamically#3512

Merged
gartnera merged 10 commits intodevelopfrom
e2e-dynamic-addresses
Feb 13, 2025
Merged

refactor(e2e): load EVM addresses dynamically#3512
gartnera merged 10 commits intodevelopfrom
e2e-dynamic-addresses

Conversation

@gartnera
Copy link
Contributor

@gartnera gartnera commented Feb 11, 2025

Pull all EVM contract addresses from the gateway attributes rather than looking at the config. Can't do this since the zetaConnector attribute is 0

Pull all EVM contract addresses from the observer chain parameters. Make balance checks a bit more safe so that they won't make infrastructure CI hard fail.

This feels a bit messy overall. The ultimate goal is to completely purge contract addresses from the config. This intermediate state is a bit awkward.

Summary by CodeRabbit

  • New Features

    • Enhanced CLI token configuration, enabling improved support for specifying token details such as network and symbol.
    • Upgraded balance reporting for tokens, offering more accurate and reliable results.
  • Refactor

    • Streamlined flag processing and contract setup for token operations, resulting in clearer error messages and smoother command execution.

@gartnera gartnera added no-changelog Skip changelog CI check SOLANA_TESTS Run make start-solana-test labels Feb 11, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

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

This pull request refactors the CLI token management and balance retrieval logic. It introduces functions to register and process ERC20 and ZRC20 flags, including new error handling and context cancellation in command execution. The contract setup logic is modularized with functions to retrieve chain parameters and foreign coin data. In addition, an interface for ERC20 balance retrieval is defined, replacing previous implementations to improve flexibility in balance fetching. Redundant flag declarations and functions have been removed to streamline the processing of token configurations.

Changes

File(s) Change Summary
cmd/zetae2e/balances.go
cmd/zetae2e/run.go
Added a call to registerERC20Flags(cmd) and integrated processZRC20Flags(cmd, &conf) for flag processing with enhanced error handling and proper context cancellation; removed obsolete flag declarations and the findERC20 function.
cmd/zetae2e/common.go Introduced new functions registerERC20Flags, processZRC20Flags, and findZRC20 to manage ERC20 and ZRC20 token flags, including gRPC calls and validation of token configurations.
cmd/zetae2e/config/contracts.go Refactored contract setup logic by adding modular functions (chainParamsBySelector, chainParamsByChainID, foreignCoinByChainID, and setContractsGatewayEVM) to streamline retrieval of chain parameters and foreign coin information and centralize EVM contract address processing.
e2e/runner/balances.go Defined a new ERC20BalanceOf interface for retrieving token balances and updated getERC20BalanceSafe to use this interface with added error handling for nil cases, thereby replacing the old getZRC20BalanceSafe method for improved balance retrieval flexibility.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant BC as BalancesCmd
    participant REF as registerERC20Flags
    participant PZF as processZRC20Flags
    participant Ctx as Context (defer cancel)
    
    U->>BC: Execute balance command
    BC->>REF: Register ERC20 flags
    BC->>PZF: Process ZRC20/ERC20 flags
    PZF-->>BC: Return processed flag values (or error)
    BC->>Ctx: Call defer cancel(nil)
Loading
sequenceDiagram
    participant Caller as Balance Caller
    participant G as getERC20BalanceSafe
    participant ERC as ERC20BalanceOf Interface
    
    Caller->>G: Request ERC20 balance for account
    alt Interface is not nil
        G->>ERC: Invoke BalanceOf for balance retrieval
        ERC-->>G: Return balance value
    else Interface is nil
        G-->>G: Log issue and create new big.Int
    end
    G-->>Caller: Return finalized balance value
Loading

Possibly related PRs

Suggested labels

UPGRADE_TESTS, ADMIN_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • ws4charlie
  • lumtis
  • swift1337
  • skosito

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@gartnera gartnera force-pushed the e2e-dynamic-addresses branch from 5e97b07 to ceb03d3 Compare February 11, 2025 05:28
@gartnera gartnera changed the title refactor(e2e): load all EVM addresses dynamically refactor(e2e): load EVM addresses dynamically Feb 11, 2025
@codecov
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.52%. Comparing base (4edb6e8) to head (87d1b8f).
Report is 10 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3512      +/-   ##
===========================================
- Coverage    65.54%   65.52%   -0.03%     
===========================================
  Files          444      445       +1     
  Lines        30563    30606      +43     
===========================================
+ Hits         20034    20055      +21     
- Misses        9675     9697      +22     
  Partials       854      854              

see 16 files with indirect coverage changes

@gartnera gartnera force-pushed the e2e-dynamic-addresses branch from 8f24316 to e4c6b35 Compare February 11, 2025 20:57
@gartnera gartnera marked this pull request as ready for review February 11, 2025 21:10
@gartnera gartnera requested a review from a team as a code owner February 11, 2025 21:10
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: 3

🧹 Nitpick comments (7)
cmd/zetae2e/config/contracts.go (3)

33-43: Consider returning an error when the selector fails to match.
Currently, this function returns nil if no matching ChainParams is found, which may lead to unhandled nil references downstream. Introducing a clear error message in such a case can make debugging simpler.

 func chainParamsBySelector(
 	chainParams []*types.ChainParams,
 	selector func(chainID int64, additionalChains []chains.Chain) bool,
 ) (*types.ChainParams, error) {
 	for _, chainParam := range chainParams {
 		if selector(chainParam.ChainId, nil) {
-			return chainParam
+			return chainParam, nil
 		}
 	}
-	return nil
+	return nil, fmt.Errorf("no chain parameters matched the selector")
 }

45-52: Optional enhancement for chainParamsByChainID.
Similar to the previous function, returning an error rather than nil could improve the robustness of error handling.


104-105: Direct assertion may be too strict for non-test usage.
Calling require.NoError(r, err) aborts on error, which is typically used in tests rather than production-like code. If this function is partly used outside of test contexts, consider returning the error to handle it gracefully.

cmd/zetae2e/balances.go (1)

52-57: Consider providing an explicit error cause to cancel.
Calling defer cancel(nil) will remove the context without a specific error cause. If you prefer capturing errors in cancellation, you might pass the actual error object for better traceability. Otherwise, this usage is acceptable.

cmd/zetae2e/common.go (2)

25-53: Flag processing logic is correct.
When both network and symbol are specified, the code retrieves the relevant addresses. However, if multiple coins share a prefix or suffix, there may be ambiguity in matching the symbol. If that becomes a frequent scenario, consider refining the symbol-matching logic.


55-103: ZRC20 discovery is neatly structured.
The partial symbol match (prefix/suffix) could cause collisions if multiple tokens share naming similarities. If this is expected, keep it as is; otherwise, consider validating exact matches or providing a more robust lookup mechanism.

e2e/runner/balances.go (1)

45-57: Consider a more descriptive function name.

While the implementation is solid, the function name could better reflect its safe nature and nil-checking behavior.

Consider renaming to getSafeERC20Balance or getERC20BalanceWithNilCheck:

-func (r *E2ERunner) getERC20BalanceSafe(z ERC20BalanceOf, name string) *big.Int {
+func (r *E2ERunner) getSafeERC20Balance(z ERC20BalanceOf, name string) *big.Int {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6884a34 and e4c6b35.

📒 Files selected for processing (5)
  • cmd/zetae2e/balances.go (3 hunks)
  • cmd/zetae2e/common.go (1 hunks)
  • cmd/zetae2e/config/contracts.go (3 hunks)
  • cmd/zetae2e/run.go (2 hunks)
  • e2e/runner/balances.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

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

  • cmd/zetae2e/balances.go
  • cmd/zetae2e/common.go
  • e2e/runner/balances.go
  • cmd/zetae2e/run.go
  • cmd/zetae2e/config/contracts.go
🔇 Additional comments (17)
cmd/zetae2e/config/contracts.go (6)

6-6: No issues with new imports.
These imports are standard in Go for Ethereum-related functionalities and test assertions.

Also applies to: 8-8


24-25: Imports confirmed.
These are valid imports for working with chain data and fungible types. No concerns here.

Also applies to: 29-30


107-114: Approach for Solana chain parameters looks consistent.
No particular concerns; usage of chainParamsBySelector is straightforward, and the code sets the Solana gateway program only if the config or chain parameters are present.


141-144: Fetching foreign coins logic is valid.
The error handling and usage of Fungible.ForeignCoinsAll for retrieving external coin data appear consistent with the rest of the code.


149-157: Referenced pointer in foreignCoinByChainID reappears here.
This usage depends on the pointer fix recommended above. Once that is resolved, referencing ethForeignCoin here should be safe.


158-166: Initialization of SystemContract is correct.
The address validation and instantiation pattern aligns with the rest of the codebase. No additional issues.

cmd/zetae2e/balances.go (2)

5-5: Import statement approved.
Including "fmt" is necessary for formatted error wrapping.


31-31: ERC20 flags registration approved.
Registering ERC20 flags here consolidates flag declarations, improving maintainability.

cmd/zetae2e/common.go (4)

1-2: New package creation is acceptable.
Defining this as package main is a reasonable approach for a CLI tool.


3-16: Imports appear relevant and valid.
This set of imports covers the entire functionality needed for chain-specific calls, string utilities, and CLI interactions.


17-18: Flag constants declared properly.
Straightforward usage of constants for CLI flags.


20-23: Registration of ERC20 flags is concise.
The function straightforwardly attaches CLI flags for future processing.

cmd/zetae2e/run.go (3)

45-45: LGTM: Flag registration is properly placed.

The registerERC20Flags call is well-positioned before other flag registrations, maintaining a clean separation of concerns.


73-76: LGTM: Error handling follows best practices.

The error handling is idiomatic Go, with proper error wrapping and descriptive messages.


79-80: LGTM: Context handling is robust.

Using context.WithCancelCause is a good practice for propagating cancellation reasons, and the deferred cleanup ensures proper resource management.

e2e/runner/balances.go (2)

41-43: LGTM: Interface is well-defined and focused.

The ERC20BalanceOf interface follows Go's interface naming conventions and uses appropriate types from go-ethereum.


70-74: LGTM: Balance retrieval is consistent and robust.

The balance retrieval implementation consistently uses the safe balance checking method across all token types.

@gartnera gartnera enabled auto-merge February 12, 2025 16:27
@gartnera gartnera added this pull request to the merge queue Feb 13, 2025
Merged via the queue into develop with commit c0d5f13 Feb 13, 2025
45 checks passed
@gartnera gartnera deleted the e2e-dynamic-addresses branch February 13, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking:cli no-changelog Skip changelog CI check SOLANA_TESTS Run make start-solana-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants