diff --git a/cmd/zetae2e/local/admin.go b/cmd/zetae2e/local/admin.go index d81e6ac46c..2697273346 100644 --- a/cmd/zetae2e/local/admin.go +++ b/cmd/zetae2e/local/admin.go @@ -38,15 +38,15 @@ func adminTestRoutine( // funding the account // we transfer around the total supply of Zeta to the admin for the chain migration test - txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 20_500_000_000) - txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000) - adminRunner.WaitForTxReceiptOnEvm(txZetaSend) - adminRunner.WaitForTxReceiptOnEvm(txERC20Send) + txZetaSend := deployerRunner.LegacySendZetaOnEvm(account.EVMAddress(), 20_500_000_000) + txERC20Send := deployerRunner.SendERC20OnEVM(account.EVMAddress(), 1000) + adminRunner.WaitForTxReceiptOnEVM(txZetaSend) + adminRunner.WaitForTxReceiptOnEVM(txERC20Send) // depositing the necessary tokens on ZetaChain - txZetaDeposit := adminRunner.DepositZeta() - txEtherDeposit := adminRunner.DepositEther() - txERC20Deposit := adminRunner.DepositERC20() + txZetaDeposit := adminRunner.LegacyDepositZeta() + txEtherDeposit := adminRunner.LegacyDepositEther() + txERC20Deposit := adminRunner.LegacyDepositERC20() adminRunner.WaitForMinedCCTX(txZetaDeposit) adminRunner.WaitForMinedCCTX(txEtherDeposit) adminRunner.WaitForMinedCCTX(txERC20Deposit) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index 532fb2a84a..c11b00494c 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -93,12 +93,12 @@ func initBitcoinRunner( require.NoError(runner, err) // send ERC20 token on EVM - txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000) - runner.WaitForTxReceiptOnEvm(txERC20Send) + txERC20Send := deployerRunner.SendERC20OnEVM(account.EVMAddress(), 1000) + runner.WaitForTxReceiptOnEVM(txERC20Send) // deposit ETH and ERC20 tokens on ZetaChain - txEtherDeposit := runner.DepositEther() - txERC20Deposit := runner.DepositERC20() + txEtherDeposit := runner.LegacyDepositEther() + txERC20Deposit := runner.LegacyDepositERC20() runner.WaitForMinedCCTX(txEtherDeposit) runner.WaitForMinedCCTX(txERC20Deposit) diff --git a/cmd/zetae2e/local/evm.go b/cmd/zetae2e/local/evm.go index 249576c753..851366da95 100644 --- a/cmd/zetae2e/local/evm.go +++ b/cmd/zetae2e/local/evm.go @@ -114,8 +114,8 @@ func evmTestRoutine( startTime := time.Now() // funding the account - txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10000) - v2Runner.WaitForTxReceiptOnEvm(txERC20Send) + txERC20Send := deployerRunner.SendERC20OnEVM(account.EVMAddress(), 10000) + v2Runner.WaitForTxReceiptOnEVM(txERC20Send) // run erc20 test testsToRun, err := v2Runner.GetE2ETestsToRunByName( diff --git a/cmd/zetae2e/local/legacy.go b/cmd/zetae2e/local/legacy.go index 174c1e5794..338fdac7db 100644 --- a/cmd/zetae2e/local/legacy.go +++ b/cmd/zetae2e/local/legacy.go @@ -37,12 +37,12 @@ func legacyERC20TestRoutine( startTime := time.Now() // funding the account - txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10000) - erc20Runner.WaitForTxReceiptOnEvm(txERC20Send) + txERC20Send := deployerRunner.SendERC20OnEVM(account.EVMAddress(), 10000) + erc20Runner.WaitForTxReceiptOnEVM(txERC20Send) // depositing the necessary tokens on ZetaChain - txEtherDeposit := erc20Runner.DepositEther() - txERC20Deposit := erc20Runner.DepositERC20() + txEtherDeposit := erc20Runner.LegacyDepositEther() + txERC20Deposit := erc20Runner.LegacyDepositERC20() erc20Runner.WaitForMinedCCTX(txEtherDeposit) erc20Runner.WaitForMinedCCTX(txERC20Deposit) @@ -89,7 +89,7 @@ func legacyEthereumTestRoutine( startTime := time.Now() // depositing the necessary tokens on ZetaChain - txEtherDeposit := ethereumRunner.DepositEther() + txEtherDeposit := ethereumRunner.LegacyDepositEther() ethereumRunner.WaitForMinedCCTX(txEtherDeposit) // run ethereum test @@ -138,12 +138,12 @@ func legacyZEVMMPTestRoutine( startTime := time.Now() // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) - zevmMPRunner.WaitForTxReceiptOnEvm(txZetaSend) + txZetaSend := deployerRunner.LegacySendZetaOnEvm(account.EVMAddress(), 1000) + zevmMPRunner.WaitForTxReceiptOnEVM(txZetaSend) // depositing the necessary tokens on ZetaChain - txZetaDeposit := zevmMPRunner.DepositZeta() - txEtherDeposit := zevmMPRunner.DepositEther() + txZetaDeposit := zevmMPRunner.LegacyDepositZeta() + txEtherDeposit := zevmMPRunner.LegacyDepositEther() zevmMPRunner.WaitForMinedCCTX(txZetaDeposit) zevmMPRunner.WaitForMinedCCTX(txEtherDeposit) @@ -191,12 +191,12 @@ func legacyZETATestRoutine( startTime := time.Now() // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) - zetaRunner.WaitForTxReceiptOnEvm(txZetaSend) + txZetaSend := deployerRunner.LegacySendZetaOnEvm(account.EVMAddress(), 1000) + zetaRunner.WaitForTxReceiptOnEVM(txZetaSend) // depositing the necessary tokens on ZetaChain - txZetaDeposit := zetaRunner.DepositZeta() - txEtherDeposit := zetaRunner.DepositEther() + txZetaDeposit := zetaRunner.LegacyDepositZeta() + txEtherDeposit := zetaRunner.LegacyDepositEther() zetaRunner.WaitForMinedCCTX(txZetaDeposit) zetaRunner.WaitForMinedCCTX(txEtherDeposit) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 26b3775a85..67935a8230 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -220,9 +220,9 @@ func localE2ETest(cmd *cobra.Command, _ []string) { // TODO: merge v1 and v2 together // https://github.com/zeta-chain/node/issues/2627 - deployerRunner.SetupEVM(contractsDeployed, true) + deployerRunner.LegacySetupEVM(contractsDeployed, true) - deployerRunner.SetupEVMV2() + deployerRunner.SetupEVM() if testSolana { deployerRunner.SetupSolana( @@ -252,7 +252,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { deployerRunner.UpdateChainParamsV2Contracts() deployerRunner.ERC20CustodyAddr = deployerRunner.ERC20CustodyV2Addr - deployerRunner.MintERC20OnEvm(1e10) + deployerRunner.MintERC20OnEVM(1e10) logger.Print("✅ setup completed in %s", time.Since(startTime)) } diff --git a/cmd/zetae2e/local/performance.go b/cmd/zetae2e/local/performance.go index 0d3fea6e5b..c5e3c42664 100644 --- a/cmd/zetae2e/local/performance.go +++ b/cmd/zetae2e/local/performance.go @@ -86,7 +86,7 @@ func ethereumWithdrawPerformanceRoutine( startTime := time.Now() // depositing the necessary tokens on ZetaChain - txEtherDeposit := r.DepositEther() + txEtherDeposit := r.LegacyDepositEther() r.WaitForMinedCCTX(txEtherDeposit) tests, err := r.GetE2ETestsToRunByName( diff --git a/cmd/zetae2e/local/precompiles.go b/cmd/zetae2e/local/precompiles.go index 3a095115c0..d2b3a2dcbe 100644 --- a/cmd/zetae2e/local/precompiles.go +++ b/cmd/zetae2e/local/precompiles.go @@ -56,8 +56,8 @@ func statefulPrecompilesTestRoutine( startTime := time.Now() // Send ERC20 that will be depositted into ERC20ZRC20 tokens. - txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1e7) - precompileRunner.WaitForTxReceiptOnEvm(txERC20Send) + txERC20Send := deployerRunner.SendERC20OnEVM(account.EVMAddress(), 1e7) + precompileRunner.WaitForTxReceiptOnEVM(txERC20Send) testsToRun, err := precompileRunner.GetE2ETestsToRunByName( e2etests.AllE2ETests, diff --git a/cmd/zetae2e/local/tss_migration.go b/cmd/zetae2e/local/tss_migration.go index 35a9f7a580..30358dc7b4 100644 --- a/cmd/zetae2e/local/tss_migration.go +++ b/cmd/zetae2e/local/tss_migration.go @@ -55,7 +55,7 @@ func tssMigrationTestRoutine( if err := tssMigrationTestRunner.RunE2ETests(testsToRun); err != nil { return fmt.Errorf("TSS migration tests failed: %v", err) } - if err := tssMigrationTestRunner.CheckBtcTSSBalance(); err != nil { + if err := tssMigrationTestRunner.CheckBTCTSSBalance(); err != nil { return err } @@ -90,7 +90,7 @@ func TSSMigration(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbo logger.Print("❌ tss migration failed") os.Exit(1) } - deployerRunner.UpdateTssAddressForConnector() - deployerRunner.UpdateTssAddressForErc20custody() + deployerRunner.UpdateTSSAddressForConnector() + deployerRunner.UpdateTSSAddressForERC20custody() logger.Print("✅ migration completed in %s ", time.Since(migrationStartTime).String()) } diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index b2ab4a9154..2e03bf9597 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -136,7 +136,7 @@ func StressTest(cmd *cobra.Command, _ []string) { // setup TSS addresses noError(e2eTest.SetTSSAddresses()) - e2eTest.SetupEVM(stressTestArgs.contractsDeployed, true) + e2eTest.LegacySetupEVM(stressTestArgs.contractsDeployed, true) // If stress test is running on local docker environment switch stressTestArgs.network { @@ -149,8 +149,8 @@ func StressTest(cmd *cobra.Command, _ []string) { }) // deposit on ZetaChain - e2eTest.DepositEther() - e2eTest.DepositZeta() + e2eTest.LegacyDepositEther() + e2eTest.LegacyDepositZeta() case "TESTNET": ethZRC20Addr := must(e2eTest.SystemContract.GasCoinZRC20ByChainId(&bind.CallOpts{}, big.NewInt(5))) e2eTest.ETHZRC20Addr = ethZRC20Addr diff --git a/e2e/e2etests/legacy/test_erc20_deposit.go b/e2e/e2etests/legacy/test_erc20_deposit.go index 1419c8c8c8..f64a520df8 100644 --- a/e2e/e2etests/legacy/test_erc20_deposit.go +++ b/e2e/e2etests/legacy/test_erc20_deposit.go @@ -13,7 +13,7 @@ func TestERC20Deposit(r *runner.E2ERunner, args []string) { // parse the deposit amount amount := utils.ParseBigInt(r, args[0]) - hash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{}) + hash := r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{}) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, hash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/legacy/test_erc20_withdraw.go b/e2e/e2etests/legacy/test_erc20_withdraw.go index d7c24bc1a1..a95d879b57 100644 --- a/e2e/e2etests/legacy/test_erc20_withdraw.go +++ b/e2e/e2etests/legacy/test_erc20_withdraw.go @@ -24,7 +24,7 @@ func TestERC20Withdraw(r *runner.E2ERunner, args []string) { r.Logger.Info("eth zrc20 approve receipt: status %d", receipt.Status) // withdraw - tx = r.WithdrawERC20(withdrawalAmount) + tx = r.LegacyWithdrawERC20(withdrawalAmount) // verify the withdraw value cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/legacy/test_eth_deposit.go b/e2e/e2etests/legacy/test_eth_deposit.go index 8e48a8e172..cba501c177 100644 --- a/e2e/e2etests/legacy/test_eth_deposit.go +++ b/e2e/e2etests/legacy/test_eth_deposit.go @@ -14,7 +14,7 @@ func TestEtherDeposit(r *runner.E2ERunner, args []string) { // parse the deposit amount amount := utils.ParseBigInt(r, args[0]) - hash := r.DepositEtherWithAmount(amount) // in wei + hash := r.LegacyDepositEtherWithAmount(amount) // in wei // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, hash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) r.Logger.CCTX(*cctx, "deposit") diff --git a/e2e/e2etests/legacy/test_eth_withdraw.go b/e2e/e2etests/legacy/test_eth_withdraw.go index ec85ef247e..d178f0c2d3 100644 --- a/e2e/e2etests/legacy/test_eth_withdraw.go +++ b/e2e/e2etests/legacy/test_eth_withdraw.go @@ -31,7 +31,7 @@ func TestEtherWithdraw(r *runner.E2ERunner, args []string) { r.Logger.EVMReceipt(*receipt, "approve") // withdraw - tx = r.WithdrawEther(withdrawalAmount) + tx = r.LegacyWithdrawEther(withdrawalAmount) // verify the withdrawal value cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/legacy/test_rate_limiter.go b/e2e/e2etests/legacy/test_rate_limiter.go index 7a07660805..61dbbdf764 100644 --- a/e2e/e2etests/legacy/test_rate_limiter.go +++ b/e2e/e2etests/legacy/test_rate_limiter.go @@ -95,11 +95,11 @@ func createAndWaitWithdraws(r *runner.E2ERunner, withdrawType withdrawType, with // create a new withdraw depending on the type switch withdrawType { case withdrawTypeZETA: - txs[i] = r.WithdrawZeta(withdrawAmount, true) + txs[i] = r.LegacyWithdrawZeta(withdrawAmount, true) case withdrawTypeETH: - txs[i] = r.WithdrawEther(withdrawAmount) + txs[i] = r.LegacyWithdrawEther(withdrawAmount) case withdrawTypeERC20: - txs[i] = r.WithdrawERC20(withdrawAmount) + txs[i] = r.LegacyWithdrawERC20(withdrawAmount) default: return fmt.Errorf("invalid withdraw type: %s", withdrawType) } @@ -242,7 +242,7 @@ func addZetaGasLiquidity(r *runner.E2ERunner) error { func approveTokens(r *runner.E2ERunner) error { // deposit and approve 50 WZETA for the tests approveAmount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(50)) - r.DepositAndApproveWZeta(approveAmount) + r.LegacyDepositAndApproveWZeta(approveAmount) // approve ETH for withdraws tx, err := r.ETHZRC20.Approve(r.ZEVMAuth, r.ETHZRC20Addr, approveAmount) diff --git a/e2e/e2etests/legacy/test_zeta_deposit.go b/e2e/e2etests/legacy/test_zeta_deposit.go index c78984a5ce..0f6016b658 100644 --- a/e2e/e2etests/legacy/test_zeta_deposit.go +++ b/e2e/e2etests/legacy/test_zeta_deposit.go @@ -13,7 +13,7 @@ func TestZetaDeposit(r *runner.E2ERunner, args []string) { // parse deposit amount amount := utils.ParseBigInt(r, args[0]) - hash := r.DepositZetaWithAmount(r.EVMAddress(), amount) + hash := r.LegacyDepositZetaWithAmount(r.EVMAddress(), amount) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, hash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/legacy/test_zeta_deposit_new_address.go b/e2e/e2etests/legacy/test_zeta_deposit_new_address.go index 86772672d5..645f08e840 100644 --- a/e2e/e2etests/legacy/test_zeta_deposit_new_address.go +++ b/e2e/e2etests/legacy/test_zeta_deposit_new_address.go @@ -15,7 +15,7 @@ func TestZetaDepositNewAddress(r *runner.E2ERunner, args []string) { amount := utils.ParseBigInt(r, args[0]) newAddress := sample.EthAddress() - hash := r.DepositZetaWithAmount(newAddress, amount) + hash := r.LegacyDepositZetaWithAmount(newAddress, amount) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, hash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go b/e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go index ff8bc30db0..82a297f10f 100644 --- a/e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go +++ b/e2e/e2etests/legacy/test_zeta_deposit_restricted_address.go @@ -16,7 +16,7 @@ func TestZetaDepositRestricted(r *runner.E2ERunner, args []string) { amount := utils.ParseBigInt(r, args[0]) // Deposit amount to restricted address - txHash := r.DepositZetaWithAmount(ethcommon.HexToAddress(sample.RestrictedEVMAddressTest), amount) + txHash := r.LegacyDepositZetaWithAmount(ethcommon.HexToAddress(sample.RestrictedEVMAddressTest), amount) // wait for 5 zeta blocks r.WaitForBlocks(5) diff --git a/e2e/e2etests/legacy/test_zeta_withdraw.go b/e2e/e2etests/legacy/test_zeta_withdraw.go index 3ac2fe91c8..2a31326491 100644 --- a/e2e/e2etests/legacy/test_zeta_withdraw.go +++ b/e2e/e2etests/legacy/test_zeta_withdraw.go @@ -14,8 +14,8 @@ func TestZetaWithdraw(r *runner.E2ERunner, args []string) { // parse withdraw amount amount := utils.ParseBigInt(r, args[0]) - r.DepositAndApproveWZeta(amount) - tx := r.WithdrawZeta(amount, true) + r.LegacyDepositAndApproveWZeta(amount) + tx := r.LegacyWithdrawZeta(amount, true) cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) r.Logger.CCTX(*cctx, "zeta withdraw") diff --git a/e2e/e2etests/test_crosschain_swap.go b/e2e/e2etests/test_crosschain_swap.go index b8ec437972..d13e8d9057 100644 --- a/e2e/e2etests/test_crosschain_swap.go +++ b/e2e/e2etests/test_crosschain_swap.go @@ -82,7 +82,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { r.Logger.Info("***** First test: ERC20 -> BTC") // Should deposit ERC20 for swap, swap for BTC and withdraw BTC - txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), big.NewInt(8e7), msg) + txHash := r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), big.NewInt(8e7), msg) cctx1 := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) // check the cctx status diff --git a/e2e/e2etests/test_deposit_and_call_out_of_gas.go b/e2e/e2etests/test_deposit_and_call_out_of_gas.go index 353ed60cd1..4539f80d67 100644 --- a/e2e/e2etests/test_deposit_and_call_out_of_gas.go +++ b/e2e/e2etests/test_deposit_and_call_out_of_gas.go @@ -23,7 +23,7 @@ func TestDepositAndCallOutOfGas(r *runner.E2ERunner, args []string) { require.NoError(r, err) // perform the deposit and call to the GasConsumer contract - tx := r.V2ETHDepositAndCall( + tx := r.ETHDepositAndCall( gasConsumerAddress, amount, []byte(randomPayload(r)), diff --git a/e2e/e2etests/test_deposit_and_call_swap.go b/e2e/e2etests/test_deposit_and_call_swap.go index fb0aafed4b..b9b6e600c2 100644 --- a/e2e/e2etests/test_deposit_and_call_swap.go +++ b/e2e/e2etests/test_deposit_and_call_swap.go @@ -77,7 +77,7 @@ func TestV2DepositAndCallSwap(r *runner.E2ERunner, _ []string) { // perform the deposit and call r.ApproveERC20OnEVM(r.GatewayEVMAddr) - tx = r.V2ERC20DepositAndCall( + tx = r.ERC20DepositAndCall( r.ZEVMSwapAppAddr, big.NewInt(8e7), memobytes, diff --git a/e2e/e2etests/test_donation.go b/e2e/e2etests/test_donation.go index 0e81d5ebaf..f81d1f4c00 100644 --- a/e2e/e2etests/test_donation.go +++ b/e2e/e2etests/test_donation.go @@ -15,7 +15,7 @@ func TestDonationEther(r *runner.E2ERunner, args []string) { // parse the donation amount amount := utils.ParseBigInt(r, args[0]) - txDonation, err := r.SendEther(r.TSSAddress, amount, []byte(constant.DonationMessage)) + txDonation, err := r.LegacySendEther(r.TSSAddress, amount, []byte(constant.DonationMessage)) require.NoError(r, err) r.Logger.EVMTransaction(*txDonation, "donation") diff --git a/e2e/e2etests/test_erc20_deposit.go b/e2e/e2etests/test_erc20_deposit.go index 1d30d866a7..07a589d449 100644 --- a/e2e/e2etests/test_erc20_deposit.go +++ b/e2e/e2etests/test_erc20_deposit.go @@ -23,7 +23,7 @@ func TestV2ERC20Deposit(r *runner.E2ERunner, args []string) { require.NoError(r, err) // perform the deposit - tx := r.V2ERC20Deposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) + tx := r.ERC20Deposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/test_erc20_deposit_and_call.go b/e2e/e2etests/test_erc20_deposit_and_call.go index af2eb264e2..457de1dd7e 100644 --- a/e2e/e2etests/test_erc20_deposit_and_call.go +++ b/e2e/e2etests/test_erc20_deposit_and_call.go @@ -27,7 +27,7 @@ func TestV2ERC20DepositAndCall(r *runner.E2ERunner, args []string) { require.NoError(r, err) // perform the deposit - tx := r.V2ERC20DepositAndCall( + tx := r.ERC20DepositAndCall( r.TestDAppV2ZEVMAddr, amount, []byte(payload), diff --git a/e2e/e2etests/test_erc20_deposit_and_call_no_message.go b/e2e/e2etests/test_erc20_deposit_and_call_no_message.go index 8ec0402688..016e15eae2 100644 --- a/e2e/e2etests/test_erc20_deposit_and_call_no_message.go +++ b/e2e/e2etests/test_erc20_deposit_and_call_no_message.go @@ -23,7 +23,7 @@ func TestV2ERC20DepositAndCallNoMessage(r *runner.E2ERunner, args []string) { require.NoError(r, err) // perform the deposit - tx := r.V2ERC20DepositAndCall( + tx := r.ERC20DepositAndCall( r.TestDAppV2ZEVMAddr, amount, []byte{}, diff --git a/e2e/e2etests/test_erc20_deposit_and_call_revert.go b/e2e/e2etests/test_erc20_deposit_and_call_revert.go index 7af1c3d614..5bc1fc7551 100644 --- a/e2e/e2etests/test_erc20_deposit_and_call_revert.go +++ b/e2e/e2etests/test_erc20_deposit_and_call_revert.go @@ -27,7 +27,7 @@ func TestV2ERC20DepositAndCallRevert(r *runner.E2ERunner, args []string) { require.EqualValues(r, int64(0), balance.Int64()) // perform the deposit - tx := r.V2ERC20DepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ + tx := r.ERC20DepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ RevertAddress: revertAddress, OnRevertGasLimit: big.NewInt(0), }) diff --git a/e2e/e2etests/test_erc20_deposit_and_call_revert_with_call.go b/e2e/e2etests/test_erc20_deposit_and_call_revert_with_call.go index ea7d6d261c..82c4c37b86 100644 --- a/e2e/e2etests/test_erc20_deposit_and_call_revert_with_call.go +++ b/e2e/e2etests/test_erc20_deposit_and_call_revert_with_call.go @@ -24,7 +24,7 @@ func TestV2ERC20DepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) r.AssertTestDAppEVMCalled(false, payload, amount) // perform the deposit - tx := r.V2ERC20DepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ + tx := r.ERC20DepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ RevertAddress: r.TestDAppV2EVMAddr, CallOnRevert: true, RevertMessage: []byte(payload), diff --git a/e2e/e2etests/test_erc20_deposit_restricted_address.go b/e2e/e2etests/test_erc20_deposit_restricted_address.go index 88e6afd7c8..a058881962 100644 --- a/e2e/e2etests/test_erc20_deposit_restricted_address.go +++ b/e2e/e2etests/test_erc20_deposit_restricted_address.go @@ -16,7 +16,7 @@ func TestERC20DepositRestricted(r *runner.E2ERunner, args []string) { amount := utils.ParseBigInt(r, args[0]) // deposit ERC20 to restricted address - txHash := r.DepositERC20WithAmountAndMessage( + txHash := r.LegacyDepositERC20WithAmountAndMessage( ethcommon.HexToAddress(sample.RestrictedEVMAddressTest), amount, []byte{}, diff --git a/e2e/e2etests/test_erc20_withdraw.go b/e2e/e2etests/test_erc20_withdraw.go index 8eebcde0de..8eaa4337ae 100644 --- a/e2e/e2etests/test_erc20_withdraw.go +++ b/e2e/e2etests/test_erc20_withdraw.go @@ -20,7 +20,7 @@ func TestV2ERC20Withdraw(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ERC20Withdraw(r.EVMAddress(), amount, gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) + tx := r.ERC20Withdraw(r.EVMAddress(), amount, gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/test_erc20_withdraw_and_arbitrary_call.go b/e2e/e2etests/test_erc20_withdraw_and_arbitrary_call.go index b303e1c331..92ca2445dd 100644 --- a/e2e/e2etests/test_erc20_withdraw_and_arbitrary_call.go +++ b/e2e/e2etests/test_erc20_withdraw_and_arbitrary_call.go @@ -24,7 +24,7 @@ func TestV2ERC20WithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ERC20WithdrawAndArbitraryCall( + tx := r.ERC20WithdrawAndArbitraryCall( r.TestDAppV2EVMAddr, amount, r.EncodeERC20Call(r.ERC20Addr, amount, payload), diff --git a/e2e/e2etests/test_erc20_withdraw_and_call.go b/e2e/e2etests/test_erc20_withdraw_and_call.go index fa7c9b6670..95244ad65a 100644 --- a/e2e/e2etests/test_erc20_withdraw_and_call.go +++ b/e2e/e2etests/test_erc20_withdraw_and_call.go @@ -31,7 +31,7 @@ func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ERC20WithdrawAndCall( + tx := r.ERC20WithdrawAndCall( r.TestDAppV2EVMAddr, amount, []byte(payload), diff --git a/e2e/e2etests/test_erc20_withdraw_and_call_no_message.go b/e2e/e2etests/test_erc20_withdraw_and_call_no_message.go index e131a80269..5dd3befa18 100644 --- a/e2e/e2etests/test_erc20_withdraw_and_call_no_message.go +++ b/e2e/e2etests/test_erc20_withdraw_and_call_no_message.go @@ -27,7 +27,7 @@ func TestV2ERC20WithdrawAndCallNoMessage(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ERC20WithdrawAndCall( + tx := r.ERC20WithdrawAndCall( r.TestDAppV2EVMAddr, amount, []byte{}, diff --git a/e2e/e2etests/test_erc20_withdraw_and_call_revert.go b/e2e/e2etests/test_erc20_withdraw_and_call_revert.go index 22a547654e..7f94ad19c9 100644 --- a/e2e/e2etests/test_erc20_withdraw_and_call_revert.go +++ b/e2e/e2etests/test_erc20_withdraw_and_call_revert.go @@ -28,7 +28,7 @@ func TestV2ERC20WithdrawAndCallRevert(r *runner.E2ERunner, args []string) { require.EqualValues(r, int64(0), balance.Int64()) // perform the withdraw - tx := r.V2ERC20WithdrawAndArbitraryCall( + tx := r.ERC20WithdrawAndArbitraryCall( r.TestDAppV2EVMAddr, amount, r.EncodeERC20CallRevert(r.ERC20Addr, amount), diff --git a/e2e/e2etests/test_erc20_withdraw_and_call_revert_with_call.go b/e2e/e2etests/test_erc20_withdraw_and_call_revert_with_call.go index 4be9ace78a..697f817e9d 100644 --- a/e2e/e2etests/test_erc20_withdraw_and_call_revert_with_call.go +++ b/e2e/e2etests/test_erc20_withdraw_and_call_revert_with_call.go @@ -25,7 +25,7 @@ func TestV2ERC20WithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ERC20WithdrawAndArbitraryCall( + tx := r.ERC20WithdrawAndArbitraryCall( r.TestDAppV2EVMAddr, amount, r.EncodeERC20CallRevert(r.ERC20Addr, amount), diff --git a/e2e/e2etests/test_eth_deposit.go b/e2e/e2etests/test_eth_deposit.go index 517e49944e..b3ceae87d4 100644 --- a/e2e/e2etests/test_eth_deposit.go +++ b/e2e/e2etests/test_eth_deposit.go @@ -19,7 +19,7 @@ func TestV2ETHDeposit(r *runner.E2ERunner, args []string) { r.Logger.Info("starting v2 eth deposit test") // perform the deposit - tx := r.V2ETHDeposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) + tx := r.ETHDeposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/test_eth_deposit_and_call.go b/e2e/e2etests/test_eth_deposit_and_call.go index 287efe46cd..726e31360c 100644 --- a/e2e/e2etests/test_eth_deposit_and_call.go +++ b/e2e/e2etests/test_eth_deposit_and_call.go @@ -25,7 +25,7 @@ func TestV2ETHDepositAndCall(r *runner.E2ERunner, args []string) { require.NoError(r, err) // perform the deposit and call to the TestDAppV2ZEVMAddr - tx := r.V2ETHDepositAndCall( + tx := r.ETHDepositAndCall( r.TestDAppV2ZEVMAddr, amount, []byte(payload), diff --git a/e2e/e2etests/test_eth_deposit_and_call_no_message.go b/e2e/e2etests/test_eth_deposit_and_call_no_message.go index a739aec761..176d223e73 100644 --- a/e2e/e2etests/test_eth_deposit_and_call_no_message.go +++ b/e2e/e2etests/test_eth_deposit_and_call_no_message.go @@ -21,7 +21,7 @@ func TestV2ETHDepositAndCallNoMessage(r *runner.E2ERunner, args []string) { require.NoError(r, err) // perform the deposit and call to the TestDAppV2ZEVMAddr - tx := r.V2ETHDepositAndCall( + tx := r.ETHDepositAndCall( r.TestDAppV2ZEVMAddr, amount, []byte{}, diff --git a/e2e/e2etests/test_eth_deposit_and_call_revert.go b/e2e/e2etests/test_eth_deposit_and_call_revert.go index 39508fd177..10d496ef60 100644 --- a/e2e/e2etests/test_eth_deposit_and_call_revert.go +++ b/e2e/e2etests/test_eth_deposit_and_call_revert.go @@ -26,7 +26,7 @@ func TestV2ETHDepositAndCallRevert(r *runner.E2ERunner, args []string) { require.EqualValues(r, int64(0), balance.Int64()) // perform the deposit - tx := r.V2ETHDepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ + tx := r.ETHDepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ RevertAddress: revertAddress, OnRevertGasLimit: big.NewInt(0), }) diff --git a/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go b/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go index 63337040ca..3f16e7223d 100644 --- a/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go +++ b/e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go @@ -24,7 +24,7 @@ func TestV2ETHDepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) { r.AssertTestDAppEVMCalled(false, payload, amount) // perform the deposit - tx := r.V2ETHDepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ + tx := r.ETHDepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{ RevertAddress: r.TestDAppV2EVMAddr, CallOnRevert: true, RevertMessage: []byte(payload), diff --git a/e2e/e2etests/test_eth_deposit_liquidity_cap.go b/e2e/e2etests/test_eth_deposit_liquidity_cap.go index 636ada56b9..169af6ac97 100644 --- a/e2e/e2etests/test_eth_deposit_liquidity_cap.go +++ b/e2e/e2etests/test_eth_deposit_liquidity_cap.go @@ -35,7 +35,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.Logger.Info("set liquidity cap tx hash: %s", res.TxHash) r.Logger.Info("Depositing more than liquidity cap should make cctx reverted") - signedTx, err := r.SendEther(r.TSSAddress, amountMoreThanCap, nil) + signedTx, err := r.LegacySendEther(r.TSSAddress, amountMoreThanCap, nil) require.NoError(r, err) receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, signedTx, r.Logger, r.ReceiptTimeout) @@ -50,7 +50,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { initialBal, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) require.NoError(r, err) - signedTx, err = r.SendEther(r.TSSAddress, amountLessThanCap, nil) + signedTx, err = r.LegacySendEther(r.TSSAddress, amountLessThanCap, nil) require.NoError(r, err) receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, signedTx, r.Logger, r.ReceiptTimeout) @@ -82,7 +82,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { initialBal, err = r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) require.NoError(r, err) - signedTx, err = r.SendEther(r.TSSAddress, amountMoreThanCap, nil) + signedTx, err = r.LegacySendEther(r.TSSAddress, amountMoreThanCap, nil) require.NoError(r, err) receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, signedTx, r.Logger, r.ReceiptTimeout) diff --git a/e2e/e2etests/test_eth_withdraw.go b/e2e/e2etests/test_eth_withdraw.go index 7993d90a20..cff29f8188 100644 --- a/e2e/e2etests/test_eth_withdraw.go +++ b/e2e/e2etests/test_eth_withdraw.go @@ -22,7 +22,7 @@ func TestV2ETHWithdraw(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ETHWithdraw(r.EVMAddress(), amount, gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) + tx := r.ETHWithdraw(r.EVMAddress(), amount, gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) // wait for the cctx to be mined cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/test_eth_withdraw_and_arbitrary_call.go b/e2e/e2etests/test_eth_withdraw_and_arbitrary_call.go index 3405bcbfa0..06e465b111 100644 --- a/e2e/e2etests/test_eth_withdraw_and_arbitrary_call.go +++ b/e2e/e2etests/test_eth_withdraw_and_arbitrary_call.go @@ -23,7 +23,7 @@ func TestV2ETHWithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ETHWithdrawAndArbitraryCall( + tx := r.ETHWithdrawAndArbitraryCall( r.TestDAppV2EVMAddr, amount, r.EncodeGasCall(payload), diff --git a/e2e/e2etests/test_eth_withdraw_and_call.go b/e2e/e2etests/test_eth_withdraw_and_call.go index c0a8a41054..ce8f3e7bba 100644 --- a/e2e/e2etests/test_eth_withdraw_and_call.go +++ b/e2e/e2etests/test_eth_withdraw_and_call.go @@ -30,7 +30,7 @@ func TestV2ETHWithdrawAndCall(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ETHWithdrawAndCall( + tx := r.ETHWithdrawAndCall( r.TestDAppV2EVMAddr, amount, []byte(payload), diff --git a/e2e/e2etests/test_eth_withdraw_and_call_no_message.go b/e2e/e2etests/test_eth_withdraw_and_call_no_message.go index 0adc6af344..d1c5ede46c 100644 --- a/e2e/e2etests/test_eth_withdraw_and_call_no_message.go +++ b/e2e/e2etests/test_eth_withdraw_and_call_no_message.go @@ -26,7 +26,7 @@ func TestV2ETHWithdrawAndCallNoMessage(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ETHWithdrawAndCall( + tx := r.ETHWithdrawAndCall( r.TestDAppV2EVMAddr, amount, []byte{}, diff --git a/e2e/e2etests/test_eth_withdraw_and_call_revert.go b/e2e/e2etests/test_eth_withdraw_and_call_revert.go index 69f7318473..bb6956bca1 100644 --- a/e2e/e2etests/test_eth_withdraw_and_call_revert.go +++ b/e2e/e2etests/test_eth_withdraw_and_call_revert.go @@ -27,7 +27,7 @@ func TestV2ETHWithdrawAndCallRevert(r *runner.E2ERunner, args []string) { require.EqualValues(r, int64(0), balance.Int64()) // perform the withdraw - tx := r.V2ETHWithdrawAndArbitraryCall( + tx := r.ETHWithdrawAndArbitraryCall( r.TestDAppV2EVMAddr, amount, r.EncodeGasCall("revert"), diff --git a/e2e/e2etests/test_eth_withdraw_and_call_revert_with_call.go b/e2e/e2etests/test_eth_withdraw_and_call_revert_with_call.go index 7fe11926d7..b820757b23 100644 --- a/e2e/e2etests/test_eth_withdraw_and_call_revert_with_call.go +++ b/e2e/e2etests/test_eth_withdraw_and_call_revert_with_call.go @@ -24,7 +24,7 @@ func TestV2ETHWithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string) r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the withdraw - tx := r.V2ETHWithdrawAndArbitraryCall( + tx := r.ETHWithdrawAndArbitraryCall( r.TestDAppV2EVMAddr, amount, r.EncodeGasCall("revert"), diff --git a/e2e/e2etests/test_eth_withdraw_and_call_through_contract.go b/e2e/e2etests/test_eth_withdraw_and_call_through_contract.go index 7328b9b236..b58b155eaa 100644 --- a/e2e/e2etests/test_eth_withdraw_and_call_through_contract.go +++ b/e2e/e2etests/test_eth_withdraw_and_call_through_contract.go @@ -40,7 +40,7 @@ func TestV2ETHWithdrawAndCallThroughContract(r *runner.E2ERunner, args []string) payload := randomPayload(r) // perform the authenticated call - tx = r.V2ETHWithdrawAndCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr, + tx = r.ETHWithdrawAndCallThroughContract(gatewayCaller, r.TestDAppV2EVMAddr, amount, []byte(payload), gatewayzevmcaller.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) diff --git a/e2e/e2etests/test_evm_to_zevm_call.go b/e2e/e2etests/test_evm_to_zevm_call.go index 305f279164..d6399e54c5 100644 --- a/e2e/e2etests/test_evm_to_zevm_call.go +++ b/e2e/e2etests/test_evm_to_zevm_call.go @@ -19,7 +19,7 @@ func TestV2EVMToZEVMCall(r *runner.E2ERunner, args []string) { r.AssertTestDAppZEVMCalled(false, payload, big.NewInt(0)) // perform the withdraw - tx := r.V2EVMToZEMVCall( + tx := r.EVMToZEMVCall( r.TestDAppV2ZEVMAddr, []byte(payload), gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}, diff --git a/e2e/e2etests/test_inbound_trackers.go b/e2e/e2etests/test_inbound_trackers.go index b26b505cf1..b1cff6e990 100644 --- a/e2e/e2etests/test_inbound_trackers.go +++ b/e2e/e2etests/test_inbound_trackers.go @@ -30,25 +30,25 @@ func TestInboundTrackers(r *runner.E2ERunner, args []string) { // send v1 eth deposit r.Logger.Print("🏃test v1 eth deposit") - txHash := r.DepositEtherWithAmount(amount) + txHash := r.LegacyDepositEtherWithAmount(amount) addTrackerAndWaitForCCTX(coin.CoinType_Gas, txHash.Hex()) r.Logger.Print("🍾v1 eth deposit observed") // send v1 erc20 deposit r.Logger.Print("🏃test v1 erc20 deposit") - txHash = r.DepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{}) + txHash = r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{}) addTrackerAndWaitForCCTX(coin.CoinType_ERC20, txHash.Hex()) r.Logger.Print("🍾v1 erc20 deposit observed") // send v2 eth deposit r.Logger.Print("🏃test v2 eth deposit") - tx := r.V2ETHDeposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) + tx := r.ETHDeposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) addTrackerAndWaitForCCTX(coin.CoinType_Gas, tx.Hash().Hex()) r.Logger.Print("🍾v2 eth deposit observed") // send v2 eth deposit and call r.Logger.Print("🏃test v2 eth eposit and call") - tx = r.V2ETHDepositAndCall( + tx = r.ETHDepositAndCall( r.TestDAppV2ZEVMAddr, amount, []byte(randomPayload(r)), @@ -60,13 +60,13 @@ func TestInboundTrackers(r *runner.E2ERunner, args []string) { // send v2 erc20 deposit r.Logger.Print("🏃test v2 erc20 deposit") r.ApproveERC20OnEVM(r.GatewayEVMAddr) - tx = r.V2ERC20Deposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) + tx = r.ERC20Deposit(r.EVMAddress(), amount, gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}) addTrackerAndWaitForCCTX(coin.CoinType_Gas, tx.Hash().Hex()) r.Logger.Print("🍾v2 erc20 deposit observed") // send v2 erc20 deposit and call r.Logger.Print("🏃test v2 erc20 deposit and call") - tx = r.V2ERC20DepositAndCall( + tx = r.ERC20DepositAndCall( r.TestDAppV2ZEVMAddr, amount, []byte(randomPayload(r)), @@ -77,7 +77,7 @@ func TestInboundTrackers(r *runner.E2ERunner, args []string) { // send v2 call r.Logger.Print("🏃test v2 call") - tx = r.V2EVMToZEMVCall( + tx = r.EVMToZEMVCall( r.TestDAppV2ZEVMAddr, []byte(randomPayload(r)), gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}, diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 5f74ef2db9..f24c272b57 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -39,7 +39,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // deposit most of the ZETA supply on ZetaChain zetaAmount := big.NewInt(1e18) zetaAmount = zetaAmount.Mul(zetaAmount, big.NewInt(20_000_000_000)) // 20B Zeta - r.DepositZetaWithAmount(r.EVMAddress(), zetaAmount) + r.LegacyDepositZetaWithAmount(r.EVMAddress(), zetaAmount) // do an ethers withdraw on the previous chain (0.01eth) for some interaction legacy.TestEtherWithdraw(r, []string{"10000000000000000"}) @@ -48,14 +48,14 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { newRunner, err := configureEVM2(r) require.NoError(r, err) - newRunner.SetupEVM(false, false) + newRunner.LegacySetupEVM(false, false) // mint some ERC20 - newRunner.MintERC20OnEvm(10000) + newRunner.MintERC20OnEVM(10000) // we deploy connectorETH in this test to simulate a new "canonical" chain emitting ZETA // to represent the ZETA already existing on ZetaChain we manually send the minted ZETA to the connector - newRunner.SendZetaOnEvm(newRunner.ConnectorEthAddr, 20_000_000_000) + newRunner.LegacySendZetaOnEvm(newRunner.ConnectorEthAddr, 20_000_000_000) // update the chain params to set up the chain chainParams := getNewEVMChainParams(newRunner) @@ -137,13 +137,13 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { // deposit Ethers and ERC20 on ZetaChain etherAmount := big.NewInt(1e18) etherAmount = etherAmount.Mul(etherAmount, big.NewInt(10)) - txEtherDeposit := newRunner.DepositEtherWithAmount(etherAmount) + txEtherDeposit := newRunner.LegacyDepositEtherWithAmount(etherAmount) newRunner.WaitForMinedCCTX(txEtherDeposit) // perform withdrawals on the new chain amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(10)) - newRunner.DepositAndApproveWZeta(amount) - tx := newRunner.WithdrawZeta(amount, true) + newRunner.LegacyDepositAndApproveWZeta(amount) + tx := newRunner.LegacyWithdrawZeta(amount, true) cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) r.Logger.CCTX(*cctx, "zeta withdraw") utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) @@ -185,7 +185,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { newRunner.ERC20ZRC20 = erc20ZRC20 // deposit ERC20 on ZetaChain - txERC20Deposit := newRunner.DepositERC20() + txERC20Deposit := newRunner.LegacyDepositERC20() newRunner.WaitForMinedCCTX(txERC20Deposit) // stop mining diff --git a/e2e/e2etests/test_pause_zrc20.go b/e2e/e2etests/test_pause_zrc20.go index 991ccbcaf8..ed76341186 100644 --- a/e2e/e2etests/test_pause_zrc20.go +++ b/e2e/e2etests/test_pause_zrc20.go @@ -92,7 +92,7 @@ func TestPauseZRC20(r *runner.E2ERunner, _ []string) { utils.RequireTxSuccessful(r, receipt) // Check deposit revert when paused - signedTx, err := r.SendEther(r.TSSAddress, big.NewInt(1e17), nil) + signedTx, err := r.LegacySendEther(r.TSSAddress, big.NewInt(1e17), nil) require.NoError(r, err) receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, signedTx, r.Logger, r.ReceiptTimeout) diff --git a/e2e/e2etests/test_precompiles_bank.go b/e2e/e2etests/test_precompiles_bank.go index 308f684572..1745a9e0b5 100644 --- a/e2e/e2etests/test_precompiles_bank.go +++ b/e2e/e2etests/test_precompiles_bank.go @@ -47,7 +47,7 @@ func TestPrecompilesBank(r *runner.E2ERunner, args []string) { }() // Get ERC20ZRC20. - txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), totalAmount, []byte{}) + txHash := r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), totalAmount, []byte{}) utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) // Create a bank contract caller. @@ -167,7 +167,7 @@ func TestPrecompilesBankNonZRC20(r *runner.E2ERunner, args []string) { // Deposit and approve 50 WZETA for the test. approveAmount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(50)) - r.DepositAndApproveWZeta(approveAmount) + r.LegacyDepositAndApproveWZeta(approveAmount) // Non ZRC20 balanceOf check should fail. _, err = bankContract.BalanceOf(&bind.CallOpts{Context: r.Ctx}, r.WZetaAddr, spender) diff --git a/e2e/e2etests/test_precompiles_bank_through_contract.go b/e2e/e2etests/test_precompiles_bank_through_contract.go index 18532f2bd6..9801325f41 100644 --- a/e2e/e2etests/test_precompiles_bank_through_contract.go +++ b/e2e/e2etests/test_precompiles_bank_through_contract.go @@ -29,7 +29,7 @@ func TestPrecompilesBankThroughContract(r *runner.E2ERunner, args []string) { ) // Get ERC20ZRC20. - txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), oneThousand, []byte{}) + txHash := r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), oneThousand, []byte{}) utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) bankPrecompileCaller, err := bank.NewIBank(bank.ContractAddress, r.ZEVMClient) diff --git a/e2e/e2etests/test_precompiles_distribute_and_claim.go b/e2e/e2etests/test_precompiles_distribute_and_claim.go index 91aa81fc44..c384c04b7b 100644 --- a/e2e/e2etests/test_precompiles_distribute_and_claim.go +++ b/e2e/e2etests/test_precompiles_distribute_and_claim.go @@ -70,7 +70,7 @@ func TestPrecompilesDistributeAndClaim(r *runner.E2ERunner, args []string) { defer resetDistributionTest(r, distrContract, lockerAddress, previousGasLimit, staker, validatorValAddr) // Get ERC20ZRC20. - txHash := r.DepositERC20WithAmountAndMessage(staker, zrc20DistrAmt, []byte{}) + txHash := r.LegacyDepositERC20WithAmountAndMessage(staker, zrc20DistrAmt, []byte{}) utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) // There is no delegation, so the response should be empty. @@ -220,7 +220,7 @@ func TestPrecompilesDistributeNonZRC20(r *runner.E2ERunner, args []string) { // Deposit and approve 50 WZETA for the test. approveAmount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(50)) - r.DepositAndApproveWZeta(approveAmount) + r.LegacyDepositAndApproveWZeta(approveAmount) // Allow the staking contract to spend 25 WZeta tokens. tx, err := r.WZeta.Approve(r.ZEVMAuth, dstrAddress, big.NewInt(25)) diff --git a/e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go b/e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go index 284185de77..bad20df052 100644 --- a/e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go +++ b/e2e/e2etests/test_precompiles_distribute_and_claim_through_contract.go @@ -73,7 +73,7 @@ func TestPrecompilesDistributeAndClaimThroughContract(r *runner.E2ERunner, args defer resetDistributionTest(r, distrContract, lockerAddress, previousGasLimit, staker, validatorValAddr) // Get ERC20ZRC20. - txHash := r.DepositERC20WithAmountAndMessage(staker, zrc20DistrAmt, []byte{}) + txHash := r.LegacyDepositERC20WithAmountAndMessage(staker, zrc20DistrAmt, []byte{}) utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) // There is no delegation, so the response should be empty. diff --git a/e2e/e2etests/test_stress_eth_deposit.go b/e2e/e2etests/test_stress_eth_deposit.go index 292851ffaa..5e1425e004 100644 --- a/e2e/e2etests/test_stress_eth_deposit.go +++ b/e2e/e2etests/test_stress_eth_deposit.go @@ -29,7 +29,7 @@ func TestStressEtherDeposit(r *runner.E2ERunner, args []string) { // send the deposits for i := 0; i < numDeposits; i++ { i := i - hash := r.DepositEtherWithAmount(depositAmount) + hash := r.LegacyDepositEtherWithAmount(depositAmount) r.Logger.Print("index %d: starting deposit, tx hash: %s", i, hash.Hex()) eg.Go(func() error { return monitorEtherDeposit(r, hash, i, time.Now()) }) diff --git a/e2e/e2etests/test_update_bytecode_connector.go b/e2e/e2etests/test_update_bytecode_connector.go index 4cbe0f66aa..9974268050 100644 --- a/e2e/e2etests/test_update_bytecode_connector.go +++ b/e2e/e2etests/test_update_bytecode_connector.go @@ -17,9 +17,9 @@ import ( func TestUpdateBytecodeConnector(r *runner.E2ERunner, _ []string) { // Can withdraw 10ZETA amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(10)) - r.DepositAndApproveWZeta(amount) + r.LegacyDepositAndApproveWZeta(amount) - tx := r.WithdrawZeta(amount, true) + tx := r.LegacyWithdrawZeta(amount, true) cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) @@ -63,8 +63,8 @@ func TestUpdateBytecodeConnector(r *runner.E2ERunner, _ []string) { require.Equal(r, "foo", response) // Can continue to interact with the connector: withdraw 10ZETA - r.DepositAndApproveWZeta(amount) - tx = r.WithdrawZeta(amount, true) + r.LegacyDepositAndApproveWZeta(amount) + tx = r.LegacyWithdrawZeta(amount, true) cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) r.Logger.CCTX(*cctx, "zeta withdraw") utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) diff --git a/e2e/e2etests/test_whitelist_erc20.go b/e2e/e2etests/test_whitelist_erc20.go index 1823947b98..f1a44b57de 100644 --- a/e2e/e2etests/test_whitelist_erc20.go +++ b/e2e/e2etests/test_whitelist_erc20.go @@ -92,7 +92,7 @@ func TestWhitelistERC20(r *runner.E2ERunner, _ []string) { r.Logger.Info("ERC20 balance: %s", balance.String()) // run deposit and withdraw ERC20 test - txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), balance, []byte{}) + txHash := r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), balance, []byte{}) r.WaitForMinedCCTX(txHash) // approve 1 unit of the gas token to cover the gas fee @@ -103,6 +103,6 @@ func TestWhitelistERC20(r *runner.E2ERunner, _ []string) { utils.RequireTxSuccessful(r, receipt) r.Logger.Info("eth zrc20 approve receipt: status %d", receipt.Status) - tx = r.WithdrawERC20(balance) + tx = r.LegacyWithdrawERC20(balance) r.WaitForMinedCCTX(tx.Hash()) } diff --git a/e2e/e2etests/test_zevm_to_evm_arbitrary_call.go b/e2e/e2etests/test_zevm_to_evm_arbitrary_call.go index 429fbea714..b5ee287f19 100644 --- a/e2e/e2etests/test_zevm_to_evm_arbitrary_call.go +++ b/e2e/e2etests/test_zevm_to_evm_arbitrary_call.go @@ -22,7 +22,7 @@ func TestV2ZEVMToEVMArbitraryCall(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the call - tx := r.V2ZEVMToEMVArbitraryCall( + tx := r.ZEVMToEMVArbitraryCall( r.TestDAppV2EVMAddr, r.EncodeSimpleCall(payload), gatewayzevm.RevertOptions{ diff --git a/e2e/e2etests/test_zevm_to_evm_call.go b/e2e/e2etests/test_zevm_to_evm_call.go index 2f1ed19d1b..d13d678277 100644 --- a/e2e/e2etests/test_zevm_to_evm_call.go +++ b/e2e/e2etests/test_zevm_to_evm_call.go @@ -23,7 +23,7 @@ func TestV2ZEVMToEVMCall(r *runner.E2ERunner, args []string) { r.ApproveETHZRC20(r.GatewayZEVMAddr) // perform the authenticated call - tx := r.V2ZEVMToEMVCall( + tx := r.ZEVMToEMVCall( r.TestDAppV2EVMAddr, []byte(payload), gatewayzevm.RevertOptions{ diff --git a/e2e/e2etests/test_zevm_to_evm_call_through_contract.go b/e2e/e2etests/test_zevm_to_evm_call_through_contract.go index fa54ca34f6..44f85225ed 100644 --- a/e2e/e2etests/test_zevm_to_evm_call_through_contract.go +++ b/e2e/e2etests/test_zevm_to_evm_call_through_contract.go @@ -34,7 +34,7 @@ func TestV2ZEVMToEVMCallThroughContract(r *runner.E2ERunner, args []string) { utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) // perform the authenticated call - tx = r.V2ZEVMToEMVCallThroughContract( + tx = r.ZEVMToEMVCallThroughContract( gatewayCaller, r.TestDAppV2EVMAddr, []byte(payload), diff --git a/e2e/runner/accounting.go b/e2e/runner/accounting.go index 223ca9c8c4..6dbd188c72 100644 --- a/e2e/runner/accounting.go +++ b/e2e/runner/accounting.go @@ -36,7 +36,7 @@ type Response struct { func (r *E2ERunner) CheckZRC20BalanceAndSupply() { r.Logger.Info("Checking ZRC20 Balance vs. Supply") - err := r.checkEthTSSBalance() + err := r.checkETHTSSBalance() require.NoError(r, err, "ETH balance check failed") err = r.checkERC20TSSBalance() @@ -45,11 +45,11 @@ func (r *E2ERunner) CheckZRC20BalanceAndSupply() { err = r.checkZetaTSSBalance() require.NoError(r, err, "ZETA balance check failed") - err = r.CheckBtcTSSBalance() + err = r.CheckBTCTSSBalance() require.NoError(r, err, "BTC balance check failed") } -func (r *E2ERunner) checkEthTSSBalance() error { +func (r *E2ERunner) checkETHTSSBalance() error { allTssAddress, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{}) if err != nil { return err @@ -86,7 +86,7 @@ func (r *E2ERunner) checkEthTSSBalance() error { return nil } -func (r *E2ERunner) CheckBtcTSSBalance() error { +func (r *E2ERunner) CheckBTCTSSBalance() error { allTssAddress, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{}) if err != nil { return err diff --git a/e2e/runner/admin_evm.go b/e2e/runner/admin_evm.go index 88b0a1121d..0769d689d6 100644 --- a/e2e/runner/admin_evm.go +++ b/e2e/runner/admin_evm.go @@ -7,7 +7,7 @@ import ( "github.com/zeta-chain/node/e2e/utils" ) -func (r *E2ERunner) UpdateTssAddressForConnector() { +func (r *E2ERunner) UpdateTSSAddressForConnector() { require.NoError(r, r.SetTSSAddresses()) tx, err := r.ConnectorEth.UpdateTssAddress(r.EVMAuth, r.TSSAddress) @@ -21,7 +21,7 @@ func (r *E2ERunner) UpdateTssAddressForConnector() { require.Equal(r, r.TSSAddress, tssAddressOnConnector) } -func (r *E2ERunner) UpdateTssAddressForErc20custody() { +func (r *E2ERunner) UpdateTSSAddressForERC20custody() { require.NoError(r, r.SetTSSAddresses()) tx, err := r.ERC20CustodyV2.UpdateTSSAddress(r.EVMAuth, r.TSSAddress) diff --git a/e2e/runner/evm.go b/e2e/runner/evm.go index d12e895d96..cc21da7622 100644 --- a/e2e/runner/evm.go +++ b/e2e/runner/evm.go @@ -10,160 +10,143 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" "github.com/stretchr/testify/require" + "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol" "github.com/zeta-chain/node/e2e/utils" ) -// WaitForTxReceiptOnEvm waits for a tx receipt on EVM -func (r *E2ERunner) WaitForTxReceiptOnEvm(tx *ethtypes.Transaction) { - r.Lock() - defer r.Unlock() - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt) -} - -// MintERC20OnEvm mints ERC20 on EVM -// amount is a multiple of 1e18 -func (r *E2ERunner) MintERC20OnEvm(amountERC20 int64) { - r.Lock() - defer r.Unlock() - - amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(amountERC20)) +// ETHDeposit calls Deposit of Gateway with gas token on EVM +func (r *E2ERunner) ETHDeposit( + receiver ethcommon.Address, + amount *big.Int, + revertOptions gatewayevm.RevertOptions, +) *ethtypes.Transaction { + // set the value of the transaction + previousValue := r.EVMAuth.Value + defer func() { + r.EVMAuth.Value = previousValue + }() + r.EVMAuth.Value = amount - tx, err := r.ERC20.Mint(r.EVMAuth, amount) + tx, err := r.GatewayEVM.Deposit0(r.EVMAuth, receiver, revertOptions) require.NoError(r, err) - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt) + logDepositInfoAndWaitForTxReceipt(r, tx, "eth_deposit") - r.Logger.Info("Mint receipt tx hash: %s", tx.Hash().Hex()) + return tx } -// SendERC20OnEvm sends ERC20 to an address on EVM -// this allows the ERC20 contract deployer to funds other accounts on EVM -// amountERC20 is a multiple of 1e18 -func (r *E2ERunner) SendERC20OnEvm(address ethcommon.Address, amountERC20 int64) *ethtypes.Transaction { - // the deployer might be sending ERC20 in different goroutines - r.Lock() - defer r.Unlock() - - amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(amountERC20)) +// ETHDepositAndCall calls DepositAndCall of Gateway with gas token on EVM +func (r *E2ERunner) ETHDepositAndCall( + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayevm.RevertOptions, +) *ethtypes.Transaction { + // set the value of the transaction + previousValue := r.EVMAuth.Value + defer func() { + r.EVMAuth.Value = previousValue + }() + r.EVMAuth.Value = amount - // transfer - tx, err := r.ERC20.Transfer(r.EVMAuth, address, amount) + tx, err := r.GatewayEVM.DepositAndCall(r.EVMAuth, receiver, payload, revertOptions) require.NoError(r, err) - return tx -} - -func (r *E2ERunner) DepositERC20() ethcommon.Hash { - r.Logger.Print("⏳ depositing ERC20 into ZEVM") + logDepositInfoAndWaitForTxReceipt(r, tx, "eth_deposit_and_call") - oneHundred := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(100)) - return r.DepositERC20WithAmountAndMessage(r.EVMAddress(), oneHundred, []byte{}) + return tx } -func (r *E2ERunner) DepositERC20WithAmountAndMessage(to ethcommon.Address, amount *big.Int, msg []byte) ethcommon.Hash { - // reset allowance, necessary for USDT - tx, err := r.ERC20.Approve(r.EVMAuth, r.ERC20CustodyAddr, big.NewInt(0)) +// ERC20Deposit calls Deposit of Gateway with erc20 token on EVM +func (r *E2ERunner) ERC20Deposit( + receiver ethcommon.Address, + amount *big.Int, + revertOptions gatewayevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayEVM.Deposit(r.EVMAuth, receiver, amount, r.ERC20Addr, revertOptions) require.NoError(r, err) - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt) + logDepositInfoAndWaitForTxReceipt(r, tx, "erc20_deposit") - r.Logger.Info("ERC20 Approve receipt tx hash: %s", tx.Hash().Hex()) + return tx +} - tx, err = r.ERC20.Approve(r.EVMAuth, r.ERC20CustodyAddr, amount) +// ERC20DepositAndCall calls DepositAndCall of Gateway with erc20 token on EVM +func (r *E2ERunner) ERC20DepositAndCall( + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayEVM.DepositAndCall0( + r.EVMAuth, + receiver, + amount, + r.ERC20Addr, + payload, + revertOptions, + ) require.NoError(r, err) - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt) + logDepositInfoAndWaitForTxReceipt(r, tx, "erc20_deposit_and_call") - r.Logger.Info("ERC20 Approve receipt tx hash: %s", tx.Hash().Hex()) + return tx +} - tx, err = r.ERC20Custody.Deposit(r.EVMAuth, to.Bytes(), r.ERC20Addr, amount, msg) +// EVMToZEMVCall calls Call of Gateway on EVM +func (r *E2ERunner) EVMToZEMVCall( + receiver ethcommon.Address, + payload []byte, + revertOptions gatewayevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayEVM.Call(r.EVMAuth, receiver, payload, revertOptions) require.NoError(r, err) - r.Logger.Info("TX: %v", tx) + return tx +} - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt) +// WaitForTxReceiptOnEVM waits for a tx receipt on EVM +func (r *E2ERunner) WaitForTxReceiptOnEVM(tx *ethtypes.Transaction) { + r.Lock() + defer r.Unlock() - r.Logger.Info("Deposit receipt tx hash: %s, status %d", receipt.TxHash.Hex(), receipt.Status) - for _, log := range receipt.Logs { - event, err := r.ERC20Custody.ParseDeposited(*log) - if err != nil { - continue - } - r.Logger.Info("Deposited event:") - r.Logger.Info(" Recipient address: %x", event.Recipient) - r.Logger.Info(" ERC20 address: %s", event.Asset.Hex()) - r.Logger.Info(" Amount: %d", event.Amount) - r.Logger.Info(" Message: %x", event.Message) - } - return tx.Hash() + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt) } -// DepositEther sends Ethers into ZEVM -func (r *E2ERunner) DepositEther() ethcommon.Hash { - amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(100)) // 100 eth - return r.DepositEtherWithAmount(amount) -} +// MintERC20OnEVM mints ERC20 on EVM +// amount is a multiple of 1e18 +func (r *E2ERunner) MintERC20OnEVM(amountERC20 int64) { + r.Lock() + defer r.Unlock() -// DepositEtherWithAmount sends Ethers into ZEVM -func (r *E2ERunner) DepositEtherWithAmount(amount *big.Int) ethcommon.Hash { - r.Logger.Print("⏳ depositing Ethers into ZEVM") + amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(amountERC20)) - signedTx, err := r.SendEther(r.TSSAddress, amount, nil) + tx, err := r.ERC20.Mint(r.EVMAuth, amount) require.NoError(r, err) - r.Logger.EVMTransaction(*signedTx, "send to TSS") - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, signedTx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt, "deposit failed") - - r.Logger.EVMReceipt(*receipt, "send to TSS") + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt) - return signedTx.Hash() + r.Logger.Info("Mint receipt tx hash: %s", tx.Hash().Hex()) } -// SendEther sends ethers to the TSS on EVM -func (r *E2ERunner) SendEther(_ ethcommon.Address, value *big.Int, data []byte) (*ethtypes.Transaction, error) { - evmClient := r.EVMClient - - nonce, err := evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) - if err != nil { - return nil, err - } - - gasLimit := uint64(30000) // in units - gasPrice, err := evmClient.SuggestGasPrice(r.Ctx) - if err != nil { - return nil, err - } - - tx := ethtypes.NewTransaction(nonce, r.TSSAddress, value, gasLimit, gasPrice, data) - chainID, err := evmClient.ChainID(r.Ctx) - if err != nil { - return nil, err - } +// SendERC20OnEVM sends ERC20 to an address on EVM +// this allows the ERC20 contract deployer to funds other accounts on EVM +// amountERC20 is a multiple of 1e18 +func (r *E2ERunner) SendERC20OnEVM(address ethcommon.Address, amountERC20 int64) *ethtypes.Transaction { + // the deployer might be sending ERC20 in different goroutines + r.Lock() + defer r.Unlock() - deployerPrivkey, err := r.Account.PrivateKey() - if err != nil { - return nil, err - } + amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(amountERC20)) - signedTx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(chainID), deployerPrivkey) - if err != nil { - return nil, err - } - err = evmClient.SendTransaction(r.Ctx, signedTx) - if err != nil { - return nil, err - } + // transfer + tx, err := r.ERC20.Transfer(r.EVMAuth, address, amount) + require.NoError(r, err) - return signedTx, nil + return tx } // ApproveERC20OnEVM approves ERC20 on EVM to a specific address @@ -248,3 +231,17 @@ func (r *E2ERunner) AnvilMineBlocks(url string, blockTime int) (func(), error) { close(stop) }, nil } + +func logDepositInfoAndWaitForTxReceipt( + r *E2ERunner, + tx *ethtypes.Transaction, + name string, +) { + r.Logger.EVMTransaction(*tx, name) + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt, name+" failed") + + r.Logger.EVMReceipt(*receipt, name) + r.Logger.GatewayDeposit(r.GatewayEVM, *receipt, name) +} diff --git a/e2e/runner/legacy_evm.go b/e2e/runner/legacy_evm.go new file mode 100644 index 0000000000..e13ea924bb --- /dev/null +++ b/e2e/runner/legacy_evm.go @@ -0,0 +1,126 @@ +package runner + +import ( + "math/big" + + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/node/e2e/utils" +) + +// LegacyDepositERC20 sends ERC20 into ZEVM using legacy protocol contracts +func (r *E2ERunner) LegacyDepositERC20() ethcommon.Hash { + r.Logger.Print("⏳ depositing ERC20 into ZEVM") + + oneHundred := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(100)) + return r.LegacyDepositERC20WithAmountAndMessage(r.EVMAddress(), oneHundred, []byte{}) +} + +// LegacyDepositERC20WithAmountAndMessage sends ERC20 into ZEVM using legacy protocol contracts +func (r *E2ERunner) LegacyDepositERC20WithAmountAndMessage( + to ethcommon.Address, + amount *big.Int, + msg []byte, +) ethcommon.Hash { + // reset allowance, necessary for USDT + tx, err := r.ERC20.Approve(r.EVMAuth, r.ERC20CustodyAddr, big.NewInt(0)) + require.NoError(r, err) + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt) + + r.Logger.Info("ERC20 Approve receipt tx hash: %s", tx.Hash().Hex()) + + tx, err = r.ERC20.Approve(r.EVMAuth, r.ERC20CustodyAddr, amount) + require.NoError(r, err) + + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt) + + r.Logger.Info("ERC20 Approve receipt tx hash: %s", tx.Hash().Hex()) + + tx, err = r.ERC20Custody.Deposit(r.EVMAuth, to.Bytes(), r.ERC20Addr, amount, msg) + require.NoError(r, err) + + r.Logger.Info("TX: %v", tx) + + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt) + + r.Logger.Info("Deposit receipt tx hash: %s, status %d", receipt.TxHash.Hex(), receipt.Status) + for _, log := range receipt.Logs { + event, err := r.ERC20Custody.ParseDeposited(*log) + if err != nil { + continue + } + r.Logger.Info("Deposited event:") + r.Logger.Info(" Recipient address: %x", event.Recipient) + r.Logger.Info(" ERC20 address: %s", event.Asset.Hex()) + r.Logger.Info(" Amount: %d", event.Amount) + r.Logger.Info(" Message: %x", event.Message) + } + return tx.Hash() +} + +// LegacyDepositEther sends Ethers into ZEVM using legacy protocol contracts using legacy protocol contracts +func (r *E2ERunner) LegacyDepositEther() ethcommon.Hash { + amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(100)) // 100 eth + return r.LegacyDepositEtherWithAmount(amount) +} + +// LegacyDepositEtherWithAmount sends Ethers into ZEVM +func (r *E2ERunner) LegacyDepositEtherWithAmount(amount *big.Int) ethcommon.Hash { + r.Logger.Print("⏳ depositing Ethers into ZEVM") + + signedTx, err := r.LegacySendEther(r.TSSAddress, amount, nil) + require.NoError(r, err) + + r.Logger.EVMTransaction(*signedTx, "send to TSS") + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, signedTx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt, "deposit failed") + + r.Logger.EVMReceipt(*receipt, "send to TSS") + + return signedTx.Hash() +} + +// LegacySendEther sends ethers to the TSS on EVM using legacy protocol contracts +func (r *E2ERunner) LegacySendEther(_ ethcommon.Address, value *big.Int, data []byte) (*ethtypes.Transaction, error) { + evmClient := r.EVMClient + + nonce, err := evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) + if err != nil { + return nil, err + } + + gasLimit := uint64(30000) // in units + gasPrice, err := evmClient.SuggestGasPrice(r.Ctx) + if err != nil { + return nil, err + } + + tx := ethtypes.NewTransaction(nonce, r.TSSAddress, value, gasLimit, gasPrice, data) + chainID, err := evmClient.ChainID(r.Ctx) + if err != nil { + return nil, err + } + + deployerPrivkey, err := r.Account.PrivateKey() + if err != nil { + return nil, err + } + + signedTx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(chainID), deployerPrivkey) + if err != nil { + return nil, err + } + err = evmClient.SendTransaction(r.Ctx, signedTx) + if err != nil { + return nil, err + } + + return signedTx, nil +} diff --git a/e2e/runner/legacy_setup_evm.go b/e2e/runner/legacy_setup_evm.go new file mode 100644 index 0000000000..81f79dc006 --- /dev/null +++ b/e2e/runner/legacy_setup_evm.go @@ -0,0 +1,195 @@ +package runner + +import ( + "math/big" + "time" + + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/erc20custody.sol" + zetaeth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zeta.eth.sol" + zetaconnectoreth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.eth.sol" + + "github.com/zeta-chain/node/e2e/config" + "github.com/zeta-chain/node/e2e/contracts/erc20" + "github.com/zeta-chain/node/e2e/contracts/testdapp" + "github.com/zeta-chain/node/e2e/utils" + "github.com/zeta-chain/node/pkg/chains" + "github.com/zeta-chain/node/pkg/constant" + observertypes "github.com/zeta-chain/node/x/observer/types" +) + +const ( + ContractsConfigFile = "contracts.toml" +) + +// LegacySetEVMContractsFromConfig set legacy EVM contracts for e2e test from the config +func (r *E2ERunner) LegacySetEVMContractsFromConfig() { + conf, err := config.ReadConfig(ContractsConfigFile) + require.NoError(r, err) + + // Set ZetaEthAddr + r.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddr.String()) + r.ZetaEth, err = zetaeth.NewZetaEth(r.ZetaEthAddr, r.EVMClient) + require.NoError(r, err) + + // Set ConnectorEthAddr + r.ConnectorEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ConnectorEthAddr.String()) + r.ConnectorEth, err = zetaconnectoreth.NewZetaConnectorEth(r.ConnectorEthAddr, r.EVMClient) + require.NoError(r, err) +} + +// LegacySetupEVM setup legacy contracts on EVM for e2e test +func (r *E2ERunner) LegacySetupEVM(contractsDeployed bool, whitelistERC20 bool) { + r.Logger.Print("⚙️ setting up EVM network") + startTime := time.Now() + defer func() { + r.Logger.Info("EVM setup took %s\n", time.Since(startTime)) + }() + + // TODO: put this logic outside of this function + // We use this config to be consistent with the old implementation + // https://github.com/zeta-chain/node-private/issues/41 + if contractsDeployed { + r.LegacySetEVMContractsFromConfig() + return + } + conf := config.DefaultConfig() + + r.Logger.InfoLoud("Deploy ZetaETH ConnectorETH ERC20Custody ERC20\n") + + // donate to the TSS address to avoid account errors because deploying gas token ZRC20 will automatically mint + // gas token on ZetaChain to initialize the pool + txDonation, err := r.LegacySendEther(r.TSSAddress, big.NewInt(101000000000000000), []byte(constant.DonationMessage)) + require.NoError(r, err) + + r.Logger.Info("Deploying ZetaEth contract") + zetaEthAddr, txZetaEth, ZetaEth, err := zetaeth.DeployZetaEth( + r.EVMAuth, + r.EVMClient, + r.EVMAddress(), + big.NewInt(21_000_000_000), + ) + require.NoError(r, err) + + r.ZetaEth = ZetaEth + r.ZetaEthAddr = zetaEthAddr + conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(zetaEthAddr.String()) + r.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), txZetaEth.Hash()) + + r.Logger.Info("Deploying ZetaConnectorEth contract") + connectorEthAddr, txConnector, ConnectorEth, err := zetaconnectoreth.DeployZetaConnectorEth( + r.EVMAuth, + r.EVMClient, + zetaEthAddr, + r.TSSAddress, + r.EVMAddress(), + r.EVMAddress(), + ) + require.NoError(r, err) + + r.ConnectorEth = ConnectorEth + r.ConnectorEthAddr = connectorEthAddr + conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(connectorEthAddr.String()) + + r.Logger.Info( + "ZetaConnectorEth contract address: %s, tx hash: %s", + connectorEthAddr.Hex(), + txConnector.Hash().Hex(), + ) + + r.Logger.Info("Deploying ERC20Custody contract") + erc20CustodyAddr, txCustody, ERC20Custody, err := erc20custody.DeployERC20Custody( + r.EVMAuth, + r.EVMClient, + r.EVMAddress(), + r.EVMAddress(), + big.NewInt(0), + big.NewInt(1e18), + ethcommon.HexToAddress("0x"), + ) + require.NoError(r, err) + + r.ERC20CustodyAddr = erc20CustodyAddr + r.ERC20Custody = ERC20Custody + r.Logger.Info("ERC20Custody contract address: %s, tx hash: %s", erc20CustodyAddr.Hex(), txCustody.Hash().Hex()) + + r.Logger.Info("Deploying ERC20 contract") + erc20Addr, txERC20, erc20, err := erc20.DeployERC20(r.EVMAuth, r.EVMClient, "TESTERC20", "TESTERC20", 6) + require.NoError(r, err) + + r.ERC20 = erc20 + r.ERC20Addr = erc20Addr + r.Logger.Info("ERC20 contract address: %s, tx hash: %s", erc20Addr.Hex(), txERC20.Hash().Hex()) + + // deploy TestDApp contract + appAddr, txApp, _, err := testdapp.DeployTestDApp( + r.EVMAuth, + r.EVMClient, + r.ConnectorEthAddr, + r.ZetaEthAddr, + ) + require.NoError(r, err) + + r.EvmTestDAppAddr = appAddr + r.Logger.Info("TestDApp contract address: %s, tx hash: %s", appAddr.Hex(), txApp.Hash().Hex()) + + ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt, failMessage) + } + + // check contract deployment receipt + ensureTxReceipt(txDonation, "EVM donation tx failed") + ensureTxReceipt(txZetaEth, "ZetaEth deployment failed") + ensureTxReceipt(txConnector, "ZetaConnectorEth deployment failed") + ensureTxReceipt(txCustody, "ERC20Custody deployment failed") + ensureTxReceipt(txERC20, "ERC20 deployment failed") + ensureTxReceipt(txApp, "TestDApp deployment failed") + + // initialize custody contract + r.Logger.Info("Whitelist ERC20") + if whitelistERC20 { + txWhitelist, err := ERC20Custody.Whitelist(r.EVMAuth, erc20Addr) + require.NoError(r, err) + ensureTxReceipt(txWhitelist, "ERC20 whitelist failed") + } + + r.Logger.Info("Set TSS address") + txCustody, err = ERC20Custody.UpdateTSSAddress(r.EVMAuth, r.TSSAddress) + require.NoError(r, err) + + ensureTxReceipt(txCustody, "ERC20 update TSS address failed") + + r.Logger.Info("TSS set receipt tx hash: %s", txCustody.Hash().Hex()) + + // save config containing contract addresses + // TODO: put this logic outside of this function in a general config + // We use this config to be consistent with the old implementation + // https://github.com/zeta-chain/node-private/issues/41 + require.NoError(r, config.WriteConfig(ContractsConfigFile, conf)) + + // chain params will need to be updated if they do not match the default params + // this be required if the deployer account changes + currentChainParamsRes, err := r.ObserverClient.GetChainParamsForChain( + r.Ctx, + &observertypes.QueryGetChainParamsForChainRequest{ + ChainId: chains.GoerliLocalnet.ChainId, + }, + ) + require.NoError(r, err, "failed to get chain params for chain %d", chains.GoerliLocalnet.ChainId) + + chainParams := currentChainParamsRes.ChainParams + chainParams.Erc20CustodyContractAddress = r.ERC20CustodyAddr.Hex() + chainParams.ConnectorContractAddress = r.ConnectorEthAddr.Hex() + chainParams.ZetaTokenContractAddress = r.ZetaEthAddr.Hex() + + _, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), + chainParams, + )) + + require.NoError(r, err, "failed to update chain params") + r.Logger.Print("🔄 updated chain params") +} diff --git a/e2e/runner/legacy_zevm.go b/e2e/runner/legacy_zevm.go new file mode 100644 index 0000000000..7158c203d9 --- /dev/null +++ b/e2e/runner/legacy_zevm.go @@ -0,0 +1,189 @@ +package runner + +import ( + "math/big" + + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + zetaconnectoreth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.eth.sol" + connectorzevm "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/zetaconnectorzevm.sol" + + "github.com/zeta-chain/node/e2e/utils" +) + +// LegacySendZetaOnEvm sends ZETA to an address on EVM using legacy protocol contracts +// this allows the ZETA contract deployer to funds other accounts on EVM +func (r *E2ERunner) LegacySendZetaOnEvm(address ethcommon.Address, zetaAmount int64) *ethtypes.Transaction { + // the deployer might be sending ZETA in different goroutines + r.Lock() + defer r.Unlock() + + amount := big.NewInt(1e18) + amount = amount.Mul(amount, big.NewInt(zetaAmount)) + tx, err := r.ZetaEth.Transfer(r.EVMAuth, address, amount) + require.NoError(r, err) + + return tx +} + +// LegacyDepositZeta deposits ZETA on ZetaChain from the ZETA smart contract on EVM using legacy protocol contracts +func (r *E2ERunner) LegacyDepositZeta() ethcommon.Hash { + amount := big.NewInt(1e18) + amount = amount.Mul(amount, big.NewInt(100)) // 100 Zeta + + return r.LegacyDepositZetaWithAmount(r.EVMAddress(), amount) +} + +// LegacyDepositZetaWithAmount deposits ZETA on ZetaChain from the ZETA smart contract on EVM with the specified amount using legacy protocol contracts +func (r *E2ERunner) LegacyDepositZetaWithAmount(to ethcommon.Address, amount *big.Int) ethcommon.Hash { + tx, err := r.ZetaEth.Approve(r.EVMAuth, r.ConnectorEthAddr, amount) + require.NoError(r, err) + + r.Logger.Info("Approve tx hash: %s", tx.Hash().Hex()) + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.Logger.EVMReceipt(*receipt, "approve") + r.requireTxSuccessful(receipt, "approve tx failed") + + // query the chain ID using zevm client + zetaChainID, err := r.ZEVMClient.ChainID(r.Ctx) + require.NoError(r, err) + + tx, err = r.ConnectorEth.Send(r.EVMAuth, zetaconnectoreth.ZetaInterfacesSendInput{ + // TODO: allow user to specify destination chain id + // https://github.com/zeta-chain/node-private/issues/41 + DestinationChainId: zetaChainID, + DestinationAddress: to.Bytes(), + DestinationGasLimit: big.NewInt(250_000), + Message: nil, + ZetaValueAndGas: amount, + ZetaParams: nil, + }) + require.NoError(r, err) + + r.Logger.Info("Send tx hash: %s", tx.Hash().Hex()) + + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.Logger.EVMReceipt(*receipt, "send") + r.requireTxSuccessful(receipt, "send tx failed") + + r.Logger.Info(" Logs:") + for _, log := range receipt.Logs { + sentLog, err := r.ConnectorEth.ParseZetaSent(*log) + if err == nil { + r.Logger.Info(" Connector: %s", r.ConnectorEthAddr.String()) + r.Logger.Info(" Dest Addr: %s", ethcommon.BytesToAddress(sentLog.DestinationAddress).Hex()) + r.Logger.Info(" Dest Chain: %d", sentLog.DestinationChainId) + r.Logger.Info(" Dest Gas: %d", sentLog.DestinationGasLimit) + r.Logger.Info(" Zeta Value: %d", sentLog.ZetaValueAndGas) + r.Logger.Info(" Block Num: %d", log.BlockNumber) + } + } + + return tx.Hash() +} + +// LegacyDepositAndApproveWZeta deposits and approves WZETA on ZetaChain from the ZETA smart contract on ZEVM using legacy protocol contracts +func (r *E2ERunner) LegacyDepositAndApproveWZeta(amount *big.Int) { + r.ZEVMAuth.Value = amount + tx, err := r.WZeta.Deposit(r.ZEVMAuth) + require.NoError(r, err) + + r.ZEVMAuth.Value = big.NewInt(0) + r.Logger.Info("wzeta deposit tx hash: %s", tx.Hash().Hex()) + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.Logger.EVMReceipt(*receipt, "wzeta deposit") + r.requireTxSuccessful(receipt, "deposit failed") + + tx, err = r.WZeta.Approve(r.ZEVMAuth, r.ConnectorZEVMAddr, amount) + require.NoError(r, err) + + r.Logger.Info("wzeta approve tx hash: %s", tx.Hash().Hex()) + + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.Logger.EVMReceipt(*receipt, "wzeta approve") + r.requireTxSuccessful(receipt, "approve failed, logs: %+v", receipt.Logs) +} + +// LegacyWithdrawZeta withdraws ZETA from ZetaChain to the ZETA smart contract on EVM using legacy protocol contracts +// waitReceipt specifies whether to wait for the tx receipt and check if the tx was successful +func (r *E2ERunner) LegacyWithdrawZeta(amount *big.Int, waitReceipt bool) *ethtypes.Transaction { + chainID, err := r.EVMClient.ChainID(r.Ctx) + require.NoError(r, err) + + tx, err := r.ConnectorZEVM.Send(r.ZEVMAuth, connectorzevm.ZetaInterfacesSendInput{ + DestinationChainId: chainID, + DestinationAddress: r.EVMAddress().Bytes(), + DestinationGasLimit: big.NewInt(400_000), + Message: nil, + ZetaValueAndGas: amount, + ZetaParams: nil, + }) + require.NoError(r, err) + + r.Logger.Info("send tx hash: %s", tx.Hash().Hex()) + + if waitReceipt { + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.Logger.EVMReceipt(*receipt, "send") + r.requireTxSuccessful(receipt, "send failed, logs: %+v", receipt.Logs) + + r.Logger.Info(" Logs:") + for _, log := range receipt.Logs { + sentLog, err := r.ConnectorZEVM.ParseZetaSent(*log) + if err == nil { + r.Logger.Info(" Dest Addr: %s", ethcommon.BytesToAddress(sentLog.DestinationAddress).Hex()) + r.Logger.Info(" Dest Chain: %d", sentLog.DestinationChainId) + r.Logger.Info(" Dest Gas: %d", sentLog.DestinationGasLimit) + r.Logger.Info(" Zeta Value: %d", sentLog.ZetaValueAndGas) + } + } + } + + return tx +} + +// LegacyWithdrawEther withdraws Ether from ZetaChain to the ZETA smart contract on EVM using legacy protocol contracts +func (r *E2ERunner) LegacyWithdrawEther(amount *big.Int) *ethtypes.Transaction { + // withdraw + tx, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount) + require.NoError(r, err) + + r.Logger.EVMTransaction(*tx, "withdraw") + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt, "withdraw failed") + + r.Logger.EVMReceipt(*receipt, "withdraw") + r.Logger.ZRC20Withdrawal(r.ETHZRC20, *receipt, "withdraw") + + return tx +} + +// LegacyWithdrawERC20 withdraws an ERC20 token from ZetaChain to the ZETA smart contract on EVM using legacy protocol contracts +func (r *E2ERunner) LegacyWithdrawERC20(amount *big.Int) *ethtypes.Transaction { + tx, err := r.ERC20ZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount) + require.NoError(r, err) + + r.Logger.EVMTransaction(*tx, "withdraw") + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.Logger.Info("Receipt txhash %s status %d", receipt.TxHash, receipt.Status) + for _, log := range receipt.Logs { + event, err := r.ERC20ZRC20.ParseWithdrawal(*log) + if err != nil { + continue + } + r.Logger.Info( + " logs: from %s, to %x, value %d, gasfee %d", + event.From.Hex(), + event.To, + event.Value, + event.GasFee, + ) + } + + return tx +} diff --git a/e2e/runner/setup_evm.go b/e2e/runner/setup_evm.go index f14383356b..c5a0bcb500 100644 --- a/e2e/runner/setup_evm.go +++ b/e2e/runner/setup_evm.go @@ -4,192 +4,131 @@ import ( "math/big" "time" - ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/accounts/abi/bind" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" - "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/erc20custody.sol" - zetaeth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zeta.eth.sol" - zetaconnectoreth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.eth.sol" + erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol" + "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol" - "github.com/zeta-chain/node/e2e/config" - "github.com/zeta-chain/node/e2e/contracts/erc20" - "github.com/zeta-chain/node/e2e/contracts/testdapp" "github.com/zeta-chain/node/e2e/utils" - "github.com/zeta-chain/node/pkg/chains" "github.com/zeta-chain/node/pkg/constant" - observertypes "github.com/zeta-chain/node/x/observer/types" + "github.com/zeta-chain/node/pkg/contracts/erc1967proxy" + "github.com/zeta-chain/node/pkg/contracts/testdappv2" ) -const ( - ContractsConfigFile = "contracts.toml" -) - -// SetEVMContractsFromConfig set EVM contracts for e2e test from the config -func (r *E2ERunner) SetEVMContractsFromConfig() { - conf, err := config.ReadConfig(ContractsConfigFile) - require.NoError(r, err) - - // Set ZetaEthAddr - r.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddr.String()) - r.ZetaEth, err = zetaeth.NewZetaEth(r.ZetaEthAddr, r.EVMClient) - require.NoError(r, err) - - // Set ConnectorEthAddr - r.ConnectorEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ConnectorEthAddr.String()) - r.ConnectorEth, err = zetaconnectoreth.NewZetaConnectorEth(r.ConnectorEthAddr, r.EVMClient) - require.NoError(r, err) -} +// SetupEVM setup contracts on EVM with v2 contracts +func (r *E2ERunner) SetupEVM() { + ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt, failMessage) + } -// SetupEVM setup contracts on EVM for e2e test -func (r *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { - r.Logger.Print("⚙️ setting up EVM network") + r.Logger.Info("⚙️ setting up EVM v2 network") startTime := time.Now() defer func() { - r.Logger.Info("EVM setup took %s\n", time.Since(startTime)) + r.Logger.Info("EVM v2 setup took %s\n", time.Since(startTime)) }() - // TODO: put this logic outside of this function - // We use this config to be consistent with the old implementation - // https://github.com/zeta-chain/node-private/issues/41 - if contractsDeployed { - r.SetEVMContractsFromConfig() - return - } - conf := config.DefaultConfig() - - r.Logger.InfoLoud("Deploy ZetaETH ConnectorETH ERC20Custody ERC20\n") + r.Logger.InfoLoud("Deploy Gateway and ERC20Custody ERC20\n") // donate to the TSS address to avoid account errors because deploying gas token ZRC20 will automatically mint // gas token on ZetaChain to initialize the pool - txDonation, err := r.SendEther(r.TSSAddress, big.NewInt(101000000000000000), []byte(constant.DonationMessage)) + txDonation, err := r.LegacySendEther(r.TSSAddress, big.NewInt(101000000000000000), []byte(constant.DonationMessage)) require.NoError(r, err) - r.Logger.Info("Deploying ZetaEth contract") - zetaEthAddr, txZetaEth, ZetaEth, err := zetaeth.DeployZetaEth( - r.EVMAuth, - r.EVMClient, - r.EVMAddress(), - big.NewInt(21_000_000_000), - ) + r.Logger.Info("Deploying Gateway EVM") + gatewayEVMAddr, txGateway, _, err := gatewayevm.DeployGatewayEVM(r.EVMAuth, r.EVMClient) + require.NoError(r, err) + + ensureTxReceipt(txGateway, "Gateway deployment failed") + + gatewayEVMABI, err := gatewayevm.GatewayEVMMetaData.GetAbi() require.NoError(r, err) - r.ZetaEth = ZetaEth - r.ZetaEthAddr = zetaEthAddr - conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(zetaEthAddr.String()) - r.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), txZetaEth.Hash()) + // Encode the initializer data + initializerData, err := gatewayEVMABI.Pack("initialize", r.TSSAddress, r.ZetaEthAddr, r.Account.EVMAddress()) + require.NoError(r, err) - r.Logger.Info("Deploying ZetaConnectorEth contract") - connectorEthAddr, txConnector, ConnectorEth, err := zetaconnectoreth.DeployZetaConnectorEth( + // Deploy gateway proxy contract + gatewayProxyAddress, gatewayProxyTx, _, err := erc1967proxy.DeployERC1967Proxy( r.EVMAuth, r.EVMClient, - zetaEthAddr, - r.TSSAddress, - r.EVMAddress(), - r.EVMAddress(), + gatewayEVMAddr, + initializerData, ) require.NoError(r, err) - r.ConnectorEth = ConnectorEth - r.ConnectorEthAddr = connectorEthAddr - conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(connectorEthAddr.String()) - - r.Logger.Info( - "ZetaConnectorEth contract address: %s, tx hash: %s", - connectorEthAddr.Hex(), - txConnector.Hash().Hex(), - ) + r.GatewayEVMAddr = gatewayProxyAddress + r.GatewayEVM, err = gatewayevm.NewGatewayEVM(gatewayProxyAddress, r.EVMClient) + require.NoError(r, err) + r.Logger.Info("Gateway EVM contract address: %s, tx hash: %s", gatewayEVMAddr.Hex(), txGateway.Hash().Hex()) + // Deploy erc20custody proxy contract r.Logger.Info("Deploying ERC20Custody contract") - erc20CustodyAddr, txCustody, ERC20Custody, err := erc20custody.DeployERC20Custody( - r.EVMAuth, - r.EVMClient, - r.EVMAddress(), - r.EVMAddress(), - big.NewInt(0), - big.NewInt(1e18), - ethcommon.HexToAddress("0x"), - ) + erc20CustodyAddr, txCustody, _, err := erc20custodyv2.DeployERC20Custody(r.EVMAuth, r.EVMClient) require.NoError(r, err) - r.ERC20CustodyAddr = erc20CustodyAddr - r.ERC20Custody = ERC20Custody - r.Logger.Info("ERC20Custody contract address: %s, tx hash: %s", erc20CustodyAddr.Hex(), txCustody.Hash().Hex()) + ensureTxReceipt(txCustody, "ERC20Custody deployment failed") - r.Logger.Info("Deploying ERC20 contract") - erc20Addr, txERC20, erc20, err := erc20.DeployERC20(r.EVMAuth, r.EVMClient, "TESTERC20", "TESTERC20", 6) + erc20CustodyABI, err := erc20custodyv2.ERC20CustodyMetaData.GetAbi() require.NoError(r, err) - r.ERC20 = erc20 - r.ERC20Addr = erc20Addr - r.Logger.Info("ERC20 contract address: %s, tx hash: %s", erc20Addr.Hex(), txERC20.Hash().Hex()) + // Encode the initializer data + initializerData, err = erc20CustodyABI.Pack("initialize", r.GatewayEVMAddr, r.TSSAddress, r.Account.EVMAddress()) + require.NoError(r, err) - // deploy TestDApp contract - appAddr, txApp, _, err := testdapp.DeployTestDApp( + // Deploy erc20custody proxy contract + erc20CustodyProxyAddress, erc20ProxyTx, _, err := erc1967proxy.DeployERC1967Proxy( r.EVMAuth, r.EVMClient, - r.ConnectorEthAddr, - r.ZetaEthAddr, + erc20CustodyAddr, + initializerData, ) require.NoError(r, err) - r.EvmTestDAppAddr = appAddr - r.Logger.Info("TestDApp contract address: %s, tx hash: %s", appAddr.Hex(), txApp.Hash().Hex()) + r.ERC20CustodyV2Addr = erc20CustodyProxyAddress + r.ERC20CustodyV2, err = erc20custodyv2.NewERC20Custody(erc20CustodyProxyAddress, r.EVMClient) + require.NoError(r, err) + r.Logger.Info( + "ERC20CustodyV2 contract address: %s, tx hash: %s", + erc20CustodyAddr.Hex(), + txCustody.Hash().Hex(), + ) - ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt, failMessage) - } + ensureTxReceipt(txCustody, "ERC20CustodyV2 deployment failed") - // check contract deployment receipt - ensureTxReceipt(txDonation, "EVM donation tx failed") - ensureTxReceipt(txZetaEth, "ZetaEth deployment failed") - ensureTxReceipt(txConnector, "ZetaConnectorEth deployment failed") - ensureTxReceipt(txCustody, "ERC20Custody deployment failed") - ensureTxReceipt(txERC20, "ERC20 deployment failed") - ensureTxReceipt(txApp, "TestDApp deployment failed") - - // initialize custody contract - r.Logger.Info("Whitelist ERC20") - if whitelistERC20 { - txWhitelist, err := ERC20Custody.Whitelist(r.EVMAuth, erc20Addr) - require.NoError(r, err) - ensureTxReceipt(txWhitelist, "ERC20 whitelist failed") - } - - r.Logger.Info("Set TSS address") - txCustody, err = ERC20Custody.UpdateTSSAddress(r.EVMAuth, r.TSSAddress) + // set custody contract in gateway + txSetCustody, err := r.GatewayEVM.SetCustody(r.EVMAuth, erc20CustodyProxyAddress) require.NoError(r, err) - ensureTxReceipt(txCustody, "ERC20 update TSS address failed") + // deploy test dapp v2 + testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.EVMAuth, r.EVMClient, false) + require.NoError(r, err) - r.Logger.Info("TSS set receipt tx hash: %s", txCustody.Hash().Hex()) + r.TestDAppV2EVMAddr = testDAppV2Addr + r.TestDAppV2EVM, err = testdappv2.NewTestDAppV2(testDAppV2Addr, r.EVMClient) + require.NoError(r, err) - // save config containing contract addresses - // TODO: put this logic outside of this function in a general config - // We use this config to be consistent with the old implementation - // https://github.com/zeta-chain/node-private/issues/41 - require.NoError(r, config.WriteConfig(ContractsConfigFile, conf)) + // check contract deployment receipt + ensureTxReceipt(txDonation, "EVM donation tx failed") + ensureTxReceipt(gatewayProxyTx, "Gateway proxy deployment failed") + ensureTxReceipt(erc20ProxyTx, "ERC20Custody proxy deployment failed") + ensureTxReceipt(txSetCustody, "Set custody in Gateway failed") + ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed") - // chain params will need to be updated if they do not match the default params - // this be required if the deployer account changes - currentChainParamsRes, err := r.ObserverClient.GetChainParamsForChain( - r.Ctx, - &observertypes.QueryGetChainParamsForChainRequest{ - ChainId: chains.GoerliLocalnet.ChainId, - }, - ) - require.NoError(r, err, "failed to get chain params for chain %d", chains.GoerliLocalnet.ChainId) + // check isZetaChain is false + isZetaChain, err := r.TestDAppV2EVM.IsZetaChain(&bind.CallOpts{}) + require.NoError(r, err) + require.False(r, isZetaChain) - chainParams := currentChainParamsRes.ChainParams - chainParams.Erc20CustodyContractAddress = r.ERC20CustodyAddr.Hex() - chainParams.ConnectorContractAddress = r.ConnectorEthAddr.Hex() - chainParams.ZetaTokenContractAddress = r.ZetaEthAddr.Hex() + // whitelist the ERC20 + txWhitelist, err := r.ERC20CustodyV2.Whitelist(r.EVMAuth, r.ERC20Addr) + require.NoError(r, err) - _, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams( - r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), - chainParams, - )) + // set legacy supported (calling deposit directly in ERC20Custody) + txSetLegacySupported, err := r.ERC20CustodyV2.SetSupportsLegacy(r.EVMAuth, true) + require.NoError(r, err) - require.NoError(r, err, "failed to update chain params") - r.Logger.Print("🔄 updated chain params") + ensureTxReceipt(txWhitelist, "ERC20 whitelist failed") + ensureTxReceipt(txSetLegacySupported, "Set legacy support failed") } diff --git a/e2e/runner/setup_zeta.go b/e2e/runner/setup_zevm.go similarity index 69% rename from e2e/runner/setup_zeta.go rename to e2e/runner/setup_zevm.go index 56c803a376..310d580dd0 100644 --- a/e2e/runner/setup_zeta.go +++ b/e2e/runner/setup_zevm.go @@ -7,12 +7,14 @@ import ( "github.com/btcsuite/btcd/btcutil" "github.com/ethereum/go-ethereum/accounts/abi/bind" ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/systemcontract.sol" "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/wzeta.sol" connectorzevm "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/zetaconnectorzevm.sol" "github.com/zeta-chain/protocol-contracts/v1/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol" uniswapv2router "github.com/zeta-chain/protocol-contracts/v1/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol" + "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol" "github.com/zeta-chain/protocol-contracts/v2/pkg/zrc20.sol" "github.com/zeta-chain/node/e2e/contracts/contextapp" @@ -21,6 +23,8 @@ import ( "github.com/zeta-chain/node/e2e/txserver" e2eutils "github.com/zeta-chain/node/e2e/utils" "github.com/zeta-chain/node/pkg/chains" + "github.com/zeta-chain/node/pkg/contracts/erc1967proxy" + "github.com/zeta-chain/node/pkg/contracts/testdappv2" fungibletypes "github.com/zeta-chain/node/x/fungible/types" observertypes "github.com/zeta-chain/node/x/observer/types" ) @@ -276,3 +280,107 @@ func (r *E2ERunner) EnableHeaderVerification(chainIDList []int64) error { return r.ZetaTxServer.EnableHeaderVerification(e2eutils.AdminPolicyName, chainIDList) } + +// SetZEVMContractsV2 set contracts for the ZEVM +func (r *E2ERunner) SetZEVMContractsV2() { + ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { + receipt := e2eutils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt, failMessage+" tx hash: "+tx.Hash().Hex()) + } + + r.Logger.Print("⚙️ setting up ZEVM v2 network") + startTime := time.Now() + defer func() { + r.Logger.Info("ZEVM v2 network took %s\n", time.Since(startTime)) + }() + + r.Logger.Info("Deploying Gateway ZEVM") + gatewayZEVMAddr, txGateway, _, err := gatewayzevm.DeployGatewayZEVM(r.ZEVMAuth, r.ZEVMClient) + require.NoError(r, err) + + ensureTxReceipt(txGateway, "Gateway deployment failed") + + gatewayZEVMABI, err := gatewayzevm.GatewayZEVMMetaData.GetAbi() + require.NoError(r, err) + + // Encode the initializer data + initializerData, err := gatewayZEVMABI.Pack("initialize", r.WZetaAddr, r.Account.EVMAddress()) + require.NoError(r, err) + + // Deploy the proxy contract + r.Logger.Info( + "Deploying proxy with %s and %s, address: %s", + r.WZetaAddr.Hex(), + r.Account.EVMAddress().Hex(), + gatewayZEVMAddr.Hex(), + ) + proxyAddress, txProxy, _, err := erc1967proxy.DeployERC1967Proxy( + r.ZEVMAuth, + r.ZEVMClient, + gatewayZEVMAddr, + initializerData, + ) + require.NoError(r, err) + + r.GatewayZEVMAddr = proxyAddress + r.GatewayZEVM, err = gatewayzevm.NewGatewayZEVM(proxyAddress, r.ZEVMClient) + require.NoError(r, err) + r.Logger.Info("Gateway ZEVM contract address: %s, tx hash: %s", gatewayZEVMAddr.Hex(), txGateway.Hash().Hex()) + + // Set the gateway address in the protocol + err = r.ZetaTxServer.UpdateGatewayAddress(e2eutils.AdminPolicyName, r.GatewayZEVMAddr.Hex()) + require.NoError(r, err) + + // deploy test dapp v2 + testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.ZEVMAuth, r.ZEVMClient, true) + require.NoError(r, err) + + r.TestDAppV2ZEVMAddr = testDAppV2Addr + r.TestDAppV2ZEVM, err = testdappv2.NewTestDAppV2(testDAppV2Addr, r.ZEVMClient) + require.NoError(r, err) + + ensureTxReceipt(txProxy, "Gateway proxy deployment failed") + ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed") + + // check isZetaChain is true + isZetaChain, err := r.TestDAppV2ZEVM.IsZetaChain(&bind.CallOpts{}) + require.NoError(r, err) + require.True(r, isZetaChain) +} + +// UpdateChainParamsV2Contracts update the erc20 custody contract and gateway address in the chain params +// this operation is used when transitioning to new smart contract architecture where a new ERC20 custody contract is deployed +func (r *E2ERunner) UpdateChainParamsV2Contracts() { + res, err := r.ObserverClient.GetChainParams(r.Ctx, &observertypes.QueryGetChainParamsRequest{}) + require.NoError(r, err) + + evmChainID, err := r.EVMClient.ChainID(r.Ctx) + require.NoError(r, err) + + // find old chain params + var ( + chainParams *observertypes.ChainParams + found bool + ) + for _, cp := range res.ChainParams.ChainParams { + if cp.ChainId == evmChainID.Int64() { + chainParams = cp + found = true + break + } + } + require.True(r, found, "Chain params not found for chain id %d", evmChainID) + + // update with the new ERC20 custody contract address + chainParams.Erc20CustodyContractAddress = r.ERC20CustodyV2Addr.Hex() + + // update with the new gateway address + chainParams.GatewayAddress = r.GatewayEVMAddr.Hex() + + // update the chain params + _, err = r.ZetaTxServer.BroadcastTx(e2eutils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams( + r.ZetaTxServer.MustGetAccountAddressFromName(e2eutils.OperationalPolicyName), + chainParams, + )) + require.NoError(r, err) +} diff --git a/e2e/runner/v2_upgrade.go b/e2e/runner/upgrade.go similarity index 98% rename from e2e/runner/v2_upgrade.go rename to e2e/runner/upgrade.go index eb5af7f860..651a0750b1 100644 --- a/e2e/runner/v2_upgrade.go +++ b/e2e/runner/upgrade.go @@ -56,7 +56,7 @@ func (r *E2ERunner) UpgradeGatewayEVM() { ensureTxReceipt(txUpgrade, "GatewayEVM upgrade failed") } -// UpgradeERC20CustodyZEVM upgrades the ERC20Custody contract +// UpgradeERC20Custody upgrades the ERC20Custody contract func (r *E2ERunner) UpgradeERC20Custody() { ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) diff --git a/e2e/runner/v2_evm.go b/e2e/runner/v2_evm.go deleted file mode 100644 index 105387d2ab..0000000000 --- a/e2e/runner/v2_evm.go +++ /dev/null @@ -1,117 +0,0 @@ -package runner - -import ( - "math/big" - - ethcommon "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol" - - "github.com/zeta-chain/node/e2e/utils" -) - -// V2ETHDeposit calls Deposit of Gateway with gas token on EVM -func (r *E2ERunner) V2ETHDeposit( - receiver ethcommon.Address, - amount *big.Int, - revertOptions gatewayevm.RevertOptions, -) *ethtypes.Transaction { - // set the value of the transaction - previousValue := r.EVMAuth.Value - defer func() { - r.EVMAuth.Value = previousValue - }() - r.EVMAuth.Value = amount - - tx, err := r.GatewayEVM.Deposit0(r.EVMAuth, receiver, revertOptions) - require.NoError(r, err) - - logDepositInfoAndWaitForTxReceipt(r, tx, "eth_deposit") - - return tx -} - -// V2ETHDepositAndCall calls DepositAndCall of Gateway with gas token on EVM -func (r *E2ERunner) V2ETHDepositAndCall( - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayevm.RevertOptions, -) *ethtypes.Transaction { - // set the value of the transaction - previousValue := r.EVMAuth.Value - defer func() { - r.EVMAuth.Value = previousValue - }() - r.EVMAuth.Value = amount - - tx, err := r.GatewayEVM.DepositAndCall(r.EVMAuth, receiver, payload, revertOptions) - require.NoError(r, err) - - logDepositInfoAndWaitForTxReceipt(r, tx, "eth_deposit_and_call") - - return tx -} - -// V2ERC20Deposit calls Deposit of Gateway with erc20 token on EVM -func (r *E2ERunner) V2ERC20Deposit( - receiver ethcommon.Address, - amount *big.Int, - revertOptions gatewayevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayEVM.Deposit(r.EVMAuth, receiver, amount, r.ERC20Addr, revertOptions) - require.NoError(r, err) - - logDepositInfoAndWaitForTxReceipt(r, tx, "erc20_deposit") - - return tx -} - -// V2ERC20DepositAndCall calls DepositAndCall of Gateway with erc20 token on EVM -func (r *E2ERunner) V2ERC20DepositAndCall( - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayEVM.DepositAndCall0( - r.EVMAuth, - receiver, - amount, - r.ERC20Addr, - payload, - revertOptions, - ) - require.NoError(r, err) - - logDepositInfoAndWaitForTxReceipt(r, tx, "erc20_deposit_and_call") - - return tx -} - -// V2EVMToZEMVCall calls Call of Gateway on EVM -func (r *E2ERunner) V2EVMToZEMVCall( - receiver ethcommon.Address, - payload []byte, - revertOptions gatewayevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayEVM.Call(r.EVMAuth, receiver, payload, revertOptions) - require.NoError(r, err) - - return tx -} - -func logDepositInfoAndWaitForTxReceipt( - r *E2ERunner, - tx *ethtypes.Transaction, - name string, -) { - r.Logger.EVMTransaction(*tx, name) - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt, name+" failed") - - r.Logger.EVMReceipt(*receipt, name) - r.Logger.GatewayDeposit(r.GatewayEVM, *receipt, name) -} diff --git a/e2e/runner/v2_setup_evm.go b/e2e/runner/v2_setup_evm.go deleted file mode 100644 index 8545302fd3..0000000000 --- a/e2e/runner/v2_setup_evm.go +++ /dev/null @@ -1,134 +0,0 @@ -package runner - -import ( - "math/big" - "time" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol" - "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol" - - "github.com/zeta-chain/node/e2e/utils" - "github.com/zeta-chain/node/pkg/constant" - "github.com/zeta-chain/node/pkg/contracts/erc1967proxy" - "github.com/zeta-chain/node/pkg/contracts/testdappv2" -) - -// SetupEVMV2 setup contracts on EVM with v2 contracts -func (r *E2ERunner) SetupEVMV2() { - ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt, failMessage) - } - - r.Logger.Info("⚙️ setting up EVM v2 network") - startTime := time.Now() - defer func() { - r.Logger.Info("EVM v2 setup took %s\n", time.Since(startTime)) - }() - - r.Logger.InfoLoud("Deploy Gateway and ERC20Custody ERC20\n") - - // donate to the TSS address to avoid account errors because deploying gas token ZRC20 will automatically mint - // gas token on ZetaChain to initialize the pool - txDonation, err := r.SendEther(r.TSSAddress, big.NewInt(101000000000000000), []byte(constant.DonationMessage)) - require.NoError(r, err) - - r.Logger.Info("Deploying Gateway EVM") - gatewayEVMAddr, txGateway, _, err := gatewayevm.DeployGatewayEVM(r.EVMAuth, r.EVMClient) - require.NoError(r, err) - - ensureTxReceipt(txGateway, "Gateway deployment failed") - - gatewayEVMABI, err := gatewayevm.GatewayEVMMetaData.GetAbi() - require.NoError(r, err) - - // Encode the initializer data - initializerData, err := gatewayEVMABI.Pack("initialize", r.TSSAddress, r.ZetaEthAddr, r.Account.EVMAddress()) - require.NoError(r, err) - - // Deploy gateway proxy contract - gatewayProxyAddress, gatewayProxyTx, _, err := erc1967proxy.DeployERC1967Proxy( - r.EVMAuth, - r.EVMClient, - gatewayEVMAddr, - initializerData, - ) - require.NoError(r, err) - - r.GatewayEVMAddr = gatewayProxyAddress - r.GatewayEVM, err = gatewayevm.NewGatewayEVM(gatewayProxyAddress, r.EVMClient) - require.NoError(r, err) - r.Logger.Info("Gateway EVM contract address: %s, tx hash: %s", gatewayEVMAddr.Hex(), txGateway.Hash().Hex()) - - // Deploy erc20custody proxy contract - r.Logger.Info("Deploying ERC20Custody contract") - erc20CustodyAddr, txCustody, _, err := erc20custodyv2.DeployERC20Custody(r.EVMAuth, r.EVMClient) - require.NoError(r, err) - - ensureTxReceipt(txCustody, "ERC20Custody deployment failed") - - erc20CustodyABI, err := erc20custodyv2.ERC20CustodyMetaData.GetAbi() - require.NoError(r, err) - - // Encode the initializer data - initializerData, err = erc20CustodyABI.Pack("initialize", r.GatewayEVMAddr, r.TSSAddress, r.Account.EVMAddress()) - require.NoError(r, err) - - // Deploy erc20custody proxy contract - erc20CustodyProxyAddress, erc20ProxyTx, _, err := erc1967proxy.DeployERC1967Proxy( - r.EVMAuth, - r.EVMClient, - erc20CustodyAddr, - initializerData, - ) - require.NoError(r, err) - - r.ERC20CustodyV2Addr = erc20CustodyProxyAddress - r.ERC20CustodyV2, err = erc20custodyv2.NewERC20Custody(erc20CustodyProxyAddress, r.EVMClient) - require.NoError(r, err) - r.Logger.Info( - "ERC20CustodyV2 contract address: %s, tx hash: %s", - erc20CustodyAddr.Hex(), - txCustody.Hash().Hex(), - ) - - ensureTxReceipt(txCustody, "ERC20CustodyV2 deployment failed") - - // set custody contract in gateway - txSetCustody, err := r.GatewayEVM.SetCustody(r.EVMAuth, erc20CustodyProxyAddress) - require.NoError(r, err) - - // deploy test dapp v2 - testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.EVMAuth, r.EVMClient, false) - require.NoError(r, err) - - r.TestDAppV2EVMAddr = testDAppV2Addr - r.TestDAppV2EVM, err = testdappv2.NewTestDAppV2(testDAppV2Addr, r.EVMClient) - require.NoError(r, err) - - // check contract deployment receipt - ensureTxReceipt(txDonation, "EVM donation tx failed") - ensureTxReceipt(gatewayProxyTx, "Gateway proxy deployment failed") - ensureTxReceipt(erc20ProxyTx, "ERC20Custody proxy deployment failed") - ensureTxReceipt(txSetCustody, "Set custody in Gateway failed") - ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed") - - // check isZetaChain is false - isZetaChain, err := r.TestDAppV2EVM.IsZetaChain(&bind.CallOpts{}) - require.NoError(r, err) - require.False(r, isZetaChain) - - // whitelist the ERC20 - txWhitelist, err := r.ERC20CustodyV2.Whitelist(r.EVMAuth, r.ERC20Addr) - require.NoError(r, err) - - // set legacy supported (calling deposit directly in ERC20Custody) - txSetLegacySupported, err := r.ERC20CustodyV2.SetSupportsLegacy(r.EVMAuth, true) - require.NoError(r, err) - - ensureTxReceipt(txWhitelist, "ERC20 whitelist failed") - ensureTxReceipt(txSetLegacySupported, "Set legacy support failed") -} diff --git a/e2e/runner/v2_setup_zeta.go b/e2e/runner/v2_setup_zeta.go deleted file mode 100644 index 69f16e2658..0000000000 --- a/e2e/runner/v2_setup_zeta.go +++ /dev/null @@ -1,119 +0,0 @@ -package runner - -import ( - "time" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol" - - "github.com/zeta-chain/node/e2e/utils" - "github.com/zeta-chain/node/pkg/contracts/erc1967proxy" - "github.com/zeta-chain/node/pkg/contracts/testdappv2" - observertypes "github.com/zeta-chain/node/x/observer/types" -) - -// SetZEVMContractsV2 set contracts for the ZEVM -func (r *E2ERunner) SetZEVMContractsV2() { - ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) { - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt, failMessage+" tx hash: "+tx.Hash().Hex()) - } - - r.Logger.Print("⚙️ setting up ZEVM v2 network") - startTime := time.Now() - defer func() { - r.Logger.Info("ZEVM v2 network took %s\n", time.Since(startTime)) - }() - - r.Logger.Info("Deploying Gateway ZEVM") - gatewayZEVMAddr, txGateway, _, err := gatewayzevm.DeployGatewayZEVM(r.ZEVMAuth, r.ZEVMClient) - require.NoError(r, err) - - ensureTxReceipt(txGateway, "Gateway deployment failed") - - gatewayZEVMABI, err := gatewayzevm.GatewayZEVMMetaData.GetAbi() - require.NoError(r, err) - - // Encode the initializer data - initializerData, err := gatewayZEVMABI.Pack("initialize", r.WZetaAddr, r.Account.EVMAddress()) - require.NoError(r, err) - - // Deploy the proxy contract - r.Logger.Info( - "Deploying proxy with %s and %s, address: %s", - r.WZetaAddr.Hex(), - r.Account.EVMAddress().Hex(), - gatewayZEVMAddr.Hex(), - ) - proxyAddress, txProxy, _, err := erc1967proxy.DeployERC1967Proxy( - r.ZEVMAuth, - r.ZEVMClient, - gatewayZEVMAddr, - initializerData, - ) - require.NoError(r, err) - - r.GatewayZEVMAddr = proxyAddress - r.GatewayZEVM, err = gatewayzevm.NewGatewayZEVM(proxyAddress, r.ZEVMClient) - require.NoError(r, err) - r.Logger.Info("Gateway ZEVM contract address: %s, tx hash: %s", gatewayZEVMAddr.Hex(), txGateway.Hash().Hex()) - - // Set the gateway address in the protocol - err = r.ZetaTxServer.UpdateGatewayAddress(utils.AdminPolicyName, r.GatewayZEVMAddr.Hex()) - require.NoError(r, err) - - // deploy test dapp v2 - testDAppV2Addr, txTestDAppV2, _, err := testdappv2.DeployTestDAppV2(r.ZEVMAuth, r.ZEVMClient, true) - require.NoError(r, err) - - r.TestDAppV2ZEVMAddr = testDAppV2Addr - r.TestDAppV2ZEVM, err = testdappv2.NewTestDAppV2(testDAppV2Addr, r.ZEVMClient) - require.NoError(r, err) - - ensureTxReceipt(txProxy, "Gateway proxy deployment failed") - ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed") - - // check isZetaChain is true - isZetaChain, err := r.TestDAppV2ZEVM.IsZetaChain(&bind.CallOpts{}) - require.NoError(r, err) - require.True(r, isZetaChain) -} - -// UpdateChainParamsV2Contracts update the erc20 custody contract and gateway address in the chain params -// this operation is used when transitioning to new smart contract architecture where a new ERC20 custody contract is deployed -func (r *E2ERunner) UpdateChainParamsV2Contracts() { - res, err := r.ObserverClient.GetChainParams(r.Ctx, &observertypes.QueryGetChainParamsRequest{}) - require.NoError(r, err) - - evmChainID, err := r.EVMClient.ChainID(r.Ctx) - require.NoError(r, err) - - // find old chain params - var ( - chainParams *observertypes.ChainParams - found bool - ) - for _, cp := range res.ChainParams.ChainParams { - if cp.ChainId == evmChainID.Int64() { - chainParams = cp - found = true - break - } - } - require.True(r, found, "Chain params not found for chain id %d", evmChainID) - - // update with the new ERC20 custody contract address - chainParams.Erc20CustodyContractAddress = r.ERC20CustodyV2Addr.Hex() - - // update with the new gateway address - chainParams.GatewayAddress = r.GatewayEVMAddr.Hex() - - // update the chain params - _, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams( - r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), - chainParams, - )) - require.NoError(r, err) -} diff --git a/e2e/runner/v2_zevm.go b/e2e/runner/v2_zevm.go deleted file mode 100644 index 4f6f299db2..0000000000 --- a/e2e/runner/v2_zevm.go +++ /dev/null @@ -1,243 +0,0 @@ -package runner - -import ( - "math/big" - - ethcommon "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol" - - gatewayzevmcaller "github.com/zeta-chain/node/pkg/contracts/gatewayzevmcaller" -) - -var gasLimit = big.NewInt(250000) - -// V2ETHWithdraw calls Withdraw of Gateway with gas token on ZEVM -func (r *E2ERunner) V2ETHWithdraw( - receiver ethcommon.Address, - amount *big.Int, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayZEVM.Withdraw( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ETHZRC20Addr, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ETHWithdrawAndArbitraryCall calls WithdrawAndCall of Gateway with gas token on ZEVM using arbitrary call -func (r *E2ERunner) V2ETHWithdrawAndArbitraryCall( - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayZEVM.WithdrawAndCall0( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ETHZRC20Addr, - payload, - gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: true}, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ETHWithdrawAndCall calls WithdrawAndCall of Gateway with gas token on ZEVM using authenticated call -func (r *E2ERunner) V2ETHWithdrawAndCall( - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayZEVM.WithdrawAndCall0( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ETHZRC20Addr, - payload, - gatewayzevm.CallOptions{ - IsArbitraryCall: false, - GasLimit: gasLimit, - }, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ETHWithdrawAndCallThroughContract calls WithdrawAndCall of Gateway with gas token on ZEVM using authenticated call -// through contract -func (r *E2ERunner) V2ETHWithdrawAndCallThroughContract( - gatewayZEVMCaller *gatewayzevmcaller.GatewayZEVMCaller, - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayzevmcaller.RevertOptions, -) *ethtypes.Transaction { - tx, err := gatewayZEVMCaller.WithdrawAndCallGatewayZEVM( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ETHZRC20Addr, - payload, - gatewayzevmcaller.CallOptions{ - IsArbitraryCall: false, - GasLimit: gasLimit, - }, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ERC20Withdraw calls Withdraw of Gateway with erc20 token on ZEVM -func (r *E2ERunner) V2ERC20Withdraw( - receiver ethcommon.Address, - amount *big.Int, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayZEVM.Withdraw( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ERC20ZRC20Addr, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ERC20WithdrawAndArbitraryCall calls WithdrawAndCall of Gateway with erc20 token on ZEVM using arbitrary call -func (r *E2ERunner) V2ERC20WithdrawAndArbitraryCall( - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - // this function take more gas than default 500k - // so we need to increase the gas limit - previousGasLimit := r.ZEVMAuth.GasLimit - r.ZEVMAuth.GasLimit = 10000000 - defer func() { - r.ZEVMAuth.GasLimit = previousGasLimit - }() - - tx, err := r.GatewayZEVM.WithdrawAndCall0( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ERC20ZRC20Addr, - payload, - gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: true}, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ERC20WithdrawAndCall calls WithdrawAndCall of Gateway with erc20 token on ZEVM using authenticated call -func (r *E2ERunner) V2ERC20WithdrawAndCall( - receiver ethcommon.Address, - amount *big.Int, - payload []byte, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - // this function take more gas than default 500k - // so we need to increase the gas limit - previousGasLimit := r.ZEVMAuth.GasLimit - r.ZEVMAuth.GasLimit = 10000000 - defer func() { - r.ZEVMAuth.GasLimit = previousGasLimit - }() - - tx, err := r.GatewayZEVM.WithdrawAndCall0( - r.ZEVMAuth, - receiver.Bytes(), - amount, - r.ERC20ZRC20Addr, - payload, - gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: false}, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ZEVMToEMVArbitraryCall calls Call of Gateway on ZEVM using arbitrary call -func (r *E2ERunner) V2ZEVMToEMVArbitraryCall( - receiver ethcommon.Address, - payload []byte, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayZEVM.Call( - r.ZEVMAuth, - receiver.Bytes(), - r.ETHZRC20Addr, - payload, - gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: true}, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ZEVMToEMVCall calls authenticated Call of Gateway on ZEVM using authenticated call -func (r *E2ERunner) V2ZEVMToEMVCall( - receiver ethcommon.Address, - payload []byte, - revertOptions gatewayzevm.RevertOptions, -) *ethtypes.Transaction { - tx, err := r.GatewayZEVM.Call( - r.ZEVMAuth, - receiver.Bytes(), - r.ETHZRC20Addr, - payload, - gatewayzevm.CallOptions{ - GasLimit: gasLimit, - IsArbitraryCall: false, - }, - revertOptions, - ) - require.NoError(r, err) - - return tx -} - -// V2ZEVMToEMVCallThroughContract calls authenticated Call of Gateway on ZEVM through contract using authenticated call -func (r *E2ERunner) V2ZEVMToEMVCallThroughContract( - gatewayZEVMCaller *gatewayzevmcaller.GatewayZEVMCaller, - receiver ethcommon.Address, - payload []byte, - revertOptions gatewayzevmcaller.RevertOptions, -) *ethtypes.Transaction { - tx, err := gatewayZEVMCaller.CallGatewayZEVM( - r.ZEVMAuth, - receiver.Bytes(), - r.ETHZRC20Addr, - payload, - gatewayzevmcaller.CallOptions{ - GasLimit: gasLimit, - IsArbitraryCall: false, - }, - revertOptions, - ) - require.NoError(r, err) - - return tx -} diff --git a/e2e/runner/zeta.go b/e2e/runner/zeta.go deleted file mode 100644 index fe55c3946c..0000000000 --- a/e2e/runner/zeta.go +++ /dev/null @@ -1,352 +0,0 @@ -package runner - -import ( - "fmt" - "math/big" - "time" - - "github.com/cenkalti/backoff/v4" - query "github.com/cosmos/cosmos-sdk/types/query" - ethcommon "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" - zetaconnectoreth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.eth.sol" - connectorzevm "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/zetaconnectorzevm.sol" - - "github.com/zeta-chain/node/e2e/utils" - "github.com/zeta-chain/node/pkg/chains" - "github.com/zeta-chain/node/pkg/coin" - "github.com/zeta-chain/node/pkg/retry" - "github.com/zeta-chain/node/x/crosschain/types" - observertypes "github.com/zeta-chain/node/x/observer/types" -) - -// WaitForBlocks waits for a specific number of blocks to be generated -// The parameter n is the number of blocks to wait for -func (r *E2ERunner) WaitForBlocks(n int64) { - height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{}) - if err != nil { - return - } - call := func() error { - return retry.Retry(r.waitForBlock(height.Height + n)) - } - - bo := backoff.NewConstantBackOff(time.Second * 5) - boWithMaxRetries := backoff.WithMaxRetries(bo, 10) - err = retry.DoWithBackoff(call, boWithMaxRetries) - require.NoError(r, err, "failed to wait for %d blocks", n) -} - -// WaitForTSSGeneration waits for a specific number of TSS to be generated -// The parameter n is the number of TSS to wait for -func (r *E2ERunner) WaitForTSSGeneration(tssNumber int64) { - call := func() error { - return retry.Retry(r.checkNumberOfTSSGenerated(tssNumber)) - } - bo := backoff.NewConstantBackOff(time.Second * 5) - boWithMaxRetries := backoff.WithMaxRetries(bo, 10) - err := retry.DoWithBackoff(call, boWithMaxRetries) - require.NoError(r, err, "failed to wait for %d tss generation", tssNumber) -} - -// checkNumberOfTSSGenerated checks the number of TSS generated -// if the number of tss is less that the `tssNumber` provided we return an error -func (r *E2ERunner) checkNumberOfTSSGenerated(tssNumber int64) error { - tssList, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{}) - if err != nil { - return err - } - if int64(len(tssList.TssList)) < tssNumber { - return fmt.Errorf("waiting for %d tss generation, number of TSS :%d", tssNumber, len(tssList.TssList)) - } - return nil -} - -func (r *E2ERunner) waitForBlock(n int64) error { - height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{}) - if err != nil { - return err - } - if height.Height < n { - return fmt.Errorf("waiting for %d blocks, current height %d", n, height.Height) - } - return nil -} - -// WaitForTxReceiptOnZEVM waits for a tx receipt on ZEVM -func (r *E2ERunner) WaitForTxReceiptOnZEVM(tx *ethtypes.Transaction) { - r.Lock() - defer r.Unlock() - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt) -} - -// WaitForMinedCCTX waits for a cctx to be mined from a tx -func (r *E2ERunner) WaitForMinedCCTX(txHash ethcommon.Hash) { - r.Lock() - defer r.Unlock() - - cctx := utils.WaitCctxMinedByInboundHash( - r.Ctx, - txHash.Hex(), - r.CctxClient, - r.Logger, - r.CctxTimeout, - ) - utils.RequireCCTXStatus(r, cctx, types.CctxStatus_OutboundMined) -} - -// WaitForMinedCCTXFromIndex waits for a cctx to be mined from its index -func (r *E2ERunner) WaitForMinedCCTXFromIndex(index string) *types.CrossChainTx { - return r.waitForMinedCCTXFromIndex(index, types.CctxStatus_OutboundMined) -} - -func (r *E2ERunner) waitForMinedCCTXFromIndex(index string, status types.CctxStatus) *types.CrossChainTx { - r.Lock() - defer r.Unlock() - - cctx := utils.WaitCCTXMinedByIndex(r.Ctx, index, r.CctxClient, r.Logger, r.CctxTimeout) - utils.RequireCCTXStatus(r, cctx, status) - - return cctx -} - -// WaitForSpecificCCTX scans for cctx by filters and ensures it's mined -func (r *E2ERunner) WaitForSpecificCCTX( - filter func(*types.CrossChainTx) bool, - status types.CctxStatus, - timeout time.Duration, -) *types.CrossChainTx { - var ( - ctx = r.Ctx - start = time.Now() - reqQuery = &types.QueryAllCctxRequest{ - Pagination: &query.PageRequest{Reverse: true}, - } - ) - - for time.Since(start) < timeout { - res, err := r.CctxClient.CctxAll(ctx, reqQuery) - require.NoError(r, err) - - for i := range res.CrossChainTx { - tx := res.CrossChainTx[i] - if filter(tx) { - return r.waitForMinedCCTXFromIndex(tx.Index, status) - } - } - - time.Sleep(time.Second) - } - - r.Logger.Error("WaitForSpecificCCTX: No CCTX found. Timed out") - r.FailNow() - - return nil -} - -// SendZetaOnEvm sends ZETA to an address on EVM -// this allows the ZETA contract deployer to funds other accounts on EVM -func (r *E2ERunner) SendZetaOnEvm(address ethcommon.Address, zetaAmount int64) *ethtypes.Transaction { - // the deployer might be sending ZETA in different goroutines - r.Lock() - defer r.Unlock() - - amount := big.NewInt(1e18) - amount = amount.Mul(amount, big.NewInt(zetaAmount)) - tx, err := r.ZetaEth.Transfer(r.EVMAuth, address, amount) - require.NoError(r, err) - - return tx -} - -// DepositZeta deposits ZETA on ZetaChain from the ZETA smart contract on EVM -func (r *E2ERunner) DepositZeta() ethcommon.Hash { - amount := big.NewInt(1e18) - amount = amount.Mul(amount, big.NewInt(100)) // 100 Zeta - - return r.DepositZetaWithAmount(r.EVMAddress(), amount) -} - -// DepositZetaWithAmount deposits ZETA on ZetaChain from the ZETA smart contract on EVM with the specified amount -func (r *E2ERunner) DepositZetaWithAmount(to ethcommon.Address, amount *big.Int) ethcommon.Hash { - tx, err := r.ZetaEth.Approve(r.EVMAuth, r.ConnectorEthAddr, amount) - require.NoError(r, err) - - r.Logger.Info("Approve tx hash: %s", tx.Hash().Hex()) - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.EVMReceipt(*receipt, "approve") - r.requireTxSuccessful(receipt, "approve tx failed") - - // query the chain ID using zevm client - zetaChainID, err := r.ZEVMClient.ChainID(r.Ctx) - require.NoError(r, err) - - tx, err = r.ConnectorEth.Send(r.EVMAuth, zetaconnectoreth.ZetaInterfacesSendInput{ - // TODO: allow user to specify destination chain id - // https://github.com/zeta-chain/node-private/issues/41 - DestinationChainId: zetaChainID, - DestinationAddress: to.Bytes(), - DestinationGasLimit: big.NewInt(250_000), - Message: nil, - ZetaValueAndGas: amount, - ZetaParams: nil, - }) - require.NoError(r, err) - - r.Logger.Info("Send tx hash: %s", tx.Hash().Hex()) - - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.EVMReceipt(*receipt, "send") - r.requireTxSuccessful(receipt, "send tx failed") - - r.Logger.Info(" Logs:") - for _, log := range receipt.Logs { - sentLog, err := r.ConnectorEth.ParseZetaSent(*log) - if err == nil { - r.Logger.Info(" Connector: %s", r.ConnectorEthAddr.String()) - r.Logger.Info(" Dest Addr: %s", ethcommon.BytesToAddress(sentLog.DestinationAddress).Hex()) - r.Logger.Info(" Dest Chain: %d", sentLog.DestinationChainId) - r.Logger.Info(" Dest Gas: %d", sentLog.DestinationGasLimit) - r.Logger.Info(" Zeta Value: %d", sentLog.ZetaValueAndGas) - r.Logger.Info(" Block Num: %d", log.BlockNumber) - } - } - - return tx.Hash() -} - -// DepositAndApproveWZeta deposits and approves WZETA on ZetaChain from the ZETA smart contract on ZEVM -func (r *E2ERunner) DepositAndApproveWZeta(amount *big.Int) { - r.ZEVMAuth.Value = amount - tx, err := r.WZeta.Deposit(r.ZEVMAuth) - require.NoError(r, err) - - r.ZEVMAuth.Value = big.NewInt(0) - r.Logger.Info("wzeta deposit tx hash: %s", tx.Hash().Hex()) - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.EVMReceipt(*receipt, "wzeta deposit") - r.requireTxSuccessful(receipt, "deposit failed") - - tx, err = r.WZeta.Approve(r.ZEVMAuth, r.ConnectorZEVMAddr, amount) - require.NoError(r, err) - - r.Logger.Info("wzeta approve tx hash: %s", tx.Hash().Hex()) - - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.EVMReceipt(*receipt, "wzeta approve") - r.requireTxSuccessful(receipt, "approve failed, logs: %+v", receipt.Logs) -} - -// WithdrawZeta withdraws ZETA from ZetaChain to the ZETA smart contract on EVM -// waitReceipt specifies whether to wait for the tx receipt and check if the tx was successful -func (r *E2ERunner) WithdrawZeta(amount *big.Int, waitReceipt bool) *ethtypes.Transaction { - chainID, err := r.EVMClient.ChainID(r.Ctx) - require.NoError(r, err) - - tx, err := r.ConnectorZEVM.Send(r.ZEVMAuth, connectorzevm.ZetaInterfacesSendInput{ - DestinationChainId: chainID, - DestinationAddress: r.EVMAddress().Bytes(), - DestinationGasLimit: big.NewInt(400_000), - Message: nil, - ZetaValueAndGas: amount, - ZetaParams: nil, - }) - require.NoError(r, err) - - r.Logger.Info("send tx hash: %s", tx.Hash().Hex()) - - if waitReceipt { - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.EVMReceipt(*receipt, "send") - r.requireTxSuccessful(receipt, "send failed, logs: %+v", receipt.Logs) - - r.Logger.Info(" Logs:") - for _, log := range receipt.Logs { - sentLog, err := r.ConnectorZEVM.ParseZetaSent(*log) - if err == nil { - r.Logger.Info(" Dest Addr: %s", ethcommon.BytesToAddress(sentLog.DestinationAddress).Hex()) - r.Logger.Info(" Dest Chain: %d", sentLog.DestinationChainId) - r.Logger.Info(" Dest Gas: %d", sentLog.DestinationGasLimit) - r.Logger.Info(" Zeta Value: %d", sentLog.ZetaValueAndGas) - } - } - } - - return tx -} - -// WithdrawEther withdraws Ether from ZetaChain to the ZETA smart contract on EVM -func (r *E2ERunner) WithdrawEther(amount *big.Int) *ethtypes.Transaction { - // withdraw - tx, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount) - require.NoError(r, err) - - r.Logger.EVMTransaction(*tx, "withdraw") - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.requireTxSuccessful(receipt, "withdraw failed") - - r.Logger.EVMReceipt(*receipt, "withdraw") - r.Logger.ZRC20Withdrawal(r.ETHZRC20, *receipt, "withdraw") - - return tx -} - -// WithdrawERC20 withdraws an ERC20 token from ZetaChain to the ZETA smart contract on EVM -func (r *E2ERunner) WithdrawERC20(amount *big.Int) *ethtypes.Transaction { - tx, err := r.ERC20ZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount) - require.NoError(r, err) - - r.Logger.EVMTransaction(*tx, "withdraw") - - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - r.Logger.Info("Receipt txhash %s status %d", receipt.TxHash, receipt.Status) - for _, log := range receipt.Logs { - event, err := r.ERC20ZRC20.ParseWithdrawal(*log) - if err != nil { - continue - } - r.Logger.Info( - " logs: from %s, to %x, value %d, gasfee %d", - event.From.Hex(), - event.To, - event.Value, - event.GasFee, - ) - } - - return tx -} - -// skipChainOperations checks if the chain operations should be skipped for E2E -func (r *E2ERunner) skipChainOperations(chainID int64) bool { - skip := r.IsRunningUpgrade() && chains.IsTONChain(chainID, nil) - - if skip { - r.Logger.Print("Skipping chain operations for chain %d", chainID) - } - - return skip -} - -// AddInboundTracker adds an inbound tracker from the tx hash -func (r *E2ERunner) AddInboundTracker(coinType coin.CoinType, txHash string) { - require.NotNil(r, r.ZetaTxServer) - - chainID, err := r.EVMClient.ChainID(r.Ctx) - require.NoError(r, err) - - msg := types.NewMsgAddInboundTracker( - r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName), - chainID.Int64(), - coinType, - txHash, - ) - _, err = r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msg) - require.NoError(r, err) -} diff --git a/e2e/runner/zevm.go b/e2e/runner/zevm.go new file mode 100644 index 0000000000..2a020ca23d --- /dev/null +++ b/e2e/runner/zevm.go @@ -0,0 +1,407 @@ +package runner + +import ( + "fmt" + "math/big" + "time" + + "github.com/cenkalti/backoff/v4" + query "github.com/cosmos/cosmos-sdk/types/query" + ethcommon "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" + "github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol" + + "github.com/zeta-chain/node/e2e/utils" + "github.com/zeta-chain/node/pkg/chains" + "github.com/zeta-chain/node/pkg/coin" + "github.com/zeta-chain/node/pkg/contracts/gatewayzevmcaller" + "github.com/zeta-chain/node/pkg/retry" + "github.com/zeta-chain/node/x/crosschain/types" + observertypes "github.com/zeta-chain/node/x/observer/types" +) + +var gasLimit = big.NewInt(250000) + +// ETHWithdraw calls Withdraw of Gateway with gas token on ZEVM +func (r *E2ERunner) ETHWithdraw( + receiver ethcommon.Address, + amount *big.Int, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayZEVM.Withdraw( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ETHZRC20Addr, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ETHWithdrawAndArbitraryCall calls WithdrawAndCall of Gateway with gas token on ZEVM using arbitrary call +func (r *E2ERunner) ETHWithdrawAndArbitraryCall( + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayZEVM.WithdrawAndCall0( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ETHZRC20Addr, + payload, + gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: true}, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ETHWithdrawAndCall calls WithdrawAndCall of Gateway with gas token on ZEVM using authenticated call +func (r *E2ERunner) ETHWithdrawAndCall( + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayZEVM.WithdrawAndCall0( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ETHZRC20Addr, + payload, + gatewayzevm.CallOptions{ + IsArbitraryCall: false, + GasLimit: gasLimit, + }, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ETHWithdrawAndCallThroughContract calls WithdrawAndCall of Gateway with gas token on ZEVM using authenticated call +// through contract +func (r *E2ERunner) ETHWithdrawAndCallThroughContract( + gatewayZEVMCaller *gatewayzevmcaller.GatewayZEVMCaller, + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayzevmcaller.RevertOptions, +) *ethtypes.Transaction { + tx, err := gatewayZEVMCaller.WithdrawAndCallGatewayZEVM( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ETHZRC20Addr, + payload, + gatewayzevmcaller.CallOptions{ + IsArbitraryCall: false, + GasLimit: gasLimit, + }, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ERC20Withdraw calls Withdraw of Gateway with erc20 token on ZEVM +func (r *E2ERunner) ERC20Withdraw( + receiver ethcommon.Address, + amount *big.Int, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayZEVM.Withdraw( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ERC20ZRC20Addr, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ERC20WithdrawAndArbitraryCall calls WithdrawAndCall of Gateway with erc20 token on ZEVM using arbitrary call +func (r *E2ERunner) ERC20WithdrawAndArbitraryCall( + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + // this function take more gas than default 500k + // so we need to increase the gas limit + previousGasLimit := r.ZEVMAuth.GasLimit + r.ZEVMAuth.GasLimit = 10000000 + defer func() { + r.ZEVMAuth.GasLimit = previousGasLimit + }() + + tx, err := r.GatewayZEVM.WithdrawAndCall0( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ERC20ZRC20Addr, + payload, + gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: true}, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ERC20WithdrawAndCall calls WithdrawAndCall of Gateway with erc20 token on ZEVM using authenticated call +func (r *E2ERunner) ERC20WithdrawAndCall( + receiver ethcommon.Address, + amount *big.Int, + payload []byte, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + // this function take more gas than default 500k + // so we need to increase the gas limit + previousGasLimit := r.ZEVMAuth.GasLimit + r.ZEVMAuth.GasLimit = 10000000 + defer func() { + r.ZEVMAuth.GasLimit = previousGasLimit + }() + + tx, err := r.GatewayZEVM.WithdrawAndCall0( + r.ZEVMAuth, + receiver.Bytes(), + amount, + r.ERC20ZRC20Addr, + payload, + gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: false}, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ZEVMToEMVArbitraryCall calls Call of Gateway on ZEVM using arbitrary call +func (r *E2ERunner) ZEVMToEMVArbitraryCall( + receiver ethcommon.Address, + payload []byte, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayZEVM.Call( + r.ZEVMAuth, + receiver.Bytes(), + r.ETHZRC20Addr, + payload, + gatewayzevm.CallOptions{GasLimit: gasLimit, IsArbitraryCall: true}, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ZEVMToEMVCall calls authenticated Call of Gateway on ZEVM using authenticated call +func (r *E2ERunner) ZEVMToEMVCall( + receiver ethcommon.Address, + payload []byte, + revertOptions gatewayzevm.RevertOptions, +) *ethtypes.Transaction { + tx, err := r.GatewayZEVM.Call( + r.ZEVMAuth, + receiver.Bytes(), + r.ETHZRC20Addr, + payload, + gatewayzevm.CallOptions{ + GasLimit: gasLimit, + IsArbitraryCall: false, + }, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// ZEVMToEMVCallThroughContract calls authenticated Call of Gateway on ZEVM through contract using authenticated call +func (r *E2ERunner) ZEVMToEMVCallThroughContract( + gatewayZEVMCaller *gatewayzevmcaller.GatewayZEVMCaller, + receiver ethcommon.Address, + payload []byte, + revertOptions gatewayzevmcaller.RevertOptions, +) *ethtypes.Transaction { + tx, err := gatewayZEVMCaller.CallGatewayZEVM( + r.ZEVMAuth, + receiver.Bytes(), + r.ETHZRC20Addr, + payload, + gatewayzevmcaller.CallOptions{ + GasLimit: gasLimit, + IsArbitraryCall: false, + }, + revertOptions, + ) + require.NoError(r, err) + + return tx +} + +// WaitForBlocks waits for a specific number of blocks to be generated +// The parameter n is the number of blocks to wait for +func (r *E2ERunner) WaitForBlocks(n int64) { + height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{}) + if err != nil { + return + } + call := func() error { + return retry.Retry(r.waitForBlock(height.Height + n)) + } + + bo := backoff.NewConstantBackOff(time.Second * 5) + boWithMaxRetries := backoff.WithMaxRetries(bo, 10) + err = retry.DoWithBackoff(call, boWithMaxRetries) + require.NoError(r, err, "failed to wait for %d blocks", n) +} + +// WaitForTSSGeneration waits for a specific number of TSS to be generated +// The parameter n is the number of TSS to wait for +func (r *E2ERunner) WaitForTSSGeneration(tssNumber int64) { + call := func() error { + return retry.Retry(r.checkNumberOfTSSGenerated(tssNumber)) + } + bo := backoff.NewConstantBackOff(time.Second * 5) + boWithMaxRetries := backoff.WithMaxRetries(bo, 10) + err := retry.DoWithBackoff(call, boWithMaxRetries) + require.NoError(r, err, "failed to wait for %d tss generation", tssNumber) +} + +// checkNumberOfTSSGenerated checks the number of TSS generated +// if the number of tss is less that the `tssNumber` provided we return an error +func (r *E2ERunner) checkNumberOfTSSGenerated(tssNumber int64) error { + tssList, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{}) + if err != nil { + return err + } + if int64(len(tssList.TssList)) < tssNumber { + return fmt.Errorf("waiting for %d tss generation, number of TSS :%d", tssNumber, len(tssList.TssList)) + } + return nil +} + +func (r *E2ERunner) waitForBlock(n int64) error { + height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{}) + if err != nil { + return err + } + if height.Height < n { + return fmt.Errorf("waiting for %d blocks, current height %d", n, height.Height) + } + return nil +} + +// WaitForTxReceiptOnZEVM waits for a tx receipt on ZEVM +func (r *E2ERunner) WaitForTxReceiptOnZEVM(tx *ethtypes.Transaction) { + r.Lock() + defer r.Unlock() + + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + r.requireTxSuccessful(receipt) +} + +// WaitForMinedCCTX waits for a cctx to be mined from a tx +func (r *E2ERunner) WaitForMinedCCTX(txHash ethcommon.Hash) { + r.Lock() + defer r.Unlock() + + cctx := utils.WaitCctxMinedByInboundHash( + r.Ctx, + txHash.Hex(), + r.CctxClient, + r.Logger, + r.CctxTimeout, + ) + utils.RequireCCTXStatus(r, cctx, types.CctxStatus_OutboundMined) +} + +// WaitForMinedCCTXFromIndex waits for a cctx to be mined from its index +func (r *E2ERunner) WaitForMinedCCTXFromIndex(index string) *types.CrossChainTx { + return r.waitForMinedCCTXFromIndex(index, types.CctxStatus_OutboundMined) +} + +func (r *E2ERunner) waitForMinedCCTXFromIndex(index string, status types.CctxStatus) *types.CrossChainTx { + r.Lock() + defer r.Unlock() + + cctx := utils.WaitCCTXMinedByIndex(r.Ctx, index, r.CctxClient, r.Logger, r.CctxTimeout) + utils.RequireCCTXStatus(r, cctx, status) + + return cctx +} + +// WaitForSpecificCCTX scans for cctx by filters and ensures it's mined +func (r *E2ERunner) WaitForSpecificCCTX( + filter func(*types.CrossChainTx) bool, + status types.CctxStatus, + timeout time.Duration, +) *types.CrossChainTx { + var ( + ctx = r.Ctx + start = time.Now() + reqQuery = &types.QueryAllCctxRequest{ + Pagination: &query.PageRequest{Reverse: true}, + } + ) + + for time.Since(start) < timeout { + res, err := r.CctxClient.CctxAll(ctx, reqQuery) + require.NoError(r, err) + + for i := range res.CrossChainTx { + tx := res.CrossChainTx[i] + if filter(tx) { + return r.waitForMinedCCTXFromIndex(tx.Index, status) + } + } + + time.Sleep(time.Second) + } + + r.Logger.Error("WaitForSpecificCCTX: No CCTX found. Timed out") + r.FailNow() + + return nil +} + +// skipChainOperations checks if the chain operations should be skipped for E2E +func (r *E2ERunner) skipChainOperations(chainID int64) bool { + skip := r.IsRunningUpgrade() && chains.IsTONChain(chainID, nil) + + if skip { + r.Logger.Print("Skipping chain operations for chain %d", chainID) + } + + return skip +} + +// AddInboundTracker adds an inbound tracker from the tx hash +func (r *E2ERunner) AddInboundTracker(coinType coin.CoinType, txHash string) { + require.NotNil(r, r.ZetaTxServer) + + chainID, err := r.EVMClient.ChainID(r.Ctx) + require.NoError(r, err) + + msg := types.NewMsgAddInboundTracker( + r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName), + chainID.Int64(), + coinType, + txHash, + ) + _, err = r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msg) + require.NoError(r, err) +}