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: fix upgrade tests #3196

Merged
merged 12 commits into from
Nov 22, 2024
Merged

test: fix upgrade tests #3196

merged 12 commits into from
Nov 22, 2024

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Nov 21, 2024

Description

Fixes the upgrade and upgrade-light tests by making the following changes

  • Do not error if coin pair already exists for when creating uni swap coin pair
  • Skip Bitcoin dust withdraw for v21 test run

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

    • Introduced a new command-line flag to skip Bitcoin dust withdrawal tests in local end-to-end testing.
    • Updated scripts to include the new flag for running tests.
  • Bug Fixes

    • Enhanced error logging for cross-chain swap and ZRC20 swap tests to provide detailed error messages for better debugging.
    • Improved error handling in deposit and call swap tests, allowing for continued execution even if an error occurs.
  • Documentation

    • Added comments to clarify expected behavior in Bitcoin deposit tests related to dust amounts.

Copy link
Contributor

coderabbitai bot commented Nov 21, 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
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces a new command-line flag, flagSkipBitcoinDustWithdraw, to facilitate the skipping of specific Bitcoin dust withdrawal tests in local end-to-end testing. This flag is integrated into the existing command structure and modifies the test execution flow accordingly. Additionally, enhancements are made to error logging in several test functions to provide clearer error messages. The overall structure and functionality of the testing framework remain intact, ensuring consistent behavior across tests.

Changes

File Path Change Summary
cmd/zetae2e/local/local.go Added flagSkipBitcoinDustWithdraw flag to skip Bitcoin dust withdrawal tests; modified localE2ETest logic accordingly.
contrib/localnet/orchestrator/start-zetae2e.sh Updated start-zetae2e.sh to include --skip-bitcoin-dust-withdraw flag for test execution based on upgrade height.
e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go Added comments to clarify expected behavior of TestBitcoinDepositAndCallRevertWithDust.
e2e/e2etests/test_crosschain_swap.go Enhanced error logging in TestCrosschainSwap to include specific error details from CreatePair method.
e2e/e2etests/test_v2_deposit_and_call_swap.go Modified error handling in TestV2DepositAndCallSwap to log errors without failing the test immediately.
e2e/e2etests/test_zrc20_swap.go Improved error logging in TestZRC20Swap to provide specific error messages when creating pairs fails.

Possibly related PRs

Suggested labels

UPGRADE_LIGHT_TESTS

Suggested reviewers

  • skosito
  • ws4charlie
  • fbac
  • brewmaster012
  • lumtis
  • 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.

@kingpinXD kingpinXD added UPGRADE_TESTS Run make start-upgrade-tests TSS_MIGRATION_TESTS Run TSS migration tests no-changelog Skip changelog CI check labels Nov 21, 2024
@kingpinXD kingpinXD changed the title test: stop e2e test from erroring out if uniswap pair already exists test: fix upgrade tests Nov 22, 2024
@kingpinXD kingpinXD removed the TSS_MIGRATION_TESTS Run TSS migration tests label Nov 22, 2024
@kingpinXD kingpinXD marked this pull request as ready for review November 22, 2024 03:58
Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

lgtm

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

🧹 Outside diff range and nitpick comments (9)
e2e/e2etests/test_zrc20_swap.go (2)

Line range hint 16-21: Consider implementing a more robust initialization strategy.

The current approach of ignoring initialization failures, while functional, could be improved for better test reliability and clarity. Consider implementing a helper function that checks for pair existence before attempting creation.

func ensurePairExists(r *runner.E2ERunner) (ethcommon.Address, error) {
    pair, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.ERC20ZRC20Addr, r.ETHZRC20Addr)
    if err != nil {
        return ethcommon.Address{}, err
    }
    if pair != (ethcommon.Address{}) {
        return pair, nil
    }
    tx, err := r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.ETHZRC20Addr)
    if err != nil {
        return ethcommon.Address{}, err
    }
    receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
    return r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.ERC20ZRC20Addr, r.ETHZRC20Addr)
}

Line range hint 45-52: Consider restructuring gas limit management.

The current gas limit modification could be encapsulated in a helper function for better reusability and cleaner test structure.

