From 4c22ffaa9131273b74f782a9d30b01ba8816680e Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 6 Dec 2024 16:13:02 +0100 Subject: [PATCH] switch v2 with legacy --- .github/workflows/e2e.yml | 14 +- Makefile | 6 +- cmd/zetae2e/local/bitcoin.go | 4 +- cmd/zetae2e/local/evm.go | 2 + cmd/zetae2e/local/legacy.go | 53 +++++++ cmd/zetae2e/local/local.go | 147 ++++++++---------- cmd/zetae2e/local/zeta.go | 64 -------- e2e/e2etests/e2etests.go | 117 +++++++------- .../{ => legacy}/test_zeta_deposit.go | 2 +- .../test_zeta_deposit_new_address.go | 2 +- .../test_zeta_deposit_restricted_address.go | 2 +- .../{ => legacy}/test_zeta_withdraw.go | 2 +- .../test_zeta_withdraw_bitcoin_revert.go | 2 +- e2e/e2etests/test_migrate_chain_support.go | 2 +- e2e/e2etests/test_zrc20_swap.go | 89 ----------- 15 files changed, 191 insertions(+), 317 deletions(-) rename e2e/e2etests/{ => legacy}/test_zeta_deposit.go (96%) rename e2e/e2etests/{ => legacy}/test_zeta_deposit_new_address.go (97%) rename e2e/e2etests/{ => legacy}/test_zeta_deposit_restricted_address.go (97%) rename e2e/e2etests/{ => legacy}/test_zeta_withdraw.go (97%) rename e2e/e2etests/{ => legacy}/test_zeta_withdraw_bitcoin_revert.go (99%) delete mode 100644 e2e/e2etests/test_zrc20_swap.go diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ce1cb33e53..8e4e5adcf6 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -120,7 +120,7 @@ jobs: TSS_MIGRATION_TESTS: ${{ steps.matrix-conditionals.outputs.TSS_MIGRATION_TESTS }} SOLANA_TESTS: ${{ steps.matrix-conditionals.outputs.SOLANA_TESTS }} TON_TESTS: ${{ steps.matrix-conditionals.outputs.TON_TESTS }} - V2_TESTS: ${{ steps.matrix-conditionals.outputs.V2_TESTS }} + LEGACY_TESTS: ${{ steps.matrix-conditionals.outputs.LEGACY_TESTS }} ENABLE_MONITORING: ${{ steps.matrix-conditionals.outputs.ENABLE_MONITORING }} steps: # use api rather than event context to avoid race conditions (label added after push) @@ -152,7 +152,7 @@ jobs: core.setOutput('TSS_MIGRATION_TESTS', labels.includes('TSS_MIGRATION_TESTS')); core.setOutput('SOLANA_TESTS', labels.includes('SOLANA_TESTS')); core.setOutput('TON_TESTS', labels.includes('TON_TESTS')); - core.setOutput('V2_TESTS', labels.includes('V2_TESTS')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627) + core.setOutput('LEGACY_TESTS', labels.includes('LEGACY_TESTS')); core.setOutput('ENABLE_MONITORING', labels.includes('ENABLE_MONITORING')); } else if (context.eventName === 'merge_group') { // default mergequeue tests @@ -181,7 +181,7 @@ jobs: core.setOutput('STATEFUL_DATA_TESTS', true); core.setOutput('SOLANA_TESTS', true); core.setOutput('TON_TESTS', true); - core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627) + core.setOutput('LEGACY_TESTS', true); } else if (context.eventName === 'schedule') { core.setOutput('DEFAULT_TESTS', true); core.setOutput('UPGRADE_TESTS', true); @@ -193,7 +193,7 @@ jobs: core.setOutput('TSS_MIGRATION_TESTS', true); core.setOutput('SOLANA_TESTS', true); core.setOutput('TON_TESTS', true); - core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627) + core.setOutput('LEGACY_TESTS', true); } else if (context.eventName === 'workflow_dispatch') { const makeTargets = context.payload.inputs['make-targets'].split(','); core.setOutput('DEFAULT_TESTS', makeTargets.includes('default-test')); @@ -206,7 +206,7 @@ jobs: core.setOutput('TSS_MIGRATION_TESTS', makeTargets.includes('tss-migration-test')); core.setOutput('SOLANA_TESTS', makeTargets.includes('solana-test')); core.setOutput('TON_TESTS', makeTargets.includes('ton-test')); - core.setOutput('V2_TESTS', makeTargets.includes('v2-test')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627) + core.setOutput('LEGACY_TESTS', makeTargets.includes('legacy-test')); core.setOutput('ENABLE_MONITORING', context.payload.inputs['enable-monitoring']); } @@ -255,9 +255,9 @@ jobs: - make-target: "start-ton-test" runs-on: ubuntu-20.04 run: ${{ needs.matrix-conditionals.outputs.TON_TESTS == 'true' }} - - make-target: "start-v2-test" + - make-target: "start-legacy-test" runs-on: ubuntu-20.04 - run: ${{ needs.matrix-conditionals.outputs.V2_TESTS == 'true' }} + run: ${{ needs.matrix-conditionals.outputs.LEGACY_TESTS == 'true' }} name: ${{ matrix.make-target }} uses: ./.github/workflows/reusable-e2e.yml with: diff --git a/Makefile b/Makefile index 833f1d4590..82e9c89a0a 100644 --- a/Makefile +++ b/Makefile @@ -312,9 +312,9 @@ start-ton-test: e2e-images export E2E_ARGS="--skip-regular --test-ton" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile ton up -d -start-v2-test: e2e-images - @echo "--> Starting e2e smart contracts v2 test" - export E2E_ARGS="--skip-regular --test-v2" && \ +start-legacy-test: e2e-images + @echo "--> Starting e2e smart contracts legacy test" + export E2E_ARGS="--skip-regular --test-legacy" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) up -d ############################################################################### diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index 900c9c3792..532fb2a84a 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -13,8 +13,8 @@ import ( "github.com/zeta-chain/node/testutil" ) -// initBitcoinTestRunners initializes Bitcoin deposit and withdraw test runners -func initBitcoinTestRunners( +// bitcoinTestRoutines returns test routines for deposit and withdraw tests +func bitcoinTestRoutines( conf config.Config, deployerRunner *runner.E2ERunner, verbose bool, diff --git a/cmd/zetae2e/local/evm.go b/cmd/zetae2e/local/evm.go index e937aec974..249576c753 100644 --- a/cmd/zetae2e/local/evm.go +++ b/cmd/zetae2e/local/evm.go @@ -28,6 +28,7 @@ func startEVMTests(eg *errgroup.Group, conf config.Config, deployerRunner *runne e2etests.TestEVMToZEVMCallName, e2etests.TestETHDepositAndCallNoMessageName, e2etests.TestETHWithdrawAndCallNoMessageName, + e2etests.TestEtherWithdrawRestrictedName, // to change to use v2 )) // Test happy paths for erc20 token workflow @@ -41,6 +42,7 @@ func startEVMTests(eg *errgroup.Group, conf config.Config, deployerRunner *runne e2etests.TestERC20DepositAndCallNoMessageName, e2etests.TestERC20WithdrawAndCallNoMessageName, e2etests.TestDepositAndCallSwapName, + e2etests.TestERC20DepositRestrictedName, // to change to use v2 )) // Test revert cases for gas token workflow diff --git a/cmd/zetae2e/local/legacy.go b/cmd/zetae2e/local/legacy.go index b83225ad0c..174c1e5794 100644 --- a/cmd/zetae2e/local/legacy.go +++ b/cmd/zetae2e/local/legacy.go @@ -165,3 +165,56 @@ func legacyZEVMMPTestRoutine( return err } } + +// legacyZETATestRoutine runs Zeta transfer and message passing related e2e tests +func legacyZETATestRoutine( + conf config.Config, + deployerRunner *runner.E2ERunner, + verbose bool, + testNames ...string, +) func() error { + return func() (err error) { + account := conf.AdditionalAccounts.UserZetaTest + // initialize runner for zeta test + zetaRunner, err := initTestRunner( + "zeta", + conf, + deployerRunner, + account, + runner.NewLogger(verbose, color.FgBlue, "zeta"), + ) + if err != nil { + return err + } + + zetaRunner.Logger.Print("🏃 starting Zeta tests") + startTime := time.Now() + + // funding the account + txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) + zetaRunner.WaitForTxReceiptOnEvm(txZetaSend) + + // depositing the necessary tokens on ZetaChain + txZetaDeposit := zetaRunner.DepositZeta() + txEtherDeposit := zetaRunner.DepositEther() + zetaRunner.WaitForMinedCCTX(txZetaDeposit) + zetaRunner.WaitForMinedCCTX(txEtherDeposit) + + // run zeta test + testsToRun, err := zetaRunner.GetE2ETestsToRunByName( + e2etests.AllE2ETests, + testNames..., + ) + if err != nil { + return fmt.Errorf("zeta tests failed: %v", err) + } + + if err := zetaRunner.RunE2ETests(testsToRun); err != nil { + return fmt.Errorf("zeta tests failed: %v", err) + } + + zetaRunner.Logger.Print("🍾 Zeta tests completed in %s", time.Since(startTime).String()) + + return err + } +} diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 05bf34586d..26b3775a85 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -41,7 +41,7 @@ const ( flagTestTSSMigration = "test-tss-migration" flagSkipBitcoinSetup = "skip-bitcoin-setup" flagSkipHeaderProof = "skip-header-proof" - flagTestV2 = "test-v2" + flagTestLegacy = "test-legacy" flagSkipTrackerCheck = "skip-tracker-check" flagSkipPrecompiles = "skip-precompiles" flagUpgradeContracts = "upgrade-contracts" @@ -77,7 +77,7 @@ func NewLocalCmd() *cobra.Command { cmd.Flags().Bool(flagSkipBitcoinSetup, false, "set to true to skip bitcoin wallet setup") cmd.Flags().Bool(flagSkipHeaderProof, false, "set to true to skip header proof tests") cmd.Flags().Bool(flagTestTSSMigration, false, "set to true to include a migration test at the end") - cmd.Flags().Bool(flagTestV2, false, "set to true to run tests for v2 contracts") + cmd.Flags().Bool(flagTestLegacy, false, "set to true to run legacy EVM tests") cmd.Flags().Bool(flagSkipTrackerCheck, false, "set to true to skip tracker check at the end of the tests") cmd.Flags().Bool(flagSkipPrecompiles, false, "set to true to skip stateful precompiled contracts test") cmd.Flags(). @@ -107,7 +107,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { skipHeaderProof = must(cmd.Flags().GetBool(flagSkipHeaderProof)) skipTrackerCheck = must(cmd.Flags().GetBool(flagSkipTrackerCheck)) testTSSMigration = must(cmd.Flags().GetBool(flagTestTSSMigration)) - testV2 = must(cmd.Flags().GetBool(flagTestV2)) + testLegacy = must(cmd.Flags().GetBool(flagTestLegacy)) skipPrecompiles = must(cmd.Flags().GetBool(flagSkipPrecompiles)) upgradeContracts = must(cmd.Flags().GetBool(flagUpgradeContracts)) ) @@ -278,41 +278,18 @@ func localE2ETest(cmd *cobra.Command, _ []string) { os.Exit(0) } + if upgradeContracts { + deployerRunner.UpgradeGatewaysAndERC20Custody() + } + // run tests var eg errgroup.Group if !skipRegular { - // defines all tests, if light is enabled, only the most basic tests are run and advanced are skipped - erc20Tests := []string{ - e2etests.TestLegacyERC20WithdrawName, - e2etests.TestLegacyMultipleERC20WithdrawsName, - e2etests.TestLegacyERC20DepositAndCallRefundName, - e2etests.TestZRC20SwapName, - } - erc20AdvancedTests := []string{ - e2etests.TestERC20DepositRestrictedName, - } - zetaTests := []string{ - e2etests.TestZetaWithdrawName, - e2etests.TestLegacyMessagePassingExternalChainsName, - e2etests.TestLegacyMessagePassingRevertFailExternalChainsName, - e2etests.TestLegacyMessagePassingRevertSuccessExternalChainsName, - } - zetaAdvancedTests := []string{ - e2etests.TestZetaDepositRestrictedName, - e2etests.TestZetaDepositName, - e2etests.TestZetaDepositNewAddressName, - } - zevmMPTests := []string{} - zevmMPAdvancedTests := []string{ - e2etests.TestLegacyMessagePassingZEVMToEVMName, - e2etests.TestLegacyMessagePassingEVMtoZEVMName, - e2etests.TestLegacyMessagePassingEVMtoZEVMRevertName, - e2etests.TestLegacyMessagePassingZEVMtoEVMRevertName, - e2etests.TestLegacyMessagePassingZEVMtoEVMRevertFailName, - e2etests.TestLegacyMessagePassingEVMtoZEVMRevertFailName, - } + // start the EVM tests + startEVMTests(&eg, conf, deployerRunner, verbose) + // start the bitcoin tests // btc withdraw tests are those that need a Bitcoin node wallet to send UTXOs bitcoinDepositTests := []string{ e2etests.TestBitcoinDonationName, @@ -332,7 +309,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { bitcoinWithdrawTests := []string{ e2etests.TestBitcoinWithdrawSegWitName, e2etests.TestBitcoinWithdrawInvalidAddressName, - e2etests.TestZetaWithdrawBTCRevertName, + e2etests.TestLegacyZetaWithdrawBTCRevertName, } bitcoinWithdrawTestsAdvanced := []string{ e2etests.TestBitcoinWithdrawTaprootName, @@ -342,46 +319,12 @@ func localE2ETest(cmd *cobra.Command, _ []string) { e2etests.TestBitcoinWithdrawMultipleName, e2etests.TestBitcoinWithdrawRestrictedName, } - ethereumTests := []string{ - e2etests.TestLegacyEtherWithdrawName, - e2etests.TestLegacyEtherDepositAndCallName, - e2etests.TestLegacyEtherDepositAndCallRefundName, - } - ethereumAdvancedTests := []string{ - e2etests.TestEtherWithdrawRestrictedName, - } - precompiledContractTests := []string{} - - if !skipPrecompiles { - precompiledContractTests = []string{ - e2etests.TestPrecompilesPrototypeName, - e2etests.TestPrecompilesPrototypeThroughContractName, - e2etests.TestPrecompilesStakingName, - // Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005. - // e2etests.TestPrecompilesStakingThroughContractName, - e2etests.TestPrecompilesBankName, - e2etests.TestPrecompilesBankFailName, - e2etests.TestPrecompilesBankThroughContractName, - e2etests.TestPrecompilesDistributeName, - e2etests.TestPrecompilesDistributeNonZRC20Name, - e2etests.TestPrecompilesDistributeThroughContractName, - } - } - if !light { - erc20Tests = append(erc20Tests, erc20AdvancedTests...) - zetaTests = append(zetaTests, zetaAdvancedTests...) - zevmMPTests = append(zevmMPTests, zevmMPAdvancedTests...) + // if light is enabled, only the most basic tests are run and advanced are skipped bitcoinDepositTests = append(bitcoinDepositTests, bitcoinDepositTestsAdvanced...) bitcoinWithdrawTests = append(bitcoinWithdrawTests, bitcoinWithdrawTestsAdvanced...) - ethereumTests = append(ethereumTests, ethereumAdvancedTests...) } - - eg.Go(statefulPrecompilesTestRoutine(conf, deployerRunner, verbose, precompiledContractTests...)) - eg.Go(legacyERC20TestRoutine(conf, deployerRunner, verbose, erc20Tests...)) - eg.Go(zetaTestRoutine(conf, deployerRunner, verbose, zetaTests...)) - eg.Go(legacyZEVMMPTestRoutine(conf, deployerRunner, verbose, zevmMPTests...)) - runnerDeposit, runnerWithdraw := initBitcoinTestRunners( + bitcoinDepositTestRoutine, bitcoinWithdrawTestRoutine := bitcoinTestRoutines( conf, deployerRunner, verbose, @@ -389,9 +332,24 @@ func localE2ETest(cmd *cobra.Command, _ []string) { bitcoinDepositTests, bitcoinWithdrawTests, ) - eg.Go(runnerDeposit) - eg.Go(runnerWithdraw) - eg.Go(legacyEthereumTestRoutine(conf, deployerRunner, verbose, ethereumTests...)) + eg.Go(bitcoinDepositTestRoutine) + eg.Go(bitcoinWithdrawTestRoutine) + } + + if !skipPrecompiles { + eg.Go(statefulPrecompilesTestRoutine(conf, deployerRunner, verbose, + e2etests.TestPrecompilesPrototypeName, + e2etests.TestPrecompilesPrototypeThroughContractName, + e2etests.TestPrecompilesStakingName, + // Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005. + // e2etests.TestPrecompilesStakingThroughContractName, + e2etests.TestPrecompilesBankName, + e2etests.TestPrecompilesBankFailName, + e2etests.TestPrecompilesBankThroughContractName, + e2etests.TestPrecompilesDistributeName, + e2etests.TestPrecompilesDistributeNonZRC20Name, + e2etests.TestPrecompilesDistributeThroughContractName, + )) } if testAdmin { @@ -405,23 +363,19 @@ func localE2ETest(cmd *cobra.Command, _ []string) { e2etests.TestPauseERC20CustodyName, e2etests.TestMigrateERC20CustodyFundsName, - // Test the rate limiter functionalities - // this test is currently incomplete and takes 10m to run - // TODO: define assertion, and make more optimized - // https://github.com/zeta-chain/node/issues/2090 - //e2etests.TestRateLimiterName, - - // TestMigrateChainSupportName tests EVM chain migration. Currently this test doesn't work with Anvil because pre-EIP1559 txs are not supported + // Currently this test doesn't work with Anvil because pre-EIP1559 txs are not supported // See issue below for details // TODO: reenable this test as per the issue below // https://github.com/zeta-chain/node/issues/1980 // e2etests.TestMigrateChainSupportName, )) } + if testPerformance { eg.Go(ethereumDepositPerformanceRoutine(conf, deployerRunner, verbose, e2etests.TestStressEtherDepositName)) eg.Go(ethereumWithdrawPerformanceRoutine(conf, deployerRunner, verbose, e2etests.TestStressEtherWithdrawName)) } + if testSolana { if deployerRunner.SolanaClient == nil { logger.Print("❌ solana client is nil, maybe solana rpc is not set") @@ -463,12 +417,33 @@ func localE2ETest(cmd *cobra.Command, _ []string) { eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...)) } - if upgradeContracts { - deployerRunner.UpgradeGatewaysAndERC20Custody() - } - - if testV2 { - startEVMTests(&eg, conf, deployerRunner, verbose) + if testLegacy { + eg.Go(legacyERC20TestRoutine(conf, deployerRunner, verbose, + e2etests.TestLegacyERC20WithdrawName, + e2etests.TestLegacyMultipleERC20WithdrawsName, + e2etests.TestLegacyERC20DepositAndCallRefundName)) + eg.Go(legacyZETATestRoutine(conf, deployerRunner, verbose, + e2etests.TestLegacyZetaWithdrawName, + e2etests.TestLegacyMessagePassingExternalChainsName, + e2etests.TestLegacyMessagePassingRevertFailExternalChainsName, + e2etests.TestLegacyMessagePassingRevertSuccessExternalChainsName, + e2etests.TestLegacyZetaDepositRestrictedName, + e2etests.TestLegacyZetaDepositName, + e2etests.TestLegacyZetaDepositNewAddressName, + )) + eg.Go(legacyZEVMMPTestRoutine(conf, deployerRunner, verbose, + e2etests.TestLegacyMessagePassingZEVMToEVMName, + e2etests.TestLegacyMessagePassingEVMtoZEVMName, + e2etests.TestLegacyMessagePassingEVMtoZEVMRevertName, + e2etests.TestLegacyMessagePassingZEVMtoEVMRevertName, + e2etests.TestLegacyMessagePassingZEVMtoEVMRevertFailName, + e2etests.TestLegacyMessagePassingEVMtoZEVMRevertFailName, + )) + eg.Go(legacyEthereumTestRoutine(conf, deployerRunner, verbose, + e2etests.TestLegacyEtherWithdrawName, + e2etests.TestLegacyEtherDepositAndCallName, + e2etests.TestLegacyEtherDepositAndCallRefundName, + )) } // while tests are executed, monitor blocks in parallel to check if system txs are on top and they have biggest priority diff --git a/cmd/zetae2e/local/zeta.go b/cmd/zetae2e/local/zeta.go index c361876948..469c3dc0d8 100644 --- a/cmd/zetae2e/local/zeta.go +++ b/cmd/zetae2e/local/zeta.go @@ -1,65 +1 @@ package local - -import ( - "fmt" - "time" - - "github.com/fatih/color" - - "github.com/zeta-chain/node/e2e/config" - "github.com/zeta-chain/node/e2e/e2etests" - "github.com/zeta-chain/node/e2e/runner" -) - -// zetaTestRoutine runs Zeta transfer and message passing related e2e tests -func zetaTestRoutine( - conf config.Config, - deployerRunner *runner.E2ERunner, - verbose bool, - testNames ...string, -) func() error { - return func() (err error) { - account := conf.AdditionalAccounts.UserZetaTest - // initialize runner for zeta test - zetaRunner, err := initTestRunner( - "zeta", - conf, - deployerRunner, - account, - runner.NewLogger(verbose, color.FgBlue, "zeta"), - ) - if err != nil { - return err - } - - zetaRunner.Logger.Print("🏃 starting Zeta tests") - startTime := time.Now() - - // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) - zetaRunner.WaitForTxReceiptOnEvm(txZetaSend) - - // depositing the necessary tokens on ZetaChain - txZetaDeposit := zetaRunner.DepositZeta() - txEtherDeposit := zetaRunner.DepositEther() - zetaRunner.WaitForMinedCCTX(txZetaDeposit) - zetaRunner.WaitForMinedCCTX(txEtherDeposit) - - // run zeta test - testsToRun, err := zetaRunner.GetE2ETestsToRunByName( - e2etests.AllE2ETests, - testNames..., - ) - if err != nil { - return fmt.Errorf("zeta tests failed: %v", err) - } - - if err := zetaRunner.RunE2ETests(testsToRun); err != nil { - return fmt.Errorf("zeta tests failed: %v", err) - } - - zetaRunner.Logger.Print("🍾 Zeta tests completed in %s", time.Since(startTime).String()) - - return err - } -} diff --git a/e2e/e2etests/e2etests.go b/e2e/e2etests/e2etests.go index f60fb60904..a8da23104a 100644 --- a/e2e/e2etests/e2etests.go +++ b/e2e/e2etests/e2etests.go @@ -43,16 +43,6 @@ const ( TestEtherWithdrawRestrictedName = "eth_withdraw_restricted" TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential - /* - ZETA tests - Test transfer of ZETA asset across chains - */ - TestZetaDepositName = "zeta_deposit" - TestZetaDepositNewAddressName = "zeta_deposit_new_address" - TestZetaDepositRestrictedName = "zeta_deposit_restricted" - TestZetaWithdrawName = "zeta_withdraw" - TestZetaWithdrawBTCRevertName = "zeta_withdraw_btc_revert" // #nosec G101 - not a hardcoded password - /* * Solana tests */ @@ -104,7 +94,6 @@ const ( Application tests Test various smart contract applications across chains */ - TestZRC20SwapName = "zrc20_swap" TestCrosschainSwapName = "crosschain_swap" /* @@ -183,6 +172,19 @@ const ( TestLegacyMultipleERC20DepositName = "legacy_erc20_multiple_deposit" TestLegacyMultipleERC20WithdrawsName = "legacy_erc20_multiple_withdraw" TestLegacyERC20DepositAndCallRefundName = "legacy_erc20_deposit_and_call_refund" + + /* + ZETA tests + Test transfer of ZETA asset across chains + Note: It is still the only way to transfer ZETA across chains. Work to integrate ZETA transfers as part of the gateway is in progress + These tests are marked as legacy because there is no longer active development on ZETA transfers, and we stopped integrating ZETA support on new mainnet chains + */ + TestLegacyZetaDepositName = "legacy_zeta_deposit" + TestLegacyZetaDepositNewAddressName = "legacy_zeta_deposit_new_address" + TestLegacyZetaDepositRestrictedName = "legacy_zeta_deposit_restricted" + TestLegacyZetaWithdrawName = "legacy_zeta_withdraw" + TestLegacyZetaWithdrawBTCRevertName = "legacy_zeta_withdraw_btc_revert" // #nosec G101 - not a hardcoded password + ) // AllE2ETests is an ordered list of all e2e tests @@ -412,49 +414,6 @@ var AllE2ETests = []runner.E2ETest{ []runner.ArgDefinition{}, TestV2DepositAndCallSwap, ), - /* - ZETA tests - */ - runner.NewE2ETest( - TestZetaDepositName, - "deposit ZETA from Ethereum to ZEVM", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaDeposit, - ), - runner.NewE2ETest( - TestZetaDepositNewAddressName, - "deposit ZETA from Ethereum to a new ZEVM address which does not exist yet", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaDepositNewAddress, - ), - runner.NewE2ETest( - TestZetaDepositRestrictedName, - "deposit ZETA from Ethereum to ZEVM restricted address", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaDepositRestricted, - ), - runner.NewE2ETest( - TestZetaWithdrawName, - "withdraw ZETA from ZEVM to Ethereum", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, - }, - TestZetaWithdraw, - ), - runner.NewE2ETest( - TestZetaWithdrawBTCRevertName, - "sending ZETA from ZEVM to Bitcoin with a message that should revert cctxs", - []runner.ArgDefinition{ - {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, - }, - TestZetaWithdrawBTCRevert, - ), /* Solana tests @@ -746,12 +705,6 @@ var AllE2ETests = []runner.E2ETest{ /* Application tests */ - runner.NewE2ETest( - TestZRC20SwapName, - "swap ZRC20 ERC20 for ZRC20 ETH", - []runner.ArgDefinition{}, - TestZRC20Swap, - ), runner.NewE2ETest( TestCrosschainSwapName, "testing Bitcoin ERC20 cross-chain swap", @@ -1142,4 +1095,48 @@ var AllE2ETests = []runner.E2ETest{ []runner.ArgDefinition{}, legacy.TestERC20DepositAndCallRefund, ), + + /* + ZETA tests + */ + runner.NewE2ETest( + TestLegacyZetaDepositName, + "deposit ZETA from Ethereum to ZEVM", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + legacy.TestZetaDeposit, + ), + runner.NewE2ETest( + TestLegacyZetaDepositNewAddressName, + "deposit ZETA from Ethereum to a new ZEVM address which does not exist yet", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + legacy.TestZetaDepositNewAddress, + ), + runner.NewE2ETest( + TestLegacyZetaDepositRestrictedName, + "deposit ZETA from Ethereum to ZEVM restricted address", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + legacy.TestZetaDepositRestricted, + ), + runner.NewE2ETest( + TestLegacyZetaWithdrawName, + "withdraw ZETA from ZEVM to Ethereum", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "10000000000000000000"}, + }, + legacy.TestZetaWithdraw, + ), + runner.NewE2ETest( + TestLegacyZetaWithdrawBTCRevertName, + "sending ZETA from ZEVM to Bitcoin with a message that should revert cctxs", + []runner.ArgDefinition{ + {Description: "amount in azeta", DefaultValue: "1000000000000000000"}, + }, + legacy.TestZetaWithdrawBTCRevert, + ), } diff --git a/e2e/e2etests/test_zeta_deposit.go b/e2e/e2etests/legacy/test_zeta_deposit.go similarity index 96% rename from e2e/e2etests/test_zeta_deposit.go rename to e2e/e2etests/legacy/test_zeta_deposit.go index ddb6c5ef83..c78984a5ce 100644 --- a/e2e/e2etests/test_zeta_deposit.go +++ b/e2e/e2etests/legacy/test_zeta_deposit.go @@ -1,4 +1,4 @@ -package e2etests +package legacy import ( "github.com/stretchr/testify/require" diff --git a/e2e/e2etests/test_zeta_deposit_new_address.go b/e2e/e2etests/legacy/test_zeta_deposit_new_address.go similarity index 97% rename from e2e/e2etests/test_zeta_deposit_new_address.go rename to e2e/e2etests/legacy/test_zeta_deposit_new_address.go index 5c62f9b829..86772672d5 100644 --- a/e2e/e2etests/test_zeta_deposit_new_address.go +++ b/e2e/e2etests/legacy/test_zeta_deposit_new_address.go @@ -1,4 +1,4 @@ -package e2etests +package legacy import ( "github.com/stretchr/testify/require" diff --git a/e2e/e2etests/test_zeta_deposit_restricted_address.go b/e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go similarity index 97% rename from e2e/e2etests/test_zeta_deposit_restricted_address.go rename to e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go index 7915630be6..ff8bc30db0 100644 --- a/e2e/e2etests/test_zeta_deposit_restricted_address.go +++ b/e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go @@ -1,4 +1,4 @@ -package e2etests +package legacy import ( ethcommon "github.com/ethereum/go-ethereum/common" diff --git a/e2e/e2etests/test_zeta_withdraw.go b/e2e/e2etests/legacy/test_zeta_withdraw.go similarity index 97% rename from e2e/e2etests/test_zeta_withdraw.go rename to e2e/e2etests/legacy/test_zeta_withdraw.go index 755bacc51e..3ac2fe91c8 100644 --- a/e2e/e2etests/test_zeta_withdraw.go +++ b/e2e/e2etests/legacy/test_zeta_withdraw.go @@ -1,4 +1,4 @@ -package e2etests +package legacy import ( "github.com/stretchr/testify/require" diff --git a/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go b/e2e/e2etests/legacy/test_zeta_withdraw_bitcoin_revert.go similarity index 99% rename from e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go rename to e2e/e2etests/legacy/test_zeta_withdraw_bitcoin_revert.go index c4896bd8fd..88504a87c4 100644 --- a/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go +++ b/e2e/e2etests/legacy/test_zeta_withdraw_bitcoin_revert.go @@ -1,4 +1,4 @@ -package e2etests +package legacy import ( "math/big" diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 4a0a25825e..5f74ef2db9 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -151,7 +151,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { legacy.TestEtherWithdraw(newRunner, []string{"50000000000000000"}) // finally try to deposit Zeta back - TestZetaDeposit(newRunner, []string{"100000000000000000"}) + legacy.TestZetaDeposit(newRunner, []string{"100000000000000000"}) // ERC20 test diff --git a/e2e/e2etests/test_zrc20_swap.go b/e2e/e2etests/test_zrc20_swap.go deleted file mode 100644 index dcf1a312c2..0000000000 --- a/e2e/e2etests/test_zrc20_swap.go +++ /dev/null @@ -1,89 +0,0 @@ -package e2etests - -import ( - "math/big" - "time" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" - - "github.com/zeta-chain/node/e2e/runner" - "github.com/zeta-chain/node/e2e/utils" -) - -func TestZRC20Swap(r *runner.E2ERunner, _ []string) { - // TODO: move into setup and skip it if already initialized - // https://github.com/zeta-chain/node-private/issues/88 - // it is kept as is for now to be consistent with the old implementation - // if the tx fails due to already initialized, it will be ignored - tx, err := r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.ETHZRC20Addr) - if err != nil { - r.Logger.Print("ℹī¸ create pair error %s", err.Error()) - } else { - utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - } - - zrc20EthPair, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.ERC20ZRC20Addr, r.ETHZRC20Addr) - require.NoError(r, err) - - r.Logger.Info("ZRC20-ETH pair receipt pair addr %s", zrc20EthPair.Hex()) - - tx, err = r.ERC20ZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e18)) - require.NoError(r, err) - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.Info("ERC20 ZRC20 approval receipt txhash %s status %d", receipt.TxHash, receipt.Status) - - tx, err = r.ETHZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e18)) - require.NoError(r, err) - - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.Info("ETH ZRC20 approval receipt txhash %s status %d", receipt.TxHash, receipt.Status) - - // temporarily increase gas limit to 400000 - previousGasLimit := r.ZEVMAuth.GasLimit - defer func() { - r.ZEVMAuth.GasLimit = previousGasLimit - }() - - r.ZEVMAuth.GasLimit = 400000 - tx, err = r.UniswapV2Router.AddLiquidity( - r.ZEVMAuth, - r.ERC20ZRC20Addr, - r.ETHZRC20Addr, - big.NewInt(90000), - big.NewInt(1000), - big.NewInt(90000), - big.NewInt(1000), - r.EVMAddress(), - big.NewInt(time.Now().Add(10*time.Minute).Unix()), - ) - require.NoError(r, err) - - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.Info("Add liquidity receipt txhash %s status %d", receipt.TxHash, receipt.Status) - - balETHBefore, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) - require.NoError(r, err) - - ethOutAmout := big.NewInt(1) - tx, err = r.UniswapV2Router.SwapExactTokensForTokens( - r.ZEVMAuth, - big.NewInt(1000), - ethOutAmout, - []ethcommon.Address{r.ERC20ZRC20Addr, r.ETHZRC20Addr}, - r.EVMAddress(), - big.NewInt(time.Now().Add(10*time.Minute).Unix()), - ) - require.NoError(r, err) - - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.Info("Swap ERC20 ZRC20 for ETH ZRC20 %s status %d", receipt.TxHash, receipt.Status) - - balETHAfter, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) - require.NoError(r, err) - - ethDiff := big.NewInt(0).Sub(balETHAfter, balETHBefore) - require.NotEqual(r, -1, ethDiff.Cmp(ethOutAmout), "swap failed") -}