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

test: configure Solana gateway program id for E2E tests #3154

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Nov 13, 2024

Description

  • Removed hardcoded Solana gateway program ID and use configured address in the localnet.yml file.

Closes: #3148

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

Release Notes

  • New Features

    • Whitelist functionality for SPL tokens on Solana.
    • Integration of SPL deposits and withdrawals.
    • Enhanced end-to-end testing for Solana gateway configurations.
  • Bug Fixes

    • Resolved issues with out-of-gas errors during omnichain calls.
    • Fixed configuration resolution problems in the orchestrator.
  • Refactor

    • Improved the zetaclient and CLI for better performance and usability.
    • Updated contract address handling for consistency across configurations.

These updates significantly enhance the functionality and reliability of the ZetaChain ecosystem.

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

📝 Walkthrough

Walkthrough

This pull request introduces several enhancements, fixes, and refactoring efforts across the ZetaChain node. Key features include the whitelisting of SPL tokens on Solana, improvements in build reproducibility, and the integration of SPL deposits and withdrawals. The testing framework has been enhanced with new end-to-end tests for Solana configurations. Refactoring includes the removal of the HSM signer from the zetaclient and updates to the emissions module. Fixes address issues related to transaction processing and configuration resolution.

Changes

File Path Change Summary
changelog.md Updated to reflect various enhancements, fixes, and refactoring across multiple versions of ZetaChain node.
cmd/zetae2e/config/config.go Wrapped contract address assignments with config.DoubleQuotedString for consistent formatting.
cmd/zetae2e/config/contracts.go Updated contract address handling and added new contract assignments for ERC20 custody and test DApps.
cmd/zetae2e/config/local.yml Added gateway_program_id and spl entries under the solana section.
cmd/zetae2e/config/localnet.yml Introduced a new contracts section with Solana gateway program ID configuration.
cmd/zetae2e/local/local.go Updated SetupSolana method to accept an additional parameter for GatewayProgramID.
e2e/config/config.go Changed GatewayProgramID field type from string to DoubleQuotedString.
e2e/runner/setup_solana.go Updated SetupSolana method to accept a dynamic gatewayID parameter.
e2e/runner/solana.go Replaced hardcoded GatewayProgramID with instance variable r.GatewayProgram.
pkg/contracts/solana/gateway.go Removed constant SolanaGatewayProgramID and added new discriminator variables for gateway instructions.
pkg/contracts/solana/inbound_test.go Updated test functions to use OldSolanaGatewayAddressDevnet for gateway address.
zetaclient/chains/solana/observer/inbound_test.go Updated test function to use OldSolanaGatewayAddressDevnet for gateway address.
zetaclient/orchestrator/orchestrator_test.go Updated test cases to dynamically source the Solana gateway address from test utilities.
zetaclient/testutils/constant.go Added constant OldSolanaGatewayAddressDevnet and updated gateway addresses in GatewayAddresses map.

Assessment against linked issues

Objective Addressed Explanation
Parameterize gateway program ID for e2e tests (3148)
Use different values for e2e tests and live networks (3148)

Possibly related PRs

Suggested labels

no-changelog

Suggested reviewers

  • fbac
  • kingpinXD
  • brewmaster012
  • lumtis
  • skosito
  • swift1337

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 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.

@ws4charlie ws4charlie added chain:solana SOLANA_TESTS Run make start-solana-test E2E E2E tests related and removed breaking:cli labels Nov 13, 2024
@ws4charlie ws4charlie marked this pull request as ready for review November 13, 2024 21:20
@ws4charlie ws4charlie changed the title test: configure Solana gateway program id in E2E test test: configure Solana gateway program id for E2E tests Nov 13, 2024
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: 2

🧹 Outside diff range and nitpick comments (16)
pkg/contracts/solana/gateway.go (3)

Line range hint 1-1: Fix typo in package documentation

There's a typo in the package documentation: "privides" should be "provides".

-// Package solana privides structures and constants that are used when interacting with the gateway program on Solana chain.
+// Package solana provides structures and constants that are used when interacting with the gateway program on Solana chain.

29-44: Consider grouping related discriminators

The discriminators are well-documented but could be organized better. Consider grouping them logically:

  1. Initialization discriminators (Initialize, InitializeRentPayer)
  2. Transaction discriminators (Deposit, DepositSPL, Withdraw, WithdrawSPL)
  3. Management discriminators (WhitelistSplMint)
 var (
 	// Initialization
 	DiscriminatorInitialize = idlgateway.IDLGateway.GetDiscriminator("initialize")
 	DiscriminatorInitializeRentPayer = idlgateway.IDLGateway.GetDiscriminator("initialize_rent_payer")
 
 	// Transaction Operations
 	DiscriminatorDeposit = idlgateway.IDLGateway.GetDiscriminator("deposit")
 	DiscriminatorDepositSPL = idlgateway.IDLGateway.GetDiscriminator("deposit_spl_token")
 	DiscriminatorWithdraw = idlgateway.IDLGateway.GetDiscriminator("withdraw")
 	DiscriminatorWithdrawSPL = idlgateway.IDLGateway.GetDiscriminator("withdraw_spl_token")
 
 	// Management Operations
 	DiscriminatorWhitelistSplMint = idlgateway.IDLGateway.GetDiscriminator("whitelist_spl_mint")
 )

Line range hint 47-73: Consider adding input validation for gateway address

The utility functions are well-implemented, but ParseGatewayWithPDA could benefit from additional validation before processing the gateway address.

 func ParseGatewayWithPDA(gatewayAddress string) (solana.PublicKey, solana.PublicKey, error) {
 	var gatewayID, pda solana.PublicKey
 
+	if gatewayAddress == "" {
+		return gatewayID, pda, errors.New("gateway address cannot be empty")
+	}
+
 	// decode gateway address
 	gatewayID, err := solana.PublicKeyFromBase58(gatewayAddress)
 	if err != nil {
 		return gatewayID, pda, errors.Wrap(err, "unable to decode address")
 	}
cmd/zetae2e/config/config.go (2)

Line range hint 58-87: Consider refactoring for improved maintainability.

The function could benefit from being split into smaller, focused helper functions for each blockchain platform.

Consider refactoring like this:

 func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.Config {
-    // copy contracts from deployer runner
-    conf.Contracts.Solana.GatewayProgramID = config.DoubleQuotedString(r.GatewayProgram.String())
-    // ... rest of the assignments
+    conf = exportSolanaContracts(r, conf)
+    conf = exportEVMContracts(r, conf)
+    conf = exportZEVMContracts(r, conf)
+    conf = exportV2Contracts(r, conf)
     return conf
 }

+func exportSolanaContracts(r *runner.E2ERunner, conf config.Config) config.Config {
+    conf.Contracts.Solana.GatewayProgramID = config.DoubleQuotedString(r.GatewayProgram.String())
+    conf.Contracts.Solana.SPLAddr = config.DoubleQuotedString(r.SPLAddr.String())
+    return conf
+}

Line range hint 82-87: Enhance documentation for v2 contracts.

The v2 contracts section would benefit from documentation explaining the upgrade path and differences from v1.

Add comments like this:

-    // v2
+    // v2 contracts represent the upgraded protocol version with enhanced features:
+    // - Improved gateway implementation
+    // - New custody contract with additional security measures
+    // - Updated test DApps compatible with v2 protocol
cmd/zetae2e/config/localnet.yml (3)

101-102: LGTM! Consider adding documentation.

The new contracts section provides a clean structure for configuration. Consider adding a comment block explaining the purpose and configuration options of this section.


103-104: Consider parameterizing the gateway program ID.

While using the old program ID (94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d) is valid for E2E tests, hardcoding it might limit flexibility. Consider:

  1. Using environment variables
  2. Adding a comment explaining why this specific ID is used
  3. Creating separate configuration files for different environments (e.g., localnet.yml, testnet.yml)

This would make it easier to manage different program IDs across environments.


105-105: Address empty SPL configuration and add newline.

Two issues need attention:

  1. The spl configuration is empty without explanation
  2. The file is missing a newline at EOF

Apply this diff to fix these issues:

  solana:
    gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"
-    spl: ""
+    # SPL token configuration for E2E tests
+    spl: ""
+
🧰 Tools
🪛 yamllint

[error] 105-105: no new line character at the end of file

(new-line-at-end-of-file)

zetaclient/chains/solana/observer/inbound_test.go (2)

74-74: Add documentation explaining gateway address usage

Consider adding a comment explaining why this specific test uses the old gateway address. This will help future maintainers understand the relationship between the test data and the gateway address configuration.

+	// Using old gateway address as the test data is from a historical devnet transaction
+	// that was processed with this specific gateway program ID
 	chainParams.GatewayAddress = testutils.OldSolanaGatewayAddressDevnet

74-74: Consider standardizing gateway address usage across tests

The test file uses different approaches for gateway addresses in different tests:

  • Test_FilterInboundEventAndVote uses GatewayAddressTest
  • Test_FilterInboundEvents uses testutils.OldSolanaGatewayAddressDevnet
  • Test_BuildInboundVoteMsgFromEvent uses sample.SolanaAddress(t)

Consider standardizing the approach or documenting why different tests need different gateway addresses.

Suggestions:

  1. Create a test helper that provides appropriate gateway addresses based on the test scenario
  2. Add constants for different gateway addresses with clear naming
  3. Document the rationale for using different addresses in different tests
cmd/zetae2e/config/local.yml (1)

122-122: Add newline at end of file

Add a newline character at the end of the file to comply with YAML formatting standards.

Apply this change:

    spl: ""
+
🧰 Tools
🪛 yamllint

[error] 122-122: no new line character at the end of file

(new-line-at-end-of-file)

cmd/zetae2e/config/contracts.go (1)

Line range hint 33-39: Ensure consistent error handling across contract setups

The Solana contract setup lacks error handling compared to EVM/ZEVM sections. Consider applying the same level of error checking for consistency.

 // set Solana contracts
 if c := conf.Contracts.Solana.GatewayProgramID; c != "" {
-    r.GatewayProgram = solana.MustPublicKeyFromBase58(c.String())
+    pubKey, err := solana.PublicKeyFromBase58(c.String())
+    if err != nil {
+        return fmt.Errorf("invalid GatewayProgramID: %w", err)
+    }
+    r.GatewayProgram = pubKey
 }

 if c := conf.Contracts.Solana.SPLAddr; c != "" {
-    r.SPLAddr = solana.MustPublicKeyFromBase58(c.String())
+    pubKey, err := solana.PublicKeyFromBase58(c.String())
+    if err != nil {
+        return fmt.Errorf("invalid SPLAddr: %w", err)
+    }
+    r.SPLAddr = pubKey
 }
e2e/runner/solana.go (1)

Line range hint 1-400: Consider enhancing test reliability with retries and timeouts.

The E2E test utilities could benefit from additional reliability mechanisms:

  1. Add retry mechanisms for transient Solana RPC failures
  2. Implement configurable timeouts for transaction confirmations
  3. Add validation for PDA account data after creation

Would you like me to provide a detailed implementation for these enhancements?

cmd/zetae2e/local/local.go (2)

227-230: Consider adding validation for the gateway program ID.

The implementation correctly configures the Solana gateway program ID from the configuration. However, consider adding validation to ensure the program ID is well-formed before passing it to SetupSolana.

+// Validate Solana gateway program ID
+if err := validateSolanaAddress(conf.Contracts.Solana.GatewayProgramID.String()); err != nil {
+    logger.Print("❌ invalid Solana gateway program ID: %v", err)
+    os.Exit(1)
+}
 deployerRunner.SetupSolana(
     conf.Contracts.Solana.GatewayProgramID.String(),
     conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String(),
 )

226-226: Track the TODO comment in the issue system.

The TODO comment references issue #2762 for simplifying this file. Consider breaking down the test orchestration into smaller, more focused files for better maintainability.

Would you like me to create a new GitHub issue to track the implementation of these test orchestration improvements?

zetaclient/orchestrator/orchestrator_test.go (1)

128-129: Consider consolidating gateway address configuration

The gateway address configuration for Solana and TON chains are set separately. Consider refactoring to use a common pattern for consistency.

-	solChainParams.GatewayAddress = testutils.GatewayAddresses[solChain.ChainId]
-	tonChainParams.GatewayAddress = sample.GenerateTONAccountID().ToRaw()
+	// Configure gateway addresses using chain-specific utilities
+	chainGatewayAddresses := map[int64]string{
+		solChain.ChainId: testutils.GatewayAddresses[solChain.ChainId],
+		tonChain.ChainId: sample.GenerateTONAccountID().ToRaw(),
+	}
+	for chainID, address := range chainGatewayAddresses {
+		if params := lo.FindOrNil([]observertypes.ChainParams{solChainParams, tonChainParams}, 
+			func(p observertypes.ChainParams) bool { return p.ChainId == chainID }); params != nil {
+			params.GatewayAddress = address
+		}
+	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d6ed9aa and 8b7afd8.

📒 Files selected for processing (14)
  • changelog.md (1 hunks)
  • cmd/zetae2e/config/config.go (1 hunks)
  • cmd/zetae2e/config/contracts.go (1 hunks)
  • cmd/zetae2e/config/local.yml (1 hunks)
  • cmd/zetae2e/config/localnet.yml (1 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/config/config.go (1 hunks)
  • e2e/runner/setup_solana.go (2 hunks)
  • e2e/runner/solana.go (2 hunks)
  • pkg/contracts/solana/gateway.go (1 hunks)
  • pkg/contracts/solana/inbound_test.go (2 hunks)
  • zetaclient/chains/solana/observer/inbound_test.go (1 hunks)
  • zetaclient/orchestrator/orchestrator_test.go (2 hunks)
  • zetaclient/testutils/constant.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (11)
cmd/zetae2e/config/config.go (1)

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

cmd/zetae2e/config/contracts.go (1)

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

cmd/zetae2e/local/local.go (1)

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

e2e/config/config.go (1)

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

e2e/runner/setup_solana.go (1)

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

e2e/runner/solana.go (1)

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

pkg/contracts/solana/gateway.go (1)

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

pkg/contracts/solana/inbound_test.go (1)

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

zetaclient/chains/solana/observer/inbound_test.go (1)

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

zetaclient/orchestrator/orchestrator_test.go (1)

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

zetaclient/testutils/constant.go (1)

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

🪛 yamllint
cmd/zetae2e/config/local.yml

[error] 122-122: no new line character at the end of file

(new-line-at-end-of-file)

cmd/zetae2e/config/localnet.yml

[error] 105-105: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (18)
pkg/contracts/solana/inbound_test.go (2)

82-82: Verify SPL token deposit compatibility.

The gateway address change is consistent with the previous test. However, since this test involves SPL tokens, we should verify that OldSolanaGatewayAddressDevnet supports SPL token deposits correctly.

✅ Verification successful

Gateway address change is compatible with SPL token deposits

The verification confirms that:

  1. The test data shows successful SPL token deposits through the gateway program
  2. The gateway program handles SPL deposits through a dedicated deposit_spl_token instruction
  3. No special gateway address requirements exist for SPL tokens versus native tokens

The gateway address change is safe as it only affects the test configuration and the gateway program handles both native and SPL token deposits through the same gateway address.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for SPL token specific gateway configurations and test data

# Look for SPL token specific configurations or tests
echo "Checking for SPL token specific gateway configurations:"
rg -A 5 "SPL.*[Gg]ateway|[Gg]ateway.*SPL" --type go

# Check if the SPL test data contains gateway address references
echo -e "\nChecking SPL test data:"
cat pkg/contracts/solana/testdata/aY8yLDze*.json | jq -r 'if has("gatewayAddress") then .gatewayAddress else empty end'

Length of output: 5530


Script:

#!/bin/bash
# Let's verify the test data content and gateway address usage

# Check the content of the SPL test data file
echo "Checking SPL test data content:"
cat "pkg/contracts/solana/testdata/aY8yLDze"*.json

# Look for gateway address usage in SPL deposit tests
echo -e "\nChecking gateway address usage in SPL deposit tests:"
rg -B 5 -A 5 "OldSolanaGatewayAddressDevnet.*SPL|SPL.*OldSolanaGatewayAddressDevnet" --type go

# Check for any SPL deposit specific configurations
echo -e "\nChecking SPL deposit configurations:"
rg -B 3 -A 3 "DepositSPL.*struct|DepositSPL.*interface" --type go

Length of output: 6951


50-50: Verify test data compatibility with new gateway address.

The gateway address change looks good, but we should ensure the test data in testdata/MS3MPLN7...json is compatible with OldSolanaGatewayAddressDevnet.

✅ Verification successful

Gateway address in test data matches the constant value

The test data files and gateway address are consistent. The transaction data shows interactions with program ID 94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d, which matches exactly with the OldSolanaGatewayAddressDevnet constant being used in the test. Both deposit and SPL deposit test cases are properly configured with the correct gateway address.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if other test files need similar gateway address updates and verify test data compatibility

# Find all test files that might reference gateway addresses
echo "Checking for other test files that might need updates:"
rg -l "GatewayAddress" --type go --glob "*_test.go"

# Check if the test data contains any gateway address references
echo -e "\nChecking test data for gateway address references:"
rg -l "gatewayAddress|GatewayAddress" pkg/contracts/solana/testdata/

Length of output: 5530


Script:

#!/bin/bash
# Let's check the specific test data file and gateway address references more precisely

# First, find the exact test data file name
echo "Looking for test data files in solana directory:"
fd -t f -e json . pkg/contracts/solana/testdata/

# Then check its contents
echo -e "\nChecking gateway address in test data:"
find pkg/contracts/solana/testdata/ -type f -name "*.json" -exec sh -c 'echo "=== $1 ==="; cat "$1" | jq .' {} \;

# Check for gateway address usage in the test file
echo -e "\nChecking gateway address usage in test file:"
rg -A 5 "GatewayAddress" pkg/contracts/solana/inbound_test.go

Length of output: 1290


Script:

#!/bin/bash
# Let's examine the contents of the test data files specifically

echo "=== Contents of first test file ==="
cat "pkg/contracts/solana/testdata/MS3MPLN7hkbyCZFwKqXcg8fmEvQMD74fN6Ps2LSWXJoRxPW5ehaxBorK9q1JFVbqnAvu9jXm6ertj7kT7HpYw1j.json"

echo -e "\n=== Contents of second test file ==="
cat "pkg/contracts/solana/testdata/aY8yLDze6nHSRi7L5REozKAZY1aAyPJ6TfibiqQL5JGwgSBkYux5z5JfXs5ed8LZqpXUy4VijoU3x15mBd66ZGE.json"

echo -e "\n=== Checking OldSolanaGatewayAddressDevnet constant ==="
rg "OldSolanaGatewayAddressDevnet" -A 2

Length of output: 6933

pkg/contracts/solana/gateway.go (1)

Line range hint 1-1: Verify all references to removed SolanaGatewayProgramID constant

The removal of the hardcoded SolanaGatewayProgramID constant aligns with the PR objectives. Let's verify all references have been updated.

✅ Verification successful

Removed constant appears only in test data and configuration files

The SolanaGatewayProgramID constant has been successfully removed, and all remaining references to the program ID 94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d are found only in:

  • Test data files (testdata/ directories)
  • Test utilities (zetaclient/testutils/constant.go)
  • Configuration files (cmd/zetae2e/config/)

These references are expected and do not require updates as they represent historical test data and configurable values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to SolanaGatewayProgramID
rg "SolanaGatewayProgramID" 

# Search for potential string literals that might be the old program ID
rg "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"

Length of output: 3909

zetaclient/testutils/constant.go (2)

42-43: LGTM! Well-documented constant declaration.

The constant name and documentation clearly indicate its purpose as the old gateway address for testing purposes.


47-49: Consider environment-specific addresses and configuration approach.

A few considerations:

  1. Using identical addresses for both devnet and mainnet environments might lead to confusion or issues. Consider using distinct addresses for better separation of concerns.
  2. Since the PR objectives mention making the gateway program ID configurable, consider moving these values to a configuration file instead of hardcoding them here.

Let's verify the usage of these addresses across the codebase:

cmd/zetae2e/config/config.go (1)

Line range hint 58-87: LGTM! Consistent string formatting applied across all contract addresses.

The implementation ensures uniform handling of contract addresses using config.DoubleQuotedString.

zetaclient/chains/solana/observer/inbound_test.go (1)

74-74: Verify test data compatibility with gateway address

The test uses archived transaction data from a specific Solana devnet transaction. We should verify that this transaction data is compatible with the old gateway address being used.

✅ Verification successful

Test data is correctly aligned with the gateway address

The test data files contain transactions that explicitly use the old gateway address 94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d. This matches exactly with the testutils.OldSolanaGatewayAddressDevnet constant being used in the test, ensuring compatibility between the test data and the gateway address configuration.

Key evidence from test data:

  • Transaction's program ID (accountKeys[3]) matches the old gateway address
  • Log messages show successful execution with the same program ID
  • The constant is properly documented in testutils/constant.go
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the test data contains references to the old gateway address

# Search for the old gateway address in the test data
rg -A 5 "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d" "${TestDataDir}"

# Check the transaction data file
fd -g "*MS3MPLN7hkbyCZFwKqXcg8fmEvQMD74fN6Ps2LSWXJoRxPW5ehaxBorK9q1JFVbqnAvu9jXm6ertj7kT7HpYw1j*" "${TestDataDir}" --exec cat {}

Length of output: 323


Script:

#!/bin/bash
# Let's first locate the test data directory and files
fd -t f -e json "MS3MPLN7hkbyCZFwKqXcg8fmEvQMD74fN6Ps2LSWXJoRxPW5ehaxBorK9q1JFVbqnAvu9jXm6ertj7kT7HpYw1j"

# Search for any references to gateway addresses in the test file
rg -A 5 "GatewayAddress" zetaclient/chains/solana/observer/inbound_test.go

# Look for the test data path pattern in the test file
rg "TestDataDir" zetaclient/chains/solana/observer/inbound_test.go

# Check for any constants or test data setup
rg "const.*TestData" zetaclient/chains/solana/observer/

Length of output: 1501


Script:

#!/bin/bash
# Let's examine the test data files we found
cat "pkg/contracts/solana/testdata/MS3MPLN7hkbyCZFwKqXcg8fmEvQMD74fN6Ps2LSWXJoRxPW5ehaxBorK9q1JFVbqnAvu9jXm6ertj7kT7HpYw1j.json"
cat "zetaclient/testdata/solana/chain_901_inbound_tx_result_MS3MPLN7hkbyCZFwKqXcg8fmEvQMD74fN6Ps2LSWXJoRxPW5ehaxBorK9q1JFVbqnAvu9jXm6ertj7kT7HpYw1j.json"

# Let's also check the testutils package for the gateway address constant
rg "OldSolanaGatewayAddressDevnet" -A 2

Length of output: 5654

e2e/runner/setup_solana.go (2)

30-30: LGTM: Method signature updated appropriately

The addition of the gatewayID parameter aligns with the PR objective to make the gateway program ID configurable, improving test flexibility.


144-144: LGTM: Verify chain params propagation

The GatewayAddress update correctly uses the configured program ID. However, let's verify the chain params update process:

✅ Verification successful

GatewayAddress update is correctly propagated

The verification confirms that the GatewayAddress parameter is consistently handled across the codebase:

  • Protocol-level definition in x/observer/types/params.pb.go
  • Proper equality checks in x/observer/types/chain_params.go
  • Consistent usage in tests with appropriate test fixtures
  • Parallel implementation for EVM chains in e2e/runner/v2_setup_zeta.go
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the chain params update logic across the codebase
# Look for other places where GatewayAddress might be set or used

# Check for other GatewayAddress assignments
rg -g '*.go' 'GatewayAddress.*=' --type go

# Check for chain params tests that might need updating
rg -g '*_test.go' 'ChainParams.*GatewayAddress' --type go

Length of output: 4089

cmd/zetae2e/config/local.yml (2)

121-121: Verify the gateway program ID configuration

According to issue #3148, this gateway program ID (94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d) corresponds to an old deployer key. While it's appropriate for E2E tests since we can't use the production ID (ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis), we should document this decision.

Consider adding a comment in the YAML file to explain why this specific ID is used for E2E tests. For example:

  solana:
+   # Using old deployer key for E2E tests as production key cannot be used
    gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"

122-122: Clarify the purpose of the empty SPL configuration

The spl: "" entry appears to be a placeholder. Please clarify its intended use or remove it if not needed.

Run the following to check if this configuration is referenced elsewhere:

✅ Verification successful

Let me search for any SPL-related configurations or usage patterns to better understand the context.


Empty SPL configuration is intentional for local environment setup

The empty SPL configuration (spl: "") is a valid placeholder used in local environment configurations. This is evidenced by:

  • It's consistently empty in both local.yml and localnet.yml
  • The codebase has extensive SPL (Solana Program Library) token support for testing and deployment
  • The configuration is used by the E2E test framework to optionally specify SPL token addresses (SPLAddr in config structs)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to solana.spl configuration
rg -l "solana\W+spl" || echo "No references found"

Length of output: 71


Script:

#!/bin/bash
# Search for any SPL related configurations or patterns
rg -i "spl[\"'\s:]" -A 2

# Also check for any SPL related imports or code
ast-grep --pattern 'import $_ from "$_spl$_"'

Length of output: 21223

🧰 Tools
🪛 yamllint

[error] 122-122: no new line character at the end of file

(new-line-at-end-of-file)

cmd/zetae2e/config/contracts.go (1)

Line range hint 1-300: Verify contract addresses in configuration files

The changes make the Solana gateway program ID configurable. Let's verify that all configuration files have been updated with valid addresses.

✅ Verification successful

Solana gateway program ID configuration is properly implemented

The verification confirms that:

  • The Solana gateway program ID is consistently configured in both local and localnet configuration files
  • The address 94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d is properly referenced across the codebase:
    • Used in test data files for validation
    • Defined as OldSolanaGatewayAddressDevnet in testutils
    • Correctly integrated in the gateway contract configuration
  • The implementation properly handles the program ID through the configuration system, with appropriate error handling and type safety
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check configuration files for Solana gateway program ID
# Expected: Find gateway_program_id in configuration files

echo "Checking configuration files for gateway_program_id:"
rg -l "gateway_program_id" --type yaml

echo -e "\nChecking the values:"
rg "gateway_program_id:" -A 1 --type yaml

Length of output: 604


Script:

#!/bin/bash
# Let's verify if this Solana address is valid and consistent across the codebase
# First, check if this address is referenced in any Go or Rust files
echo "Checking for Solana address usage in code:"
rg "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"

# Then check if there are any other Solana gateway program IDs that might conflict
echo -e "\nChecking for other potential gateway program IDs:"
rg -i "solana.*gateway.*program" -B 1 -A 1

Length of output: 8207

e2e/runner/solana.go (2)

35-35: LGTM! Verify rent payer PDA consistency.

The change to use r.GatewayProgram for rent payer PDA computation is correct.

Let's verify rent payer PDA computation consistency:

#!/bin/bash
# Description: Verify rent payer PDA computation consistency
# Search for any other rent payer PDA computations

# Look for FindProgramAddress calls with RentPayerPDASeed
rg -A 2 "FindProgramAddress.*RentPayerPDASeed"

# Look for potential rent-related PDA computations
ast-grep --pattern 'FindProgramAddress($$$rent$$$)'

24-24: LGTM! Verify PDA derivation consistency.

The change to use r.GatewayProgram instead of hardcoded program ID is correct and aligns with the PR objectives.

Let's verify that the PDA derivation remains consistent across different environments:

✅ Verification successful

PDA derivation consistency verified across codebase

The change to use r.GatewayProgram is consistent with all other PDA derivations in the codebase. The verification shows:

  • All FindProgramAddress calls use the same gateway program ID pattern
  • The PDASeed constant is consistently defined in pkg/contracts/solana/gateway.go
  • The change aligns with the global configuration pattern used throughout the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify PDA derivation consistency across configurations
# Search for any other PDA derivations using different program IDs

# Look for FindProgramAddress calls with the PDASeed
rg -A 2 "FindProgramAddress.*PDASeed" 

# Look for other potential gateway program ID references
rg -l "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d|ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis"

Length of output: 197


Script:

#!/bin/bash
# Let's try a more comprehensive search for PDA derivations and program IDs

# Search for FindProgramAddress calls
rg -A 3 "FindProgramAddress" 

# Search for gateway program related constants or configurations
rg -A 2 "GatewayProgram|gateway.*program"

# Look for any PDA seed definitions
rg "seed.*:=.*byte"

Length of output: 12631

e2e/config/config.go (1)

123-123: LGTM: Well-structured configuration field addition

The implementation correctly uses DoubleQuotedString type for consistent YAML marshaling and follows the established pattern in the codebase for address fields.

Let's verify the configuration loading:

✅ Verification successful

Let me verify the configuration loading implementation by checking how the field is used in the codebase.


Configuration field is properly integrated and utilized

The verification confirms that:

  • The GatewayProgramID field is correctly configured in both local and localnet YAML configurations
  • The field is properly utilized in the codebase:
    • Used in configuration loading (cmd/zetae2e/config/contracts.go)
    • Properly set during initialization (cmd/zetae2e/config/config.go)
    • Accessed in local implementation (cmd/zetae2e/local/local.go)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the gateway program ID configuration is properly loaded from YAML

# Check if the gateway_program_id is present in configuration files
echo "Checking configuration files for gateway_program_id..."
rg -l "gateway_program_id:" --type yaml

# Verify the structure matches our implementation
echo "Verifying configuration structure..."
rg -A 2 "solana:" --type yaml

Length of output: 1737


Script:

#!/bin/bash
# Check how GatewayProgramID is used in the code
echo "Checking usage of GatewayProgramID..."
rg -p "GatewayProgramID" -t go

# Check the configuration loading implementation
echo "Checking configuration loading implementation..."
ast-grep --pattern 'func $_(config $Config) $_ {
  $$$
}'

Length of output: 680

zetaclient/orchestrator/orchestrator_test.go (2)

43-43: LGTM: Gateway address configuration aligns with PR objectives

The change correctly implements the configurable Solana gateway address by sourcing it from testutils.GatewayAddresses, which aligns with the PR's goal of removing hardcoded values.


Line range hint 1-600: Verify test coverage for edge cases

The test suite comprehensively covers the happy path scenarios but could benefit from additional edge cases:

  1. Invalid gateway addresses
  2. Chain ID mismatches
  3. Network-specific address validation
✅ Verification successful

Based on the shell script results, I can see that the test suite already includes comprehensive error handling tests covering:

  1. Invalid chain scenarios (BSC, BTC testnet, Solana Devnet)
  2. Missing observer/signer error cases
  3. Invalid rate limiter input validation

Let me verify the address validation specifically:


Let me check the validation implementations in the mock objects and chain-specific code:


Let me check one final aspect - the actual chain-specific address validation implementations:


Test coverage for edge cases is comprehensive and well-implemented

The test suite already includes thorough validation for addresses across different chains:

  1. EVM chain validation:

    • Invalid hex addresses for both 'from' and 'to' fields
    • Empty address handling
    • Connector and custody contract address validation
  2. Solana chain validation:

    • Invalid gateway address tests
    • Address format validation
  3. Bitcoin chain validation:

    • Invalid revert address checks
    • Address type support validation
  4. TON chain validation:

    • Gateway address validation through the standard interfaces

The implementation includes proper validation at both the test and runtime levels, with appropriate error messages and handling of chain-specific address formats.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check test coverage for edge cases
echo "Checking for existing edge case tests..."

# Look for error condition tests
rg -B 2 -A 2 "require.Error|assert.Error" zetaclient/orchestrator/orchestrator_test.go

# Look for invalid address tests
rg -B 2 -A 2 "Invalid|invalid|malformed" zetaclient/orchestrator/orchestrator_test.go

# Look for chain-specific validation
ast-grep --pattern 'func Test_$_($_) {
  $$$
  require.Error($_)
  $$$
}'

Length of output: 2042


Script:

#!/bin/bash
# Check for address validation tests
rg -B 5 -A 5 "Address|address" zetaclient/orchestrator/orchestrator_test.go

# Look for validation in the implementation
rg -B 5 -A 5 "Address|address" zetaclient/orchestrator/orchestrator.go

Length of output: 7613


Script:

#!/bin/bash
# Check mock implementations for address validation
rg -B 5 -A 5 "SetGatewayAddress|SetZetaConnectorAddress|SetERC20CustodyAddress" zetaclient/testutils/mocks/

# Check chain-specific address validation
rg -B 5 -A 5 "Address.*valid|valid.*Address" pkg/chains/

Length of output: 3839


Script:

#!/bin/bash
# Check for address validation in chain implementations
rg -B 5 -A 5 "address.*valid|valid.*address" zetaclient/chains/

# Check interfaces for validation requirements
rg -B 5 -A 5 "address.*valid|valid.*address" zetaclient/chains/interfaces/

Length of output: 17662

changelog.md (1)

15-15: LGTM! The changelog entry is well-formatted and accurately describes the PR changes.

The entry follows the standard format and is correctly placed in the "Tests" section, reflecting the E2E test configuration changes for the Solana gateway program ID.

e2e/runner/setup_solana.go Show resolved Hide resolved
cmd/zetae2e/config/contracts.go Show resolved Hide resolved
Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

looks good, 2 small comments

zetaclient/testutils/constant.go Show resolved Hide resolved
cmd/zetae2e/config/local.yml Show resolved Hide resolved
@ws4charlie ws4charlie requested a review from lumtis November 13, 2024 23:22
@ws4charlie ws4charlie added this pull request to the merge queue Nov 14, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 14, 2024
@ws4charlie ws4charlie added this pull request to the merge queue Nov 14, 2024
Merged via the queue into develop with commit 07120f1 Nov 14, 2024
50 of 57 checks passed
@ws4charlie ws4charlie deleted the e2e-configure-solana-gateway-program_id branch November 14, 2024 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli chain:solana E2E E2E tests related SOLANA_TESTS Run make start-solana-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure gateway program id
4 participants