func withCustomGasLimit(r *runner.E2ERunner, gasLimit uint64, fn func() error) error {
    previousGasLimit := r.ZEVMAuth.GasLimit
    r.ZEVMAuth.GasLimit = gasLimit
    defer func() {
        r.ZEVMAuth.GasLimit = previousGasLimit
    }()
    return fn()
}

Usage example:

err := withCustomGasLimit(r, 400000, func() error {
    tx, err := r.UniswapV2Router.AddLiquidity(
        r.ZEVMAuth,
        // ... existing parameters ...
    )
    if err != nil {
        return err
    }
    receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
    return nil
})
require.NoError(r, err)
e2e/e2etests/test_v2_deposit_and_call_swap.go (2)

Line range hint 13-16: Add timeline for test deprecation

The TODO comment provides good context and issue reference. Consider adding an expected timeline for removal to help track technical debt.

-// TODO: This test is similar to TestCrosschainSwap
+// TODO(#2711): This test is similar to TestCrosschainSwap and should be removed by Q2 2025

Line range hint 29-102: Improve test structure and readability

The test implementation could benefit from the following improvements:

  1. Extract setup steps into helper functions
  2. Encapsulate gas limit manipulation
  3. Define constants for magic numbers (e.g., 1e18, 1e10, 1e8)

Example refactor for gas limit manipulation:

func withTemporaryGasLimit(r *runner.E2ERunner, gasLimit uint64, fn func() error) error {
    previousLimit := r.ZEVMAuth.GasLimit
    r.ZEVMAuth.GasLimit = gasLimit
    defer func() {
        r.ZEVMAuth.GasLimit = previousLimit
    }()
    return fn()
}

Usage:

err := withTemporaryGasLimit(r, 400000, func() error {
    tx, err := r.UniswapV2Router.AddLiquidity(...)
    if err != nil {
        return err
    }
    return utils.WaitForTxReceipt(...)
})
require.NoError(r, err)
e2e/e2etests/test_crosschain_swap.go (1)

Line range hint 24-29: Consider refactoring pair creation into test setup

The TODO comment indicates that pair creation should be moved to setup. This would improve test organization and prevent potential side effects between test runs.

Consider:

  1. Moving pair creation to a shared setup function
  2. Adding a check for existing pairs
  3. Using test fixtures or a setup/teardown pattern

Example approach:

func setupUniswapPair(r *runner.E2ERunner) error {
    // Check if pair exists first
    pair, err := r.UniswapV2Factory.GetPair(nil, r.ERC20ZRC20Addr, r.BTCZRC20Addr)
    if err != nil {
        return fmt.Errorf("failed to check existing pair: %w", err)
    }
    if pair != (common.Address{}) {
        r.Logger.Printf("ℹ️ pair already exists at %s", pair.Hex())
        return nil
    }
    
    // Create new pair if needed
    _, err = r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.BTCZRC20Addr)
    if err != nil {
        return fmt.Errorf("failed to create pair: %w", err)
    }
    return nil
}
contrib/localnet/orchestrator/start-zetae2e.sh (2)

225-226: LGTM! Consider tracking the temporary flag.

The addition of the --skip-bitcoin-dust-withdraw flag aligns with the PR objectives. However, since this is a temporary change (as indicated by the comment), it would be beneficial to track its removal.

Would you like me to create a GitHub issue to track the removal of this flag after v23 is released?


Line range hint 1-1: Consider enhancing script robustness and security.

Several improvements could make the script more robust and secure:

  1. Add strict shell options at the beginning:
 #!/bin/bash
+set -euo pipefail
  1. Add timeout to curl commands to prevent hanging:
-curl -s -f zetacore0:1317/cosmos/base/tendermint/v1beta1/node_info
+curl --max-time 10 -s -f zetacore0:1317/cosmos/base/tendermint/v1beta1/node_info
  1. Consider moving hardcoded values to configuration:
-UPGRADE_HEIGHT=${UPGRADE_HEIGHT:=225}
+UPGRADE_HEIGHT=${UPGRADE_HEIGHT:=${DEFAULT_UPGRADE_HEIGHT}}
  1. Add error handling for external commands:
-solana airdrop 100 "$relayer" > /dev/null
+if ! solana airdrop 100 "$relayer" > /dev/null; then
+  echo "Failed to fund solana relayer"
+  exit 1
+fi
cmd/zetae2e/local/local.go (2)

90-91: Consider enhancing the flag description.

While the current description is clear, it could be more informative by explaining when and why one might want to skip these tests.

-	cmd.Flags().Bool(flagSkipBitcoinDustWithdraw, false, "set to true to skip tests that withdraw dust amount from Bitcoin")
+	cmd.Flags().Bool(flagSkipBitcoinDustWithdraw, false, "set to true to skip Bitcoin dust withdrawal tests (useful for environments where dust transactions are not supported or when testing other Bitcoin functionality)")

336-338: Consider a more idiomatic implementation.

The current implementation is correct but could be more elegant using a conditional initialization.

-		if !skipBitcoinDustWithdraw {
-			bitcoinDepositTests = append(bitcoinDepositTests, e2etests.TestBitcoinDepositAndCallRevertWithDustName)
-		}
+		bitcoinDepositTests := []string{
+			e2etests.TestBitcoinDonationName,
+			e2etests.TestBitcoinDepositName,
+			e2etests.TestBitcoinDepositAndCallName,
+			e2etests.TestBitcoinDepositAndCallRevertName,
+			e2etests.TestBitcoinStdMemoDepositName,
+			e2etests.TestBitcoinStdMemoDepositAndCallName,
+			e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
+			e2etests.TestBitcoinStdMemoDepositAndCallRevertOtherAddressName,
+			e2etests.TestBitcoinStdMemoInscribedDepositAndCallName,
+			e2etests.TestCrosschainSwapName,
+		}
+		if !skipBitcoinDustWithdraw {
+			bitcoinDepositTests = append(bitcoinDepositTests,
+				e2etests.TestBitcoinDepositAndCallRevertWithDustName)
+		}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 495235e and a0afb1e.

📒 Files selected for processing (6)
  • cmd/zetae2e/local/local.go (4 hunks)
  • contrib/localnet/orchestrator/start-zetae2e.sh (1 hunks)
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go (1 hunks)
  • e2e/e2etests/test_crosschain_swap.go (1 hunks)
  • e2e/e2etests/test_v2_deposit_and_call_swap.go (1 hunks)
  • e2e/e2etests/test_zrc20_swap.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
🧰 Additional context used
📓 Path-based instructions (5)
cmd/zetae2e/local/local.go (1)

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

contrib/localnet/orchestrator/start-zetae2e.sh (1)

Pattern **/*.sh: Review the shell scripts, point out issues relative to security, performance, and maintainability.

e2e/e2etests/test_crosschain_swap.go (1)

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

e2e/e2etests/test_v2_deposit_and_call_swap.go (1)

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

e2e/e2etests/test_zrc20_swap.go (1)

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

🔇 Additional comments (2)
cmd/zetae2e/local/local.go (2)

28-50: LGTM! Flag constant follows established patterns.

The new flag constant flagSkipBitcoinDustWithdraw is well-placed and follows the existing naming conventions.


100-121: LGTM! Consistent flag value retrieval.

The flag value is retrieved using the must helper, maintaining consistency with other flag retrievals in the file.

e2e/e2etests/test_zrc20_swap.go Show resolved Hide resolved
e2e/e2etests/test_v2_deposit_and_call_swap.go Show resolved Hide resolved
e2e/e2etests/test_crosschain_swap.go Show resolved Hide resolved
@lumtis lumtis added the UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light label Nov 22, 2024
@lumtis
Copy link
Member

lumtis commented Nov 22, 2024

We should not introduce a flag and make cli more complex for just an edge case

@lumtis
Copy link
Member

lumtis commented Nov 22, 2024

Removed the flag, we already have the light flag pattern for test to not run in previous version and should reuse this

@lumtis lumtis added this pull request to the merge queue Nov 22, 2024
Merged via the queue into develop with commit eaacc09 Nov 22, 2024
41 checks passed
@lumtis lumtis deleted the fix-upgrade-test branch November 22, 2024 10:06
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 UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light UPGRADE_TESTS Run make start-upgrade-tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants