diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 1fa0234cd1..2e7bc71768 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -86,7 +86,7 @@ func RunnerFromConfig( // ExportContractsFromRunner export contracts from the runner to config using a source config func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.Config { // copy contracts from deployer runner - conf.Contracts.EVM.ZetaEthAddress = config.DoubleQuotedString(r.ZetaEthAddr.Hex()) + conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(r.ZetaEthAddr.Hex()) conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(r.ConnectorEthAddr.Hex()) conf.Contracts.EVM.CustodyAddr = config.DoubleQuotedString(r.ERC20CustodyAddr.Hex()) conf.Contracts.EVM.ERC20 = config.DoubleQuotedString(r.ERC20Addr.Hex()) diff --git a/cmd/zetae2e/config/contracts.go b/cmd/zetae2e/config/contracts.go index 03aad60ed7..110038298a 100644 --- a/cmd/zetae2e/config/contracts.go +++ b/cmd/zetae2e/config/contracts.go @@ -25,10 +25,10 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { var err error // set EVM contracts - if c := conf.Contracts.EVM.ZetaEthAddress; c != "" { + if c := conf.Contracts.EVM.ZetaEthAddr; c != "" { r.ZetaEthAddr, err = c.AsEVMAddress() if err != nil { - return fmt.Errorf("invalid ZetaEthAddress: %w", err) + return fmt.Errorf("invalid ZetaEthAddr: %w", err) } r.ZetaEth, err = zetaeth.NewZetaEth(r.ZetaEthAddr, r.EVMClient) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index d5c488dc0e..b68544c90b 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -322,7 +322,7 @@ func WithdrawETHZRC20(runner *runner.E2ERunner) { ethZRC20 := runner.ETHZRC20 runner.ZEVMAuth.Nonce = zevmNonce - _, err := ethZRC20.Withdraw(runner.ZEVMAuth, runner.DeployerAddress.Bytes(), big.NewInt(100)) + _, err := ethZRC20.Withdraw(runner.ZEVMAuth, runner.EVMAddress().Bytes(), big.NewInt(100)) if err != nil { panic(err) } diff --git a/e2e/config/config.go b/e2e/config/config.go index 32ba6865e7..0cd372cd22 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -96,7 +96,7 @@ type Contracts struct { // EVM contains the addresses of predeployed contracts on the EVM chain type EVM struct { - ZetaEthAddress DoubleQuotedString `yaml:"zeta_eth"` + ZetaEthAddr DoubleQuotedString `yaml:"zeta_eth"` ConnectorEthAddr DoubleQuotedString `yaml:"connector_eth"` CustodyAddr DoubleQuotedString `yaml:"custody"` ERC20 DoubleQuotedString `yaml:"erc20"` diff --git a/e2e/e2etests/test_context_upgrade.go b/e2e/e2etests/test_context_upgrade.go index fc1e7599de..e7b8496fe4 100644 --- a/e2e/e2etests/test_context_upgrade.go +++ b/e2e/e2etests/test_context_upgrade.go @@ -61,7 +61,7 @@ func TestContextUpgrade(r *runner.E2ERunner, args []string) { r.Logger.Info(" chainid: %d", eventIter.Event.ChainID) r.Logger.Info(" msgsender: %s", eventIter.Event.MsgSender.Hex()) found = true - if bytes.Compare(eventIter.Event.Origin, r.DeployerAddress.Bytes()) != 0 { + if bytes.Compare(eventIter.Event.Origin, r.EVMAddress().Bytes()) != 0 { panic("origin mismatch") } chainID, err := r.EVMClient.ChainID(r.Ctx) diff --git a/e2e/e2etests/test_crosschain_swap.go b/e2e/e2etests/test_crosschain_swap.go index 358e9ba7d7..d0517de7d3 100644 --- a/e2e/e2etests/test_crosschain_swap.go +++ b/e2e/e2etests/test_crosschain_swap.go @@ -65,7 +65,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { big.NewInt(1e8), big.NewInt(1e8), big.NewInt(1e5), - r.DeployerAddress, + r.EVMAddress(), big.NewInt(time.Now().Add(10*time.Minute).Unix()), ) if err != nil { @@ -94,7 +94,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.DeployerAddress, big.NewInt(8e7), msg) + txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), big.NewInt(8e7), msg) cctx1 := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) // check the cctx status @@ -139,7 +139,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { } r.Logger.Info("#utxos %d", len(utxos)) r.Logger.Info("memo address %s", r.ERC20ZRC20Addr) - memo, err := r.ZEVMSwapApp.EncodeMemo(&bind.CallOpts{}, r.ERC20ZRC20Addr, r.DeployerAddress.Bytes()) + memo, err := r.ZEVMSwapApp.EncodeMemo(&bind.CallOpts{}, r.ERC20ZRC20Addr, r.EVMAddress().Bytes()) if err != nil { panic(err) } @@ -180,7 +180,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { r.Logger.Info("******* Third test: BTC -> ETH with contract call reverted; should refund BTC") // the following memo will result in a revert in the contract call as targetZRC20 is set to DeployerAddress // which is apparently not a ZRC20 contract; the UNISWAP call will revert - memo, err := r.ZEVMSwapApp.EncodeMemo(&bind.CallOpts{}, r.DeployerAddress, r.DeployerAddress.Bytes()) + memo, err := r.ZEVMSwapApp.EncodeMemo(&bind.CallOpts{}, r.EVMAddress(), r.EVMAddress().Bytes()) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_erc20_deposit.go b/e2e/e2etests/test_erc20_deposit.go index f550ce4aa7..afeb4fd4bb 100644 --- a/e2e/e2etests/test_erc20_deposit.go +++ b/e2e/e2etests/test_erc20_deposit.go @@ -17,7 +17,7 @@ func TestERC20Deposit(r *runner.E2ERunner, args []string) { panic("Invalid amount specified for TestERC20Deposit.") } - hash := r.DepositERC20WithAmountAndMessage(r.DeployerAddress, amount, []byte{}) + hash := r.DepositERC20WithAmountAndMessage(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/test_erc20_deposit_refund.go b/e2e/e2etests/test_erc20_deposit_refund.go index 684adf3d6f..3526271c4d 100644 --- a/e2e/e2etests/test_erc20_deposit_refund.go +++ b/e2e/e2etests/test_erc20_deposit_refund.go @@ -16,7 +16,7 @@ import ( func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { // Get the initial balance of the deployer - initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -46,14 +46,14 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { msg := types.NewMsgRefundAbortedCCTX( r.ZetaTxServer.GetAccountAddress(0), cctx.Index, - r.DeployerAddress.String()) + r.EVMAddress().String()) _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) if err != nil { panic(err) } // Check that the erc20 in the aborted cctx was refunded on ZetaChain - newBalance, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + newBalance, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -79,7 +79,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { } r.Logger.Info("Liquidity pool created") - erc20Balance, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + erc20Balance, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -115,7 +115,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { } // check that the erc20 in the reverted cctx was refunded on EVM - erc20BalanceAfterRefund, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + erc20BalanceAfterRefund, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -144,7 +144,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { func createZetaERC20LiquidityPool(r *runner.E2ERunner) error { amount := big.NewInt(1e10) - txHash := r.DepositERC20WithAmountAndMessage(r.DeployerAddress, amount, []byte{}) + txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{}) utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) tx, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e10)) @@ -164,7 +164,7 @@ func createZetaERC20LiquidityPool(r *runner.E2ERunner) error { amount, big.NewInt(0), big.NewInt(0), - r.DeployerAddress, + r.EVMAddress(), big.NewInt(time.Now().Add(10*time.Minute).Unix()), ) r.ZEVMAuth.Value = previousValue @@ -189,7 +189,7 @@ func sendInvalidERC20Deposit(r *runner.E2ERunner, amount *big.Int) (string, erro tx, err = r.ERC20Custody.Deposit( r.EVMAuth, - r.DeployerAddress.Bytes(), + r.EVMAddress().Bytes(), r.ERC20Addr, amount, []byte("this is an invalid msg that will cause the contract to revert"), diff --git a/e2e/e2etests/test_erc20_multiple_deposits.go b/e2e/e2etests/test_erc20_multiple_deposits.go index b09c363c8d..deae8ef9ea 100644 --- a/e2e/e2etests/test_erc20_multiple_deposits.go +++ b/e2e/e2etests/test_erc20_multiple_deposits.go @@ -27,7 +27,7 @@ func TestMultipleERC20Deposit(r *runner.E2ERunner, args []string) { panic("Invalid number of deposits specified for TestMultipleERC20Deposit.") } - initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -46,7 +46,7 @@ func TestMultipleERC20Deposit(r *runner.E2ERunner, args []string) { } // check new balance is increased by amount * count - bal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + bal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -78,7 +78,7 @@ func multipleDeposits(r *runner.E2ERunner, amount, count *big.Int) ethcommon.Has r.Logger.Info("ERC20 Approve receipt tx hash: %s", tx.Hash().Hex()) // deposit - tx, err = depositor.RunDeposits(r.EVMAuth, r.DeployerAddress.Bytes(), r.ERC20Addr, amount, []byte{}, count) + tx, err = depositor.RunDeposits(r.EVMAuth, r.EVMAddress().Bytes(), r.ERC20Addr, amount, []byte{}, count) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_erc20_multiple_withdraws.go b/e2e/e2etests/test_erc20_multiple_withdraws.go index de13c7b6b8..35cd9bcd6c 100644 --- a/e2e/e2etests/test_erc20_multiple_withdraws.go +++ b/e2e/e2etests/test_erc20_multiple_withdraws.go @@ -64,7 +64,7 @@ func TestMultipleERC20Withdraws(r *runner.E2ERunner, args []string) { r.Logger.Info("eth zrc20 approve receipt: status %d", receipt.Status) // check the balance - bal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + bal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -77,7 +77,7 @@ func TestMultipleERC20Withdraws(r *runner.E2ERunner, args []string) { // withdraw tx, err = withdrawer.RunWithdraws( r.ZEVMAuth, - r.DeployerAddress.Bytes(), + r.EVMAddress().Bytes(), r.ERC20ZRC20Addr, withdrawalAmount, numberOfWithdrawals, diff --git a/e2e/e2etests/test_eth_deposit_call.go b/e2e/e2etests/test_eth_deposit_call.go index dc6cc5cb32..f475e960aa 100644 --- a/e2e/e2etests/test_eth_deposit_call.go +++ b/e2e/e2etests/test_eth_deposit_call.go @@ -7,7 +7,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -40,7 +39,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) { if err != nil { panic(err) } - nonce, err := evmClient.PendingNonceAt(r.Ctx, r.DeployerAddress) + nonce, err := evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) if err != nil { panic(err) } @@ -51,7 +50,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) { if err != nil { panic(err) } - deployerPrivkey, err := crypto.HexToECDSA(r.DeployerPrivateKey) + deployerPrivkey, err := r.Account.PrivateKey() if err != nil { panic(err) } @@ -102,7 +101,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) { if err != nil { panic(err) } - nonce, err = evmClient.PendingNonceAt(r.Ctx, r.DeployerAddress) + nonce, err = evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_eth_deposit_liquidity_cap.go b/e2e/e2etests/test_eth_deposit_liquidity_cap.go index a132fdd35e..e34306951d 100644 --- a/e2e/e2etests/test_eth_deposit_liquidity_cap.go +++ b/e2e/e2etests/test_eth_deposit_liquidity_cap.go @@ -55,7 +55,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { r.Logger.Info("CCTX has been reverted") r.Logger.Info("Depositing less than liquidity cap should still succeed") - initialBal, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + initialBal, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -83,7 +83,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { expectedBalance := big.NewInt(0).Add(initialBal, amountLessThanCap) - bal, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + bal, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -104,7 +104,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { panic(err) } r.Logger.Info("remove liquidity cap tx hash: %s", res.TxHash) - initialBal, err = r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + initialBal, err = r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -119,7 +119,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { utils.WaitCctxMinedByInboundHash(r.Ctx, signedTx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) expectedBalance = big.NewInt(0).Add(initialBal, amountMoreThanCap) - bal, err = r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + bal, err = r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_eth_deposit_refund.go b/e2e/e2etests/test_eth_deposit_refund.go index 2de41965ea..f417d71529 100644 --- a/e2e/e2etests/test_eth_deposit_refund.go +++ b/e2e/e2etests/test_eth_deposit_refund.go @@ -6,7 +6,6 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -25,7 +24,7 @@ func TestEtherDepositAndCallRefund(r *runner.E2ERunner, args []string) { evmClient := r.EVMClient - nonce, err := evmClient.PendingNonceAt(r.Ctx, r.DeployerAddress) + nonce, err := evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) if err != nil { panic(err) } @@ -42,7 +41,7 @@ func TestEtherDepositAndCallRefund(r *runner.E2ERunner, args []string) { if err != nil { panic(err) } - deployerPrivkey, err := crypto.HexToECDSA(r.DeployerPrivateKey) + deployerPrivkey, err := r.Account.PrivateKey() if err != nil { panic(err) } @@ -95,9 +94,9 @@ func TestEtherDepositAndCallRefund(r *runner.E2ERunner, args []string) { panic("expected the revert tx receipt to have status 1; got 0") } - if *tx.To() != r.DeployerAddress { + if *tx.To() != r.EVMAddress() { printTxInfo() - panic(fmt.Sprintf("expected tx to %s; got %s", r.DeployerAddress.Hex(), tx.To().Hex())) + panic(fmt.Sprintf("expected tx to %s; got %s", r.EVMAddress().Hex(), tx.To().Hex())) } // the received value must be lower than the original value because of the paid fees for the revert tx diff --git a/e2e/e2etests/test_message_passing_external_chains.go b/e2e/e2etests/test_message_passing_external_chains.go index 5a6fed227e..944ad7cf5d 100644 --- a/e2e/e2etests/test_message_passing_external_chains.go +++ b/e2e/e2etests/test_message_passing_external_chains.go @@ -46,7 +46,7 @@ func TestMessagePassingExternalChains(r *runner.E2ERunner, args []string) { r.Logger.Info("Calling ConnectorEth.Send") tx, err = r.ConnectorEth.Send(auth, zetaconnectoreth.ZetaInterfacesSendInput{ DestinationChainId: chainID, - DestinationAddress: r.DeployerAddress.Bytes(), + DestinationAddress: r.EVMAddress().Bytes(), DestinationGasLimit: big.NewInt(400_000), Message: nil, ZetaValueAndGas: amount, diff --git a/e2e/e2etests/test_message_passing_external_chains_revert_fail.go b/e2e/e2etests/test_message_passing_external_chains_revert_fail.go index e9bdeb0c7e..1db3115ba3 100644 --- a/e2e/e2etests/test_message_passing_external_chains_revert_fail.go +++ b/e2e/e2etests/test_message_passing_external_chains_revert_fail.go @@ -43,7 +43,7 @@ func TestMessagePassingRevertFailExternalChains(r *runner.E2ERunner, args []stri r.Logger.Info("Calling ConnectorEth.Send") tx, err = r.ConnectorEth.Send(auth, zetaconnectoreth.ZetaInterfacesSendInput{ DestinationChainId: chainID, - DestinationAddress: r.DeployerAddress.Bytes(), + DestinationAddress: r.EVMAddress().Bytes(), DestinationGasLimit: big.NewInt(400_000), Message: []byte( "revert", diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index e2b6d62d52..57e57dfd1e 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -37,7 +37,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.DeployerAddress, zetaAmount) + r.DepositZetaWithAmount(r.EVMAddress(), zetaAmount) // do an ethers withdraw on the previous chain (0.01eth) for some interaction TestEtherWithdraw(r, []string{"10000000000000000"}) @@ -138,7 +138,7 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) { time.Sleep(10 * time.Second) // emitting a withdraw with the previous chain should fail - txWithdraw, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.DeployerAddress.Bytes(), big.NewInt(10000000000000000)) + txWithdraw, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), big.NewInt(10000000000000000)) if err == nil { receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, txWithdraw, r.Logger, r.ReceiptTimeout) if receipt.Status == 1 { @@ -236,7 +236,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.Ctx, "admin-evm2", r.CtxCancel, - r.DeployerAccount, + r.Account, r.EVMClient, r.ZEVMClient, r.CctxClient, @@ -253,7 +253,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { ) // All existing fields of the runner are the same except for the RPC URL and client for EVM - ewvmClient, evmAuth, err := getEVMClient(newRunner.Ctx, EVM2RPCURL, r.DeployerPrivateKey) + ewvmClient, evmAuth, err := getEVMClient(newRunner.Ctx, EVM2RPCURL, r.Account.RawEVMAddress.String()) if err != nil { return nil, err } diff --git a/e2e/e2etests/test_rate_limiter.go b/e2e/e2etests/test_rate_limiter.go index db8d67f348..63950d7d39 100644 --- a/e2e/e2etests/test_rate_limiter.go +++ b/e2e/e2etests/test_rate_limiter.go @@ -237,7 +237,7 @@ func addZetaGasLiquidity(r *runner.E2ERunner) error { amount, big.NewInt(1e18), big.NewInt(1e18), - r.DeployerAddress, + r.EVMAddress(), big.NewInt(time.Now().Add(10*time.Minute).Unix()), ) if err != nil { diff --git a/e2e/e2etests/test_stress_eth_withdraw.go b/e2e/e2etests/test_stress_eth_withdraw.go index 7f73e863a0..a26493baeb 100644 --- a/e2e/e2etests/test_stress_eth_withdraw.go +++ b/e2e/e2etests/test_stress_eth_withdraw.go @@ -46,7 +46,7 @@ func TestStressEtherWithdraw(r *runner.E2ERunner, args []string) { // send the withdraws for i := 0; i < numWithdraws; i++ { i := i - tx, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.DeployerAddress.Bytes(), withdrawalAmount) + tx, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), withdrawalAmount) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_update_bytecode_zrc20.go b/e2e/e2etests/test_update_bytecode_zrc20.go index 4762ec94bb..ed8791d040 100644 --- a/e2e/e2etests/test_update_bytecode_zrc20.go +++ b/e2e/e2etests/test_update_bytecode_zrc20.go @@ -71,11 +71,11 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) { if err != nil { panic(err) } - balance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + balance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } - approval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.DeployerAddress, approved) + approval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.EVMAddress(), approved) if err != nil { panic(err) } @@ -122,14 +122,14 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) { if totalSupply.Cmp(newTotalSupply) != 0 { panic("total supply shouldn't change upon bytecode update") } - newBalance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + newBalance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } if balance.Cmp(newBalance) != 0 { panic("balance shouldn't change upon bytecode update") } - newApproval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.DeployerAddress, approved) + newApproval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.EVMAddress(), approved) if err != nil { panic(err) } diff --git a/e2e/e2etests/test_zeta_deposit.go b/e2e/e2etests/test_zeta_deposit.go index a6fa98dbcf..c2f4385430 100644 --- a/e2e/e2etests/test_zeta_deposit.go +++ b/e2e/e2etests/test_zeta_deposit.go @@ -17,7 +17,7 @@ func TestZetaDeposit(r *runner.E2ERunner, args []string) { panic("Invalid amount specified for TestZetaDeposit.") } - hash := r.DepositZetaWithAmount(r.DeployerAddress, amount) + hash := r.DepositZetaWithAmount(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/test_zeta_withdraw_bitcoin_revert.go b/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go index 151d140a97..fa84ce5446 100644 --- a/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go +++ b/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go @@ -49,7 +49,7 @@ func TestZetaWithdrawBTCRevert(r *runner.E2ERunner, args []string) { lessThanAmount := amount.Div(amount, big.NewInt(10)) // 1/10 of amount tx, err = r.ConnectorZEVM.Send(r.ZEVMAuth, connectorzevm.ZetaInterfacesSendInput{ DestinationChainId: big.NewInt(chains.BitcoinRegtest.ChainId), - DestinationAddress: r.DeployerAddress.Bytes(), + DestinationAddress: r.EVMAddress().Bytes(), DestinationGasLimit: big.NewInt(400_000), Message: nil, ZetaValueAndGas: lessThanAmount, diff --git a/e2e/e2etests/test_zrc20_swap.go b/e2e/e2etests/test_zrc20_swap.go index 4dfea02cf1..8b3e3ab701 100644 --- a/e2e/e2etests/test_zrc20_swap.go +++ b/e2e/e2etests/test_zrc20_swap.go @@ -58,7 +58,7 @@ func TestZRC20Swap(r *runner.E2ERunner, _ []string) { big.NewInt(1000), big.NewInt(90000), big.NewInt(1000), - r.DeployerAddress, + r.EVMAddress(), big.NewInt(time.Now().Add(10*time.Minute).Unix()), ) if err != nil { @@ -67,7 +67,7 @@ func TestZRC20Swap(r *runner.E2ERunner, _ []string) { receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) r.Logger.Info("Add liquidity receipt txhash %s status %d", receipt.TxHash, receipt.Status) - balETHBefore, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + balETHBefore, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } @@ -77,7 +77,7 @@ func TestZRC20Swap(r *runner.E2ERunner, _ []string) { big.NewInt(1000), ethOutAmout, []ethcommon.Address{r.ERC20ZRC20Addr, r.ETHZRC20Addr}, - r.DeployerAddress, + r.EVMAddress(), big.NewInt(time.Now().Add(10*time.Minute).Unix()), ) if err != nil { @@ -86,7 +86,7 @@ func TestZRC20Swap(r *runner.E2ERunner, _ []string) { receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) r.Logger.Info("Swap ERC20 ZRC20 for ETH ZRC20 %s status %d", receipt.TxHash, receipt.Status) - balETHAfter, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + balETHAfter, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { panic(err) } diff --git a/e2e/runner/balances.go b/e2e/runner/balances.go index 19acfd1509..2e91edbcf5 100644 --- a/e2e/runner/balances.go +++ b/e2e/runner/balances.go @@ -31,38 +31,39 @@ type AccountBalancesDiff struct { // GetAccountBalances returns the account balances of the accounts used in the E2E test func (runner *E2ERunner) GetAccountBalances(skipBTC bool) (AccountBalances, error) { + address := runner.Account.EVMAddress() // zevm - zetaZeta, err := runner.ZEVMClient.BalanceAt(runner.Ctx, runner.DeployerAddress, nil) + zetaZeta, err := runner.ZEVMClient.BalanceAt(runner.Ctx, address, nil) if err != nil { return AccountBalances{}, err } - zetaWZeta, err := runner.WZeta.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + zetaWZeta, err := runner.WZeta.BalanceOf(&bind.CallOpts{}, address) if err != nil { return AccountBalances{}, err } - zetaEth, err := runner.ETHZRC20.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + zetaEth, err := runner.ETHZRC20.BalanceOf(&bind.CallOpts{}, address) if err != nil { return AccountBalances{}, err } - zetaErc20, err := runner.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + zetaErc20, err := runner.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, address) if err != nil { return AccountBalances{}, err } - zetaBtc, err := runner.BTCZRC20.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + zetaBtc, err := runner.BTCZRC20.BalanceOf(&bind.CallOpts{}, address) if err != nil { return AccountBalances{}, err } // evm - evmEth, err := runner.EVMClient.BalanceAt(runner.Ctx, runner.DeployerAddress, nil) + evmEth, err := runner.EVMClient.BalanceAt(runner.Ctx, address, nil) if err != nil { return AccountBalances{}, err } - evmZeta, err := runner.ZetaEth.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + evmZeta, err := runner.ZetaEth.BalanceOf(&bind.CallOpts{}, address) if err != nil { return AccountBalances{}, err } - evmErc20, err := runner.ERC20.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + evmErc20, err := runner.ERC20.BalanceOf(&bind.CallOpts{}, address) if err != nil { return AccountBalances{}, err } @@ -119,7 +120,7 @@ func (runner *E2ERunner) GetBitcoinBalance() (string, error) { // PrintAccountBalances shows the account balances of the accounts used in the E2E test // Note: USDT is mentioned as erc20 here because we want to show the balance of any erc20 contract func (runner *E2ERunner) PrintAccountBalances(balances AccountBalances) { - runner.Logger.Print(" ---💰 Account info %s ---", runner.DeployerAddress.Hex()) + runner.Logger.Print(" ---💰 Account info %s ---", runner.Account.EVMAddress().Hex()) // zevm runner.Logger.Print("ZetaChain:") diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index 493a7a3fd3..c0660a3768 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -156,7 +156,7 @@ func (runner *E2ERunner) DepositBTC(testHeader bool) { ) } - balance, err := runner.BTCZRC20.BalanceOf(&bind.CallOpts{}, runner.DeployerAddress) + balance, err := runner.BTCZRC20.BalanceOf(&bind.CallOpts{}, runner.EVMAddress()) if err != nil { panic(err) } @@ -175,7 +175,7 @@ func (runner *E2ERunner) SendToTSSFromDeployerToDeposit(amount float64, inputUTX *chainhash.Hash, error, ) { - return runner.SendToTSSFromDeployerWithMemo(amount, inputUTXOs, runner.DeployerAddress.Bytes()) + return runner.SendToTSSFromDeployerWithMemo(amount, inputUTXOs, runner.EVMAddress().Bytes()) } func (runner *E2ERunner) SendToTSSFromDeployerWithMemo( diff --git a/e2e/runner/evm.go b/e2e/runner/evm.go index 355b692ec5..4354eab83c 100644 --- a/e2e/runner/evm.go +++ b/e2e/runner/evm.go @@ -7,7 +7,6 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rpc" "github.com/zeta-chain/zetacore/e2e/utils" @@ -76,7 +75,7 @@ func (runner *E2ERunner) SendERC20OnEvm(address ethcommon.Address, amountERC20 i func (runner *E2ERunner) DepositERC20() ethcommon.Hash { runner.Logger.Print("⏳ depositing ERC20 into ZEVM") - return runner.DepositERC20WithAmountAndMessage(runner.DeployerAddress, big.NewInt(1e18), []byte{}) + return runner.DepositERC20WithAmountAndMessage(runner.EVMAddress(), big.NewInt(1e18), []byte{}) } func (runner *E2ERunner) DepositERC20WithAmountAndMessage( @@ -165,7 +164,7 @@ func (runner *E2ERunner) DepositEtherWithAmount(testHeader bool, amount *big.Int func (runner *E2ERunner) SendEther(_ ethcommon.Address, value *big.Int, data []byte) (*ethtypes.Transaction, error) { evmClient := runner.EVMClient - nonce, err := evmClient.PendingNonceAt(runner.Ctx, runner.DeployerAddress) + nonce, err := evmClient.PendingNonceAt(runner.Ctx, runner.EVMAddress()) if err != nil { return nil, err } @@ -182,7 +181,7 @@ func (runner *E2ERunner) SendEther(_ ethcommon.Address, value *big.Int, data []b return nil, err } - deployerPrivkey, err := crypto.HexToECDSA(runner.DeployerPrivateKey) + deployerPrivkey, err := runner.Account.PrivateKey() if err != nil { return nil, err } diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index 32aaf7ba08..7c1fd3ab0e 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -11,6 +11,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" ethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol" @@ -38,10 +39,8 @@ import ( // Exposes a method to run E2E test // It also provides some helper functions type E2ERunner struct { - // accounts - DeployerAccount config.Account - DeployerAddress ethcommon.Address - DeployerPrivateKey string + // account the test is using for auth + Account config.Account TSSAddress ethcommon.Address BTCTSSAddress btcutil.Address BTCDeployerAddress *btcutil.AddressWitnessPubKeyHash @@ -139,9 +138,7 @@ func NewE2ERunner( Ctx: ctx, CtxCancel: ctxCancel, - DeployerAccount: account, - DeployerAddress: account.EVMAddress(), - DeployerPrivateKey: account.RawPrivateKey.String(), + Account: account, ZEVMClient: zevmClient, EVMClient: evmClient, @@ -258,6 +255,11 @@ func (runner *E2ERunner) Unlock() { runner.mutex.Unlock() } +// EVMAddress is a shorthand for Account.EVMAddress() +func (runner *E2ERunner) EVMAddress() common.Address { + return runner.Account.EVMAddress() +} + // PrintContractAddresses prints the addresses of the contracts // the printed contracts are grouped in a zevm and evm section // there is a padding used to print the addresses at the same position diff --git a/e2e/runner/setup_bitcoin.go b/e2e/runner/setup_bitcoin.go index 15af182915..582f0bc8d0 100644 --- a/e2e/runner/setup_bitcoin.go +++ b/e2e/runner/setup_bitcoin.go @@ -48,7 +48,7 @@ func (runner *E2ERunner) SetupBitcoinAccount(initNetwork bool) { // GetBtcAddress returns the BTC address of the deployer from its EVM private key func (runner *E2ERunner) GetBtcAddress() (string, string, error) { - skBytes, err := hex.DecodeString(runner.DeployerPrivateKey) + skBytes, err := hex.DecodeString(runner.Account.RawPrivateKey.String()) if err != nil { return "", "", err } @@ -73,7 +73,7 @@ func (runner *E2ERunner) GetBtcAddress() (string, string, error) { // SetBtcAddress imports the deployer's private key into the Bitcoin node func (runner *E2ERunner) SetBtcAddress(name string, rescan bool) { - skBytes, err := hex.DecodeString(runner.DeployerPrivateKey) + skBytes, err := hex.DecodeString(runner.Account.RawPrivateKey.String()) if err != nil { panic(err) } diff --git a/e2e/runner/setup_evm.go b/e2e/runner/setup_evm.go index 41b2603a12..8519a318b3 100644 --- a/e2e/runner/setup_evm.go +++ b/e2e/runner/setup_evm.go @@ -28,7 +28,7 @@ func (runner *E2ERunner) SetEVMContractsFromConfig() { } // Set ZetaEthAddr - runner.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddress.String()) + runner.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddr.String()) runner.ZetaEth, err = zetaeth.NewZetaEth(runner.ZetaEthAddr, runner.EVMClient) if err != nil { panic(err) @@ -76,7 +76,7 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { zetaEthAddr, txZetaEth, ZetaEth, err := zetaeth.DeployZetaEth( runner.EVMAuth, runner.EVMClient, - runner.DeployerAddress, + runner.EVMAddress(), big.NewInt(21_000_000_000), ) if err != nil { @@ -84,7 +84,7 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { } runner.ZetaEth = ZetaEth runner.ZetaEthAddr = zetaEthAddr - conf.Contracts.EVM.ZetaEthAddress = config.DoubleQuotedString(zetaEthAddr.String()) + conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(zetaEthAddr.String()) runner.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), zetaEthAddr.Hash().Hex()) runner.Logger.Info("Deploying ZetaConnectorEth contract") @@ -93,8 +93,8 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { runner.EVMClient, zetaEthAddr, runner.TSSAddress, - runner.DeployerAddress, - runner.DeployerAddress, + runner.EVMAddress(), + runner.EVMAddress(), ) if err != nil { panic(err) @@ -113,8 +113,8 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { erc20CustodyAddr, txCustody, ERC20Custody, err := erc20custody.DeployERC20Custody( runner.EVMAuth, runner.EVMClient, - runner.DeployerAddress, - runner.DeployerAddress, + runner.EVMAddress(), + runner.EVMAddress(), big.NewInt(0), big.NewInt(1e18), ethcommon.HexToAddress("0x"), diff --git a/e2e/runner/zeta.go b/e2e/runner/zeta.go index 104fb4900f..0c345b35b3 100644 --- a/e2e/runner/zeta.go +++ b/e2e/runner/zeta.go @@ -87,7 +87,7 @@ func (runner *E2ERunner) DepositZeta() ethcommon.Hash { amount := big.NewInt(1e18) amount = amount.Mul(amount, big.NewInt(100)) // 100 Zeta - return runner.DepositZetaWithAmount(runner.DeployerAddress, amount) + return runner.DepositZetaWithAmount(runner.EVMAddress(), amount) } // DepositZetaWithAmount deposits ZETA on ZetaChain from the ZETA smart contract on EVM with the specified amount @@ -186,7 +186,7 @@ func (runner *E2ERunner) WithdrawZeta(amount *big.Int, waitReceipt bool) *ethtyp tx, err := runner.ConnectorZEVM.Send(runner.ZEVMAuth, connectorzevm.ZetaInterfacesSendInput{ DestinationChainId: chainID, - DestinationAddress: runner.DeployerAddress.Bytes(), + DestinationAddress: runner.EVMAddress().Bytes(), DestinationGasLimit: big.NewInt(400_000), Message: nil, ZetaValueAndGas: amount, @@ -223,7 +223,7 @@ func (runner *E2ERunner) WithdrawZeta(amount *big.Int, waitReceipt bool) *ethtyp // WithdrawEther withdraws Ether from ZetaChain to the ZETA smart contract on EVM func (runner *E2ERunner) WithdrawEther(amount *big.Int) *ethtypes.Transaction { // withdraw - tx, err := runner.ETHZRC20.Withdraw(runner.ZEVMAuth, runner.DeployerAddress.Bytes(), amount) + tx, err := runner.ETHZRC20.Withdraw(runner.ZEVMAuth, runner.EVMAddress().Bytes(), amount) if err != nil { panic(err) } @@ -241,7 +241,7 @@ func (runner *E2ERunner) WithdrawEther(amount *big.Int) *ethtypes.Transaction { // WithdrawERC20 withdraws an ERC20 token from ZetaChain to the ZETA smart contract on EVM func (runner *E2ERunner) WithdrawERC20(amount *big.Int) *ethtypes.Transaction { - tx, err := runner.ERC20ZRC20.Withdraw(runner.ZEVMAuth, runner.DeployerAddress.Bytes(), amount) + tx, err := runner.ERC20ZRC20.Withdraw(runner.ZEVMAuth, runner.EVMAddress().Bytes(), amount) if err != nil { panic(err) }