diff --git a/Dockerfile-localnet b/Dockerfile-localnet index bacf8c19a4..1ed82c6b98 100644 --- a/Dockerfile-localnet +++ b/Dockerfile-localnet @@ -28,7 +28,7 @@ RUN go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.5.0 FROM golang:1.20.14-bookworm AS base-runtime RUN apt update && \ - apt install -yq jq curl tmux python3 openssh-server iputils-ping iproute2 && \ + apt install -yq jq yq curl tmux python3 openssh-server iputils-ping iproute2 && \ rm -rf /var/lib/apt/lists/* RUN ssh-keygen -A && \ @@ -46,6 +46,7 @@ ENV PATH /root/.zetacored/cosmovisor/current/bin/:/root/.zetaclientd/upgrades/cu COPY contrib/localnet/scripts /root COPY contrib/localnet/ssh_config /etc/ssh/ssh_config.d/localnet.conf COPY contrib/localnet/zetacored /root/zetacored +COPY cmd/zetae2e/config/localnet.yml /root/config.yml RUN chmod 755 /root/*.sh && \ chmod 644 /etc/ssh/ssh_config.d/localnet.conf diff --git a/cmd/zetae2e/README.md b/cmd/zetae2e/README.md index c57863e7cf..bdc043f7d2 100644 --- a/cmd/zetae2e/README.md +++ b/cmd/zetae2e/README.md @@ -24,9 +24,9 @@ This is an example of config for interaction with Athens3: ```go zeta_chain_id: "athens_7001-1" -accounts: +default_account: evm_address: "" - evm_priv_key: "" + private_key: "" rpcs: zevm: ", generally using port 8545" evm: ", generally using port 8545" @@ -101,9 +101,9 @@ Testing a gas token requires the following values to be defined in the config: ```go zeta_chain_id -accounts: +default_account: evm_address - evm_priv_key + private_key rpcs: zevm evm diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index bf1b543227..13df89430a 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -2,9 +2,7 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" @@ -54,21 +52,13 @@ func runBalances(cmd *cobra.Command, args []string) error { // initialize context ctx, cancel := context.WithCancel(context.Background()) - // get EVM address from config - evmAddr := conf.Accounts.EVMAddress - if !ethcommon.IsHexAddress(evmAddr) { - cancel() - return errors.New("invalid EVM address") - } - // initialize deployer runner with config r, err := zetae2econfig.RunnerFromConfig( ctx, "e2e", cancel, conf, - ethcommon.HexToAddress(evmAddr), - conf.Accounts.EVMPrivKey, + conf.DefaultAccount, logger, ) if err != nil { diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index 63eb26d386..6c9c5c3f4a 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -2,9 +2,7 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" @@ -54,21 +52,13 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { // initialize context ctx, cancel := context.WithCancel(context.Background()) - // get EVM address from config - evmAddr := conf.Accounts.EVMAddress - if !ethcommon.IsHexAddress(evmAddr) { - cancel() - return errors.New("invalid EVM address") - } - // initialize deployer runner with config r, err := zetae2econfig.RunnerFromConfig( ctx, "e2e", cancel, conf, - ethcommon.HexToAddress(evmAddr), - conf.Accounts.EVMPrivKey, + conf.DefaultAccount, logger, ) if err != nil { diff --git a/cmd/zetae2e/config/clients.go b/cmd/zetae2e/config/clients.go index ae56eaa9dd..8c6bb37106 100644 --- a/cmd/zetae2e/config/clients.go +++ b/cmd/zetae2e/config/clients.go @@ -8,7 +8,6 @@ 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/crypto" "github.com/ethereum/go-ethereum/ethclient" "google.golang.org/grpc" @@ -20,7 +19,7 @@ import ( ) // getClientsFromConfig get clients from config -func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey string) ( +func getClientsFromConfig(ctx context.Context, conf config.Config, account config.Account) ( *rpcclient.Client, *ethclient.Client, *bind.TransactOpts, @@ -38,7 +37,7 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st if err != nil { return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err) } - evmClient, evmAuth, err := getEVMClient(ctx, conf.RPCs.EVM, evmPrivKey) + evmClient, evmAuth, err := getEVMClient(ctx, conf.RPCs.EVM, account) if err != nil { return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err) } @@ -48,7 +47,7 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st if err != nil { return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err) } - zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, evmPrivKey) + zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, account) if err != nil { return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err) } @@ -91,7 +90,11 @@ func getBtcClient(rpcConf config.BitcoinRPC) (*rpcclient.Client, error) { } // getEVMClient get evm client -func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client, *bind.TransactOpts, error) { +func getEVMClient( + ctx context.Context, + rpc string, + account config.Account, +) (*ethclient.Client, *bind.TransactOpts, error) { evmClient, err := ethclient.Dial(rpc) if err != nil { return nil, nil, fmt.Errorf("failed to dial evm client: %w", err) @@ -101,11 +104,11 @@ func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client, if err != nil { return nil, nil, fmt.Errorf("failed to get chain id: %w", err) } - deployerPrivkey, err := crypto.HexToECDSA(privKey) + privKey, err := account.PrivateKey() if err != nil { return nil, nil, fmt.Errorf("failed to get deployer privkey: %w", err) } - evmAuth, err := bind.NewKeyedTransactorWithChainID(deployerPrivkey, chainid) + evmAuth, err := bind.NewKeyedTransactorWithChainID(privKey, chainid) if err != nil { return nil, nil, fmt.Errorf("failed to get keyed transactor: %w", err) } diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 7918a9a9ae..a0aedef1a6 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -4,8 +4,6 @@ import ( "context" "fmt" - ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" ) @@ -16,8 +14,7 @@ func RunnerFromConfig( name string, ctxCancel context.CancelFunc, conf config.Config, - evmUserAddr ethcommon.Address, - evmUserPrivKey string, + account config.Account, logger *runner.Logger, opts ...runner.E2ERunnerOption, ) (*runner.E2ERunner, error) { @@ -33,7 +30,7 @@ func RunnerFromConfig( lightClient, zevmClient, zevmAuth, - err := getClientsFromConfig(ctx, conf, evmUserPrivKey) + err := getClientsFromConfig(ctx, conf, account) if err != nil { return nil, fmt.Errorf("failed to get clients from config: %w", err) } @@ -43,8 +40,7 @@ func RunnerFromConfig( ctx, name, ctxCancel, - evmUserAddr, - evmUserPrivKey, + account, evmClient, zevmClient, cctxClient, @@ -79,23 +75,23 @@ 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 = r.ZetaEthAddr.Hex() - conf.Contracts.EVM.ConnectorEthAddr = r.ConnectorEthAddr.Hex() - conf.Contracts.EVM.CustodyAddr = r.ERC20CustodyAddr.Hex() - conf.Contracts.EVM.ERC20 = r.ERC20Addr.Hex() - conf.Contracts.EVM.TestDappAddr = r.EvmTestDAppAddr.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()) + conf.Contracts.EVM.TestDappAddr = config.DoubleQuotedString(r.EvmTestDAppAddr.Hex()) - conf.Contracts.ZEVM.SystemContractAddr = r.SystemContractAddr.Hex() - conf.Contracts.ZEVM.ETHZRC20Addr = r.ETHZRC20Addr.Hex() - conf.Contracts.ZEVM.ERC20ZRC20Addr = r.ERC20ZRC20Addr.Hex() - conf.Contracts.ZEVM.BTCZRC20Addr = r.BTCZRC20Addr.Hex() - conf.Contracts.ZEVM.UniswapFactoryAddr = r.UniswapV2FactoryAddr.Hex() - conf.Contracts.ZEVM.UniswapRouterAddr = r.UniswapV2RouterAddr.Hex() - conf.Contracts.ZEVM.ConnectorZEVMAddr = r.ConnectorZEVMAddr.Hex() - conf.Contracts.ZEVM.WZetaAddr = r.WZetaAddr.Hex() - conf.Contracts.ZEVM.ZEVMSwapAppAddr = r.ZEVMSwapAppAddr.Hex() - conf.Contracts.ZEVM.ContextAppAddr = r.ContextAppAddr.Hex() - conf.Contracts.ZEVM.TestDappAddr = r.ZevmTestDAppAddr.Hex() + conf.Contracts.ZEVM.SystemContractAddr = config.DoubleQuotedString(r.SystemContractAddr.Hex()) + conf.Contracts.ZEVM.ETHZRC20Addr = config.DoubleQuotedString(r.ETHZRC20Addr.Hex()) + conf.Contracts.ZEVM.ERC20ZRC20Addr = config.DoubleQuotedString(r.ERC20ZRC20Addr.Hex()) + conf.Contracts.ZEVM.BTCZRC20Addr = config.DoubleQuotedString(r.BTCZRC20Addr.Hex()) + conf.Contracts.ZEVM.UniswapFactoryAddr = config.DoubleQuotedString(r.UniswapV2FactoryAddr.Hex()) + conf.Contracts.ZEVM.UniswapRouterAddr = config.DoubleQuotedString(r.UniswapV2RouterAddr.Hex()) + conf.Contracts.ZEVM.ConnectorZEVMAddr = config.DoubleQuotedString(r.ConnectorZEVMAddr.Hex()) + conf.Contracts.ZEVM.WZetaAddr = config.DoubleQuotedString(r.WZetaAddr.Hex()) + conf.Contracts.ZEVM.ZEVMSwapAppAddr = config.DoubleQuotedString(r.ZEVMSwapAppAddr.Hex()) + conf.Contracts.ZEVM.ContextAppAddr = config.DoubleQuotedString(r.ContextAppAddr.Hex()) + conf.Contracts.ZEVM.TestDappAddr = config.DoubleQuotedString(r.ZevmTestDAppAddr.Hex()) return conf } diff --git a/cmd/zetae2e/config/config_test.go b/cmd/zetae2e/config/config_test.go new file mode 100644 index 0000000000..f8eb98a01e --- /dev/null +++ b/cmd/zetae2e/config/config_test.go @@ -0,0 +1,40 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/e2e/config" +) + +func TestReadConfig(t *testing.T) { + tests := []struct { + name string + filePath string + expectNoError bool + expectNotEmpty bool + }{ + { + name: "ReadLocalnetConfig", + filePath: "localnet.yml", + expectNoError: true, + expectNotEmpty: true, + }, + { + name: "ReadLocalConfig", + filePath: "local.yml", + expectNoError: true, + expectNotEmpty: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + conf, err := config.ReadConfig(tt.filePath) + require.NoError(t, err) + require.NotEmpty(t, conf.DefaultAccount.RawEVMAddress) + require.NotEmpty(t, conf.DefaultAccount.RawPrivateKey) + }) + } +} diff --git a/cmd/zetae2e/config/contracts.go b/cmd/zetae2e/config/contracts.go index a47b39ef4e..110038298a 100644 --- a/cmd/zetae2e/config/contracts.go +++ b/cmd/zetae2e/config/contracts.go @@ -3,7 +3,6 @@ package config import ( "fmt" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol" zetaeth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zeta.eth.sol" zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol" @@ -26,169 +25,173 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { var err error // set EVM contracts - if c := conf.Contracts.EVM.ZetaEthAddress; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ZetaEthAddress: %s", c) + if c := conf.Contracts.EVM.ZetaEthAddr; c != "" { + r.ZetaEthAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ZetaEthAddr: %w", err) } - r.ZetaEthAddr = ethcommon.HexToAddress(c) r.ZetaEth, err = zetaeth.NewZetaEth(r.ZetaEthAddr, r.EVMClient) if err != nil { return err } } + if c := conf.Contracts.EVM.ConnectorEthAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ConnectorEthAddr: %s", c) + r.ConnectorEthAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ConnectorEthAddr: %w", err) } - r.ConnectorEthAddr = ethcommon.HexToAddress(c) r.ConnectorEth, err = zetaconnectoreth.NewZetaConnectorEth(r.ConnectorEthAddr, r.EVMClient) if err != nil { return err } } + if c := conf.Contracts.EVM.CustodyAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid CustodyAddr: %s", c) + r.ERC20CustodyAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid CustodyAddr: %w", err) } - r.ERC20CustodyAddr = ethcommon.HexToAddress(c) r.ERC20Custody, err = erc20custody.NewERC20Custody(r.ERC20CustodyAddr, r.EVMClient) if err != nil { return err } } + if c := conf.Contracts.EVM.ERC20; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ERC20: %s", c) + r.ERC20Addr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ERC20: %w", err) } - r.ERC20Addr = ethcommon.HexToAddress(c) r.ERC20, err = erc20.NewERC20(r.ERC20Addr, r.EVMClient) if err != nil { return err } } - // set Zevm contracts + // set ZEVM contracts if c := conf.Contracts.ZEVM.SystemContractAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid SystemContractAddr: %s", c) + r.SystemContractAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid SystemContractAddr: %w", err) } - r.SystemContractAddr = ethcommon.HexToAddress(c) r.SystemContract, err = systemcontract.NewSystemContract(r.SystemContractAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ETHZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ETHZRC20Addr: %s", c) + r.ETHZRC20Addr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ETHZRC20Addr: %w", err) } - r.ETHZRC20Addr = ethcommon.HexToAddress(c) r.ETHZRC20, err = zrc20.NewZRC20(r.ETHZRC20Addr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ERC20ZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ERC20ZRC20Addr: %s", c) + r.ERC20ZRC20Addr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ERC20ZRC20Addr: %w", err) } - r.ERC20ZRC20Addr = ethcommon.HexToAddress(c) r.ERC20ZRC20, err = zrc20.NewZRC20(r.ERC20ZRC20Addr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.BTCZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid BTCZRC20Addr: %s", c) - } - r.BTCZRC20Addr = ethcommon.HexToAddress(c) - r.BTCZRC20, err = zrc20.NewZRC20(r.BTCZRC20Addr, r.ZEVMClient) + r.BTCZRC20Addr, err = c.AsEVMAddress() if err != nil { - return err - } - } - if c := conf.Contracts.ZEVM.ERC20ZRC20Addr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ERC20ZRC20Addr: %s", c) + return fmt.Errorf("invalid BTCZRC20Addr: %w", err) } - r.ERC20ZRC20Addr = ethcommon.HexToAddress(c) - r.ERC20ZRC20, err = zrc20.NewZRC20(r.ERC20ZRC20Addr, r.ZEVMClient) + r.BTCZRC20, err = zrc20.NewZRC20(r.BTCZRC20Addr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.UniswapFactoryAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid UniswapFactoryAddr: %s", c) + r.UniswapV2FactoryAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid UniswapFactoryAddr: %w", err) } - r.UniswapV2FactoryAddr = ethcommon.HexToAddress(c) r.UniswapV2Factory, err = uniswapv2factory.NewUniswapV2Factory(r.UniswapV2FactoryAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.UniswapRouterAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid UniswapRouterAddr: %s", c) + r.UniswapV2RouterAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid UniswapRouterAddr: %w", err) } - r.UniswapV2RouterAddr = ethcommon.HexToAddress(c) r.UniswapV2Router, err = uniswapv2router.NewUniswapV2Router02(r.UniswapV2RouterAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ConnectorZEVMAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ConnectorZEVMAddr: %s", c) + r.ConnectorZEVMAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ConnectorZEVMAddr: %w", err) } - r.ConnectorZEVMAddr = ethcommon.HexToAddress(c) r.ConnectorZEVM, err = connectorzevm.NewZetaConnectorZEVM(r.ConnectorZEVMAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.WZetaAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid WZetaAddr: %s", c) + r.WZetaAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid WZetaAddr: %w", err) } - r.WZetaAddr = ethcommon.HexToAddress(c) r.WZeta, err = wzeta.NewWETH9(r.WZetaAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ZEVMSwapAppAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ZEVMSwapAppAddr: %s", c) + r.ZEVMSwapAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ZEVMSwapAppAddr: %w", err) } - r.ZEVMSwapAppAddr = ethcommon.HexToAddress(c) r.ZEVMSwapApp, err = zevmswap.NewZEVMSwapApp(r.ZEVMSwapAppAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.ContextAppAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ContextAppAddr: %s", c) + r.ContextAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ContextAppAddr: %w", err) } - r.ContextAppAddr = ethcommon.HexToAddress(c) r.ContextApp, err = contextapp.NewContextApp(r.ContextAppAddr, r.ZEVMClient) if err != nil { return err } } + if c := conf.Contracts.ZEVM.TestDappAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid ZevmTestDappAddr: %s", c) + r.ZevmTestDAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid ZevmTestDappAddr: %w", err) } - r.ZevmTestDAppAddr = ethcommon.HexToAddress(c) } + if c := conf.Contracts.EVM.TestDappAddr; c != "" { - if !ethcommon.IsHexAddress(c) { - return fmt.Errorf("invalid EvmTestDappAddr: %s", c) + r.EvmTestDAppAddr, err = c.AsEVMAddress() + if err != nil { + return fmt.Errorf("invalid EvmTestDappAddr: %w", err) } - r.EvmTestDAppAddr = ethcommon.HexToAddress(c) } return nil diff --git a/cmd/zetae2e/config/example.yml b/cmd/zetae2e/config/example.yml index be692b9d4c..21cdd6de36 100644 --- a/cmd/zetae2e/config/example.yml +++ b/cmd/zetae2e/config/example.yml @@ -1,7 +1,7 @@ zeta_chain_id: "athens_7001-1" -accounts: +default_account: evm_address: "" - evm_priv_key: "" + private_key: "" rpcs: zevm: ", generally using port 8545" evm: ", generally using port 8545" diff --git a/cmd/zetae2e/config/local.yml b/cmd/zetae2e/config/local.yml index ae2638ace7..ee5e171ccc 100644 --- a/cmd/zetae2e/config/local.yml +++ b/cmd/zetae2e/config/local.yml @@ -1,7 +1,8 @@ zeta_chain_id: "athens_7001-1" -accounts: +default_account: + bech32_address: zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd evm_address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC" - evm_priv_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263" + private_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263" rpcs: zevm: "http://0.0.0.0:9545" evm: "http://0.0.0.0:8545" diff --git a/cmd/zetae2e/config/localnet.yml b/cmd/zetae2e/config/localnet.yml new file mode 100644 index 0000000000..abb780db39 --- /dev/null +++ b/cmd/zetae2e/config/localnet.yml @@ -0,0 +1,51 @@ +zeta_chain_id: "athens_101-1" +default_account: + bech32_address: "zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd" + evm_address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC" + private_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263" +additional_accounts: + user_erc20: + bech32_address: "zeta1datate7xmwm4uk032f9rmcu0cwy7ch7kg6y6zv" + evm_address: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6" + private_key: "fda3be1b1517bdf48615bdadacc1e6463d2865868dc8077d2cdcfa4709a16894" + user_zeta_test: + bech32_address: "zeta1tnp0hvsq4y5mxuhrq9h3jfwulxywpq0ads0rer" + evm_address: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd" + private_key: "729a6cdc5c925242e7df92fdeeb94dadbf2d0b9950d4db8f034ab27a3b114ba7" + user_zevm_mp_test: + bech32_address: "zeta13t3zjxvwec7g38q8mdjga37rpes9zkfvv7tkn2" + evm_address: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c" + private_key: "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d" + user_bitcoin: + bech32_address: "zeta19q7czqysah6qg0n4y3l2a08gfzqxydla492v80" + evm_address: "0x283d810090EdF4043E75247eAeBcE848806237fD" + private_key: "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a" + user_ether: + bech32_address: "zeta134rakuus43xn63yucgxhn88ywj8ewcv6ezn2ga" + evm_address: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A" + private_key: "098e74a1c2261fa3c1b8cfca8ef2b4ff96c73ce36710d208d1f6535aef42545d" + user_misc: + bech32_address: "zeta1jqfx6qhyrj0t9ggvl3p64vaax3s9y0xldt020w" + evm_address: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf" + private_key: "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4" + user_admin: + bech32_address: "zeta17w0adeg64ky0daxwd2ugyuneellmjgnx4e483s" + evm_address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + private_key: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" + user_fungible_admin: + bech32_address: "zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3" + evm_address: "0x8305C114Ea73cAc4A88f39A173803F94741b9055" + private_key: "d88d09a7d6849c15a36eb6931f9dd616091a63e9849a2cc86f309ba11fb8fec5" +rpcs: + zevm: "http://zetacore0:8545" + evm: "http://eth:8545" + bitcoin: + host: "bitcoin:18443" + user: "smoketest" + pass: "123" + http_post_mode: true + disable_tls: true + params: regnet + zetacore_grpc: "zetacore0:9090" + zetacore_rpc: "http://zetacore0:26657" +# contracts will be populated on first run \ No newline at end of file diff --git a/cmd/zetae2e/init.go b/cmd/zetae2e/init.go index b35f42ff97..742b3ebd96 100644 --- a/cmd/zetae2e/init.go +++ b/cmd/zetae2e/init.go @@ -16,7 +16,7 @@ func NewInitCmd() *cobra.Command { var InitCmd = &cobra.Command{ Use: "init", Short: "initialize config file for e2e tests", - Run: initConfig, + RunE: initConfig, } InitCmd.Flags().StringVar(&initConf.RPCs.EVM, "ethURL", "http://eth:8545", "--ethURL http://eth:8545") @@ -33,9 +33,14 @@ func NewInitCmd() *cobra.Command { return InitCmd } -func initConfig(_ *cobra.Command, _ []string) { - err := config.WriteConfig(configFile, initConf) +func initConfig(_ *cobra.Command, _ []string) error { + err := initConf.GenerateKeys() if err != nil { - fmt.Printf("error writing config file: %s", err.Error()) + return fmt.Errorf("generating keys: %w", err) } + err = config.WriteConfig(configFile, initConf) + if err != nil { + return fmt.Errorf("writing config: %w", err) + } + return nil } diff --git a/cmd/zetae2e/local/accounts.go b/cmd/zetae2e/local/accounts.go deleted file mode 100644 index 16ab7d97a4..0000000000 --- a/cmd/zetae2e/local/accounts.go +++ /dev/null @@ -1,44 +0,0 @@ -package local - -import ( - ethcommon "github.com/ethereum/go-ethereum/common" -) - -var ( - // DeployerAddress is the address of the account for deploying networks - DeployerAddress = ethcommon.HexToAddress("0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC") - DeployerPrivateKey = "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263" // #nosec G101 - used for testing - - // UserERC20Address is the address of the account for testing ERC20 - UserERC20Address = ethcommon.HexToAddress("0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6") - UserERC20PrivateKey = "fda3be1b1517bdf48615bdadacc1e6463d2865868dc8077d2cdcfa4709a16894" // #nosec G101 - used for testing - - // UserZetaTestAddress is the address of the account for testing Zeta transfers - UserZetaTestAddress = ethcommon.HexToAddress("0x5cC2fBb200A929B372e3016F1925DcF988E081fd") - UserZetaTestPrivateKey = "729a6cdc5c925242e7df92fdeeb94dadbf2d0b9950d4db8f034ab27a3b114ba7" // #nosec G101 - used for testing - - // UserZEVMMPTestAddress is the address of the account for testing ZEVM Message Passing - UserZEVMMPTestAddress = ethcommon.HexToAddress("0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c") - UserZEVMMPTestPrivateKey = "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d" // #nosec G101 - used for testing - - // UserBitcoinAddress is the address of the account for testing Bitcoin - UserBitcoinAddress = ethcommon.HexToAddress("0x283d810090EdF4043E75247eAeBcE848806237fD") - UserBitcoinPrivateKey = "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a" // #nosec G101 - used for testing - - // UserEtherAddress is the address of the account for testing Ether - UserEtherAddress = ethcommon.HexToAddress("0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A") - UserEtherPrivateKey = "098e74a1c2261fa3c1b8cfca8ef2b4ff96c73ce36710d208d1f6535aef42545d" // #nosec G101 - used for testing - - // UserMiscAddress is the address of the account for miscellaneous tests - UserMiscAddress = ethcommon.HexToAddress("0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf") - UserMiscPrivateKey = "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4" // #nosec G101 - used for testing - - // UserAdminAddress is the address of the account for testing admin function features - // NOTE: this is the default account using Anvil - UserAdminAddress = ethcommon.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266") - UserAdminPrivateKey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" // #nosec G101 - used for testing - - // FungibleAdminAddress is the address of the account for testing the fungible admin functions - UserFungibleAdminAddress = ethcommon.HexToAddress("0x8305C114Ea73cAc4A88f39A173803F94741b9055") - UserFungibleAdminPrivateKey = "d88d09a7d6849c15a36eb6931f9dd616091a63e9849a2cc86f309ba11fb8fec5" // #nosec G101 - used for testing -) diff --git a/cmd/zetae2e/local/admin.go b/cmd/zetae2e/local/admin.go index 63cff6fe23..bc76aeeedc 100644 --- a/cmd/zetae2e/local/admin.go +++ b/cmd/zetae2e/local/admin.go @@ -19,13 +19,13 @@ func adminTestRoutine( testNames ...string, ) func() error { return func() (err error) { + account := conf.AdditionalAccounts.UserAdmin // initialize runner for erc20 advanced test adminRunner, err := initTestRunner( "admin", conf, deployerRunner, - UserAdminAddress, - UserAdminPrivateKey, + account, runner.NewLogger(verbose, color.FgHiGreen, "admin"), runner.WithZetaTxServer(deployerRunner.ZetaTxServer), ) @@ -38,8 +38,8 @@ func adminTestRoutine( // funding the account // we transfer around the total supply of Zeta to the admin for the chain migration test - txZetaSend := deployerRunner.SendZetaOnEvm(UserAdminAddress, 20_500_000_000) - txERC20Send := deployerRunner.SendERC20OnEvm(UserAdminAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 20_500_000_000) + txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000) adminRunner.WaitForTxReceiptOnEvm(txZetaSend) adminRunner.WaitForTxReceiptOnEvm(txERC20Send) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index cfb0501a8c..05098fd5a9 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -21,13 +21,13 @@ func bitcoinTestRoutine( testNames ...string, ) func() error { return func() (err error) { + account := conf.AdditionalAccounts.UserBitcoin // initialize runner for bitcoin test bitcoinRunner, err := initTestRunner( "bitcoin", conf, deployerRunner, - UserBitcoinAddress, - UserBitcoinPrivateKey, + account, runner.NewLogger(verbose, color.FgYellow, "bitcoin"), ) if err != nil { @@ -38,7 +38,7 @@ func bitcoinTestRoutine( startTime := time.Now() // funding the account - txERC20Send := deployerRunner.SendERC20OnEvm(UserBitcoinAddress, 1000) + txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 1000) bitcoinRunner.WaitForTxReceiptOnEvm(txERC20Send) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/local/config.go b/cmd/zetae2e/local/config.go index 98ece83ac0..8788024b7d 100644 --- a/cmd/zetae2e/local/config.go +++ b/cmd/zetae2e/local/config.go @@ -1,6 +1,7 @@ package local import ( + "fmt" "path/filepath" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,12 +15,7 @@ import ( func GetConfig(cmd *cobra.Command) (config.Config, error) { configFile, err := cmd.Flags().GetString(FlagConfigFile) if err != nil { - return config.Config{}, err - } - - // use default config if no config file is specified - if configFile == "" { - return config.DefaultConfig(), nil + return config.Config{}, fmt.Errorf("--config is a required parameter") } configFile, err = filepath.Abs(configFile) diff --git a/cmd/zetae2e/local/erc20.go b/cmd/zetae2e/local/erc20.go index fe0fa8bb8a..8b0d21e564 100644 --- a/cmd/zetae2e/local/erc20.go +++ b/cmd/zetae2e/local/erc20.go @@ -19,13 +19,13 @@ func erc20TestRoutine( testNames ...string, ) func() error { return func() (err error) { + account := conf.AdditionalAccounts.UserERC20 // initialize runner for erc20 test erc20Runner, err := initTestRunner( "erc20", conf, deployerRunner, - UserERC20Address, - UserERC20PrivateKey, + account, runner.NewLogger(verbose, color.FgGreen, "erc20"), runner.WithZetaTxServer(deployerRunner.ZetaTxServer), ) @@ -37,7 +37,7 @@ func erc20TestRoutine( startTime := time.Now() // funding the account - txERC20Send := deployerRunner.SendERC20OnEvm(UserERC20Address, 10) + txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10) erc20Runner.WaitForTxReceiptOnEvm(txERC20Send) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/local/ethereum.go b/cmd/zetae2e/local/ethereum.go index fa9e7754e2..ae2eebc268 100644 --- a/cmd/zetae2e/local/ethereum.go +++ b/cmd/zetae2e/local/ethereum.go @@ -25,8 +25,7 @@ func ethereumTestRoutine( "ether", conf, deployerRunner, - UserEtherAddress, - UserEtherPrivateKey, + conf.AdditionalAccounts.UserEther, runner.NewLogger(verbose, color.FgMagenta, "ether"), ) if err != nil { diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index bd9dd654a2..7e00f9ba5b 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -127,7 +127,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { zetaTxServer, err := txserver.NewZetaTxServer( conf.RPCs.ZetaCoreRPC, []string{utils.FungibleAdminName}, - []string{UserFungibleAdminPrivateKey}, + []string{conf.AdditionalAccounts.UserFungibleAdmin.RawPrivateKey.String()}, conf.ZetaChainID, ) noError(err) @@ -138,8 +138,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { "deployer", cancel, conf, - DeployerAddress, - DeployerPrivateKey, + conf.DefaultAccount, logger, runner.WithZetaTxServer(zetaTxServer), ) diff --git a/cmd/zetae2e/local/misc.go b/cmd/zetae2e/local/misc.go index 65467ec9e5..a27c93c932 100644 --- a/cmd/zetae2e/local/misc.go +++ b/cmd/zetae2e/local/misc.go @@ -19,13 +19,13 @@ func miscTestRoutine( testNames ...string, ) func() error { return func() (err error) { + account := conf.AdditionalAccounts.UserMisc // initialize runner for misc test miscRunner, err := initTestRunner( "misc", conf, deployerRunner, - UserMiscAddress, - UserMiscPrivateKey, + account, runner.NewLogger(verbose, color.FgCyan, "misc"), ) if err != nil { @@ -36,7 +36,7 @@ func miscTestRoutine( startTime := time.Now() // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(UserMiscAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) miscRunner.WaitForTxReceiptOnEvm(txZetaSend) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/local/performance.go b/cmd/zetae2e/local/performance.go index 7d289c4e90..4039084550 100644 --- a/cmd/zetae2e/local/performance.go +++ b/cmd/zetae2e/local/performance.go @@ -27,8 +27,7 @@ func ethereumDepositPerformanceRoutine( "ether", conf, deployerRunner, - UserERC20Address, - UserERC20PrivateKey, + conf.AdditionalAccounts.UserERC20, runner.NewLogger(verbose, color.FgHiMagenta, "perf_eth_deposit"), ) if err != nil { @@ -69,8 +68,7 @@ func ethereumWithdrawPerformanceRoutine( "ether", conf, deployerRunner, - UserEtherAddress, - UserEtherPrivateKey, + conf.AdditionalAccounts.UserEther, runner.NewLogger(verbose, color.FgHiBlue, "perf_eth_withdraw"), ) if err != nil { diff --git a/cmd/zetae2e/local/test_runner.go b/cmd/zetae2e/local/test_runner.go index f2fe0ae811..198260c05c 100644 --- a/cmd/zetae2e/local/test_runner.go +++ b/cmd/zetae2e/local/test_runner.go @@ -1,8 +1,6 @@ package local import ( - ethcommon "github.com/ethereum/go-ethereum/common" - zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" @@ -14,8 +12,7 @@ func initTestRunner( name string, conf config.Config, deployerRunner *runner.E2ERunner, - userAddress ethcommon.Address, - userPrivKey string, + account config.Account, logger *runner.Logger, opts ...runner.E2ERunnerOption, ) (*runner.E2ERunner, error) { @@ -25,8 +22,7 @@ func initTestRunner( name, deployerRunner.CtxCancel, conf, - userAddress, - userPrivKey, + account, logger, opts..., ) diff --git a/cmd/zetae2e/local/zeta.go b/cmd/zetae2e/local/zeta.go index 6f5039b63f..3fdb4f48cc 100644 --- a/cmd/zetae2e/local/zeta.go +++ b/cmd/zetae2e/local/zeta.go @@ -19,13 +19,13 @@ func zetaTestRoutine( testNames ...string, ) func() error { return func() (err error) { + account := conf.AdditionalAccounts.UserZetaTest // initialize runner for zeta test zetaRunner, err := initTestRunner( "zeta", conf, deployerRunner, - UserZetaTestAddress, - UserZetaTestPrivateKey, + account, runner.NewLogger(verbose, color.FgBlue, "zeta"), ) if err != nil { @@ -36,7 +36,7 @@ func zetaTestRoutine( startTime := time.Now() // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(UserZetaTestAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) zetaRunner.WaitForTxReceiptOnEvm(txZetaSend) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/local/zevm_mp.go b/cmd/zetae2e/local/zevm_mp.go index f95fa24390..bc97c45e29 100644 --- a/cmd/zetae2e/local/zevm_mp.go +++ b/cmd/zetae2e/local/zevm_mp.go @@ -19,13 +19,13 @@ func zevmMPTestRoutine( testNames ...string, ) func() error { return func() (err error) { + account := conf.AdditionalAccounts.UserZEVMMPTest // initialize runner for zevm mp test zevmMPRunner, err := initTestRunner( "zevm_mp", conf, deployerRunner, - UserZEVMMPTestAddress, - UserZEVMMPTestPrivateKey, + account, runner.NewLogger(verbose, color.FgHiRed, "zevm_mp"), ) if err != nil { @@ -36,7 +36,7 @@ func zevmMPTestRoutine( startTime := time.Now() // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(UserZEVMMPTestAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(account.EVMAddress(), 1000) zevmMPRunner.WaitForTxReceiptOnEvm(txZetaSend) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index 7d57500823..9c36d8e3d2 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -8,7 +8,6 @@ import ( "strings" "time" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" @@ -75,20 +74,13 @@ func runE2ETest(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - // get EVM address from config - evmAddr := conf.Accounts.EVMAddress - if !ethcommon.IsHexAddress(evmAddr) { - return errors.New("invalid EVM address") - } - // initialize deployer runner with config testRunner, err := zetae2econfig.RunnerFromConfig( ctx, "e2e", cancel, conf, - ethcommon.HexToAddress(evmAddr), - conf.Accounts.EVMPrivKey, + conf.DefaultAccount, logger, ) if err != nil { diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index f77924e768..99a5365adc 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -2,9 +2,7 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" @@ -42,20 +40,13 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { // initialize context ctx, cancel := context.WithCancel(context.Background()) - // get EVM address from config - evmAddr := conf.Accounts.EVMAddress - if !ethcommon.IsHexAddress(evmAddr) { - cancel() - return errors.New("invalid EVM address") - } // initialize deployer runner with config r, err := zetae2econfig.RunnerFromConfig( ctx, "e2e", cancel, conf, - ethcommon.HexToAddress(evmAddr), - conf.Accounts.EVMPrivKey, + conf.DefaultAccount, logger, ) if err != nil { diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 780a525b19..01b61317a1 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -2,9 +2,7 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" @@ -42,21 +40,13 @@ func runShowTSS(_ *cobra.Command, args []string) error { // initialize context ctx, cancel := context.WithCancel(context.Background()) - // get EVM address from config - evmAddr := conf.Accounts.EVMAddress - if !ethcommon.IsHexAddress(evmAddr) { - cancel() - return errors.New("invalid EVM address") - } - // initialize deployer runner with config testRunner, err := zetae2econfig.RunnerFromConfig( ctx, "tss", cancel, conf, - ethcommon.HexToAddress(evmAddr), - conf.Accounts.EVMPrivKey, + conf.DefaultAccount, logger, ) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index ca0446cbc9..30b2faf924 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -12,7 +12,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/accounts/abi/bind" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/fatih/color" "github.com/spf13/cobra" @@ -38,12 +37,10 @@ var ( ) type stressArguments struct { - deployerAddress string - deployerPrivateKey string - network string - txnInterval int64 - contractsDeployed bool - config string + network string + txnInterval int64 + contractsDeployed bool + config string } var stressTestArgs = stressArguments{} @@ -57,10 +54,6 @@ func NewStressTestCmd() *cobra.Command { Run: StressTest, } - StressCmd.Flags(). - StringVar(&stressTestArgs.deployerAddress, "addr", "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", "--addr ") - StressCmd.Flags(). - StringVar(&stressTestArgs.deployerPrivateKey, "privKey", "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263", "--privKey ") StressCmd.Flags().StringVar(&stressTestArgs.network, "network", "LOCAL", "--network TESTNET") StressCmd.Flags(). Int64Var(&stressTestArgs.txnInterval, "tx-interval", 500, "--tx-interval [TIME_INTERVAL_MILLISECONDS]") @@ -69,8 +62,6 @@ func NewStressTestCmd() *cobra.Command { StressCmd.Flags().StringVar(&stressTestArgs.config, local.FlagConfigFile, "", "config file to use for the E2E test") StressCmd.Flags().Bool(flagVerbose, false, "set to true to enable verbose logging") - local.DeployerAddress = ethcommon.HexToAddress(stressTestArgs.deployerAddress) - return StressCmd } @@ -93,11 +84,13 @@ func StressTest(cmd *cobra.Command, _ []string) { // initialize E2E tests config conf := must(local.GetConfig(cmd)) + deployerAccount := conf.DefaultAccount + // Initialize clients ---------------------------------------------------------------- evmClient := must(ethclient.Dial(conf.RPCs.EVM)) - bal := must(evmClient.BalanceAt(context.TODO(), local.DeployerAddress, nil)) + bal := must(evmClient.BalanceAt(context.TODO(), deployerAccount.EVMAddress(), nil)) - fmt.Printf("Deployer address: %s, balance: %d Wei\n", local.DeployerAddress.Hex(), bal) + fmt.Printf("Deployer address: %s, balance: %d Wei\n", deployerAccount.EVMAddress().Hex(), bal) grpcConn := must(grpc.Dial(conf.RPCs.ZetaCoreGRPC, grpc.WithInsecure())) @@ -136,8 +129,7 @@ func StressTest(cmd *cobra.Command, _ []string) { "deployer", cancel, conf, - local.DeployerAddress, - local.DeployerPrivateKey, + conf.DefaultAccount, logger, )) @@ -164,7 +156,7 @@ func StressTest(cmd *cobra.Command, _ []string) { } // Check zrc20 balance of Deployer address - ethZRC20Balance := must(e2eTest.ETHZRC20.BalanceOf(nil, local.DeployerAddress)) + ethZRC20Balance := must(e2eTest.ETHZRC20.BalanceOf(nil, deployerAccount.EVMAddress())) fmt.Printf("eth zrc20 balance: %s Wei \n", ethZRC20Balance.String()) //Pre-approve ETH withdraw on ZEVM @@ -179,7 +171,7 @@ func StressTest(cmd *cobra.Command, _ []string) { blockNum := must(e2eTest.ZEVMClient.BlockNumber(ctx)) // #nosec G701 e2eTest - always in range - nonce := must(e2eTest.ZEVMClient.NonceAt(ctx, local.DeployerAddress, big.NewInt(int64(blockNum)))) + nonce := must(e2eTest.ZEVMClient.NonceAt(ctx, deployerAccount.EVMAddress(), big.NewInt(int64(blockNum)))) // #nosec G701 e2e - always in range zevmNonce = big.NewInt(int64(nonce)) @@ -309,7 +301,7 @@ func WithdrawETHZRC20(r *runner.E2ERunner) { ethZRC20 := r.ETHZRC20 r.ZEVMAuth.Nonce = zevmNonce - must(ethZRC20.Withdraw(r.ZEVMAuth, local.DeployerAddress.Bytes(), big.NewInt(100))) + must(ethZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), big.NewInt(100))) } // Get ETH based chain ID diff --git a/contrib/localnet/orchestrator/Dockerfile.fastbuild b/contrib/localnet/orchestrator/Dockerfile.fastbuild index 2ef5520c64..96f437ed30 100644 --- a/contrib/localnet/orchestrator/Dockerfile.fastbuild +++ b/contrib/localnet/orchestrator/Dockerfile.fastbuild @@ -3,13 +3,14 @@ FROM ethereum/client-go:v1.10.26 as geth FROM golang:1.20.14-bookworm as orchestrator RUN apt update && \ - apt install -yq jq curl tmux python3 openssh-server iputils-ping iproute2 && \ + apt install -yq jq yq curl tmux python3 openssh-server iputils-ping iproute2 && \ rm -rf /var/lib/apt/lists/* COPY --from=geth /usr/local/bin/geth /usr/local/bin/ COPY --from=zeta /usr/local/bin/zetacored /usr/local/bin/zetaclientd /usr/local/bin/zetae2e /usr/local/bin/ COPY contrib/localnet/orchestrator/start-zetae2e.sh /work/ +COPY cmd/zetae2e/config/localnet.yml /work/config.yml RUN chmod +x /work/*.sh WORKDIR /work diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index 791f0a6074..676d55e26e 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -37,41 +37,45 @@ sleep 2 ### Create the accounts and fund them with Ether on local Ethereum network -# unlock the deployer account -echo "funding deployer address 0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +# unlock the default account account +address=$(yq -r '.default_account.evm_address' config.yml) +echo "funding deployer address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock erc20 tester accounts -echo "funding deployer address 0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6 with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_erc20.evm_address' config.yml) +echo "funding erc20 address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock zeta tester accounts -echo "funding deployer address 0x5cC2fBb200A929B372e3016F1925DcF988E081fd with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_zeta_test.evm_address' config.yml) +echo "funding zeta tester address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock zevm message passing tester accounts -echo "funding deployer address 0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_zevm_mp_test.evm_address' config.yml) +echo "funding zevm mp tester address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock bitcoin tester accounts -echo "funding deployer address 0x283d810090EdF4043E75247eAeBcE848806237fD with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x283d810090EdF4043E75247eAeBcE848806237fD", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_bitcoin.evm_address' config.yml) +echo "funding bitcoin tester address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock ethers tester accounts -echo "funding deployer address 0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_ether.evm_address' config.yml) +echo "funding ether tester address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock miscellaneous tests accounts -echo "funding deployer address 0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_misc.evm_address' config.yml) +echo "funding misc tester address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 # unlock admin erc20 tests accounts -echo "funding deployer address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", value: web3.toWei(10000,"ether")})' attach http://eth:8545 - -# unlock the TSS account -echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 10000 Ether" -geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", value: web3.toWei(10000,"ether")})' attach http://eth:8545 +address=$(yq -r '.additional_accounts.user_admin.evm_address' config.yml) +echo "funding admin tester address ${address} with 10000 Ether" +geth --exec "eth.sendTransaction({from: eth.coinbase, to: '${address}', value: web3.toWei(10000,'ether')})" attach http://eth:8545 ### Run zetae2e command depending on the option passed @@ -83,7 +87,7 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then UPGRADE_HEIGHT=${UPGRADE_HEIGHT:=225} if [[ ! -f deployed.yml ]]; then - zetae2e local $E2E_ARGS --setup-only --config-out deployed.yml --skip-header-proof + zetae2e local $E2E_ARGS --setup-only --config config.yml --config-out deployed.yml --skip-header-proof if [ $? -ne 0 ]; then echo "e2e setup failed" exit 1 @@ -159,7 +163,7 @@ else echo "running e2e setup..." if [[ ! -f deployed.yml ]]; then - zetae2e local $E2E_ARGS --setup-only --config-out deployed.yml + zetae2e local $E2E_ARGS --config config.yml --setup-only --config-out deployed.yml if [ $? -ne 0 ]; then echo "e2e setup failed" exit 1 diff --git a/contrib/localnet/scripts/start-zetacored.sh b/contrib/localnet/scripts/start-zetacored.sh index 29be9fb1ad..aba9538c5e 100755 --- a/contrib/localnet/scripts/start-zetacored.sh +++ b/contrib/localnet/scripts/start-zetacored.sh @@ -213,23 +213,30 @@ then fi # set admin account - zetacored add-genesis-account zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3 100000000000000000000000000azeta zetacored add-genesis-account zeta1n0rn6sne54hv7w2uu93fl48ncyqz97d3kty6sh 100000000000000000000000000azeta # Funds the localnet_gov_admin account - cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][0]["address"]="zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json - cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][1]["address"]="zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json - cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][2]["address"]="zeta1svzuz982w09vf2y08xsh8qplj36phyz466krj3"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + + address=$(yq -r '.additional_accounts.user_fungible_admin.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta + cat $HOME/.zetacored/config/genesis.json | jq --arg address "$address" '.app_state["authority"]["policies"]["items"][0]["address"] = $address' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq --arg address "$address" '.app_state["authority"]["policies"]["items"][1]["address"] = $address' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq --arg address "$address" '.app_state["authority"]["policies"]["items"][2]["address"] = $address' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json # give balance to runner accounts to deploy contracts directly on zEVM -# deployer - zetacored add-genesis-account zeta1uhznv7uzyjq84s3q056suc8pkme85lkvhrz3dd 100000000000000000000000000azeta +# default account + address=$(yq -r '.default_account.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # erc20 tester - zetacored add-genesis-account zeta1datate7xmwm4uk032f9rmcu0cwy7ch7kg6y6zv 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_erc20.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # zeta tester - zetacored add-genesis-account zeta1tnp0hvsq4y5mxuhrq9h3jfwulxywpq0ads0rer 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_zeta_test.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # bitcoin tester - zetacored add-genesis-account zeta19q7czqysah6qg0n4y3l2a08gfzqxydla492v80 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_bitcoin.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # ethers tester - zetacored add-genesis-account zeta134rakuus43xn63yucgxhn88ywj8ewcv6ezn2ga 100000000000000000000000000azeta + address=$(yq -r '.additional_accounts.user_ether.bech32_address' /root/config.yml) + zetacored add-genesis-account "$address" 100000000000000000000000000azeta # 3. Copy the genesis.json to all the nodes .And use it to create a gentx for every node zetacored gentx operator 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING --gas-prices 20000000000azeta diff --git a/e2e/config/config.go b/e2e/config/config.go index 450b02c5a3..66409ee339 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -1,26 +1,70 @@ package config import ( + "crypto/ecdsa" "errors" "fmt" "os" + "strings" "github.com/btcsuite/btcd/chaincfg" - "gopkg.in/yaml.v2" + "github.com/cosmos/cosmos-sdk/types/bech32" + ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" + "gopkg.in/yaml.v3" ) +// DoubleQuotedString forces a string to be double quoted when marshaling to yaml. +// This is required because of https://github.com/go-yaml/yaml/issues/847 +type DoubleQuotedString string + +func (s DoubleQuotedString) MarshalYAML() (interface{}, error) { + return yaml.Node{ + Value: string(s), + Kind: yaml.ScalarNode, + Style: yaml.DoubleQuotedStyle, + }, nil +} + +func (s DoubleQuotedString) String() string { + return string(s) +} + +func (s DoubleQuotedString) AsEVMAddress() (ethcommon.Address, error) { + if !ethcommon.IsHexAddress(string(s)) { + return ethcommon.Address{}, fmt.Errorf("invalid evm address: %s", string(s)) + } + return ethcommon.HexToAddress(string(s)), nil +} + // Config contains the configuration for the e2e test type Config struct { - Accounts Accounts `yaml:"accounts"` - RPCs RPCs `yaml:"rpcs"` - Contracts Contracts `yaml:"contracts"` - ZetaChainID string `yaml:"zeta_chain_id"` + // Default account to use when running tests and running setup + DefaultAccount Account `yaml:"default_account"` + AdditionalAccounts AdditionalAccounts `yaml:"additional_accounts"` + RPCs RPCs `yaml:"rpcs"` + Contracts Contracts `yaml:"contracts"` + ZetaChainID string `yaml:"zeta_chain_id"` +} + +// Account contains configuration for an account +type Account struct { + RawBech32Address DoubleQuotedString `yaml:"bech32_address"` + RawEVMAddress DoubleQuotedString `yaml:"evm_address"` + RawPrivateKey DoubleQuotedString `yaml:"private_key"` } -// Accounts contains the configuration for the accounts -type Accounts struct { - EVMAddress string `yaml:"evm_address"` - EVMPrivKey string `yaml:"evm_priv_key"` +// AdditionalAccounts are extra accounts required to run specific tests +type AdditionalAccounts struct { + UserERC20 Account `yaml:"user_erc20"` + UserZetaTest Account `yaml:"user_zeta_test"` + UserZEVMMPTest Account `yaml:"user_zevm_mp_test"` + UserBitcoin Account `yaml:"user_bitcoin"` + UserEther Account `yaml:"user_ether"` + UserMisc Account `yaml:"user_misc"` + UserAdmin Account `yaml:"user_admin"` + UserFungibleAdmin Account `yaml:"user_fungible_admin"` } // RPCs contains the configuration for the RPC endpoints @@ -50,26 +94,26 @@ type Contracts struct { // EVM contains the addresses of predeployed contracts on the EVM chain type EVM struct { - ZetaEthAddress string `yaml:"zeta_eth"` - ConnectorEthAddr string `yaml:"connector_eth"` - CustodyAddr string `yaml:"custody"` - ERC20 string `yaml:"erc20"` - TestDappAddr string `yaml:"test_dapp"` + ZetaEthAddr DoubleQuotedString `yaml:"zeta_eth"` + ConnectorEthAddr DoubleQuotedString `yaml:"connector_eth"` + CustodyAddr DoubleQuotedString `yaml:"custody"` + ERC20 DoubleQuotedString `yaml:"erc20"` + TestDappAddr DoubleQuotedString `yaml:"test_dapp"` } // ZEVM contains the addresses of predeployed contracts on the zEVM chain type ZEVM struct { - SystemContractAddr string `yaml:"system_contract"` - ETHZRC20Addr string `yaml:"eth_zrc20"` - ERC20ZRC20Addr string `yaml:"erc20_zrc20"` - BTCZRC20Addr string `yaml:"btc_zrc20"` - UniswapFactoryAddr string `yaml:"uniswap_factory"` - UniswapRouterAddr string `yaml:"uniswap_router"` - ConnectorZEVMAddr string `yaml:"connector_zevm"` - WZetaAddr string `yaml:"wzeta"` - ZEVMSwapAppAddr string `yaml:"zevm_swap_app"` - ContextAppAddr string `yaml:"context_app"` - TestDappAddr string `yaml:"test_dapp"` + SystemContractAddr DoubleQuotedString `yaml:"system_contract"` + ETHZRC20Addr DoubleQuotedString `yaml:"eth_zrc20"` + ERC20ZRC20Addr DoubleQuotedString `yaml:"erc20_zrc20"` + BTCZRC20Addr DoubleQuotedString `yaml:"btc_zrc20"` + UniswapFactoryAddr DoubleQuotedString `yaml:"uniswap_factory"` + UniswapRouterAddr DoubleQuotedString `yaml:"uniswap_router"` + ConnectorZEVMAddr DoubleQuotedString `yaml:"connector_zevm"` + WZetaAddr DoubleQuotedString `yaml:"wzeta"` + ZEVMSwapAppAddr DoubleQuotedString `yaml:"zevm_swap_app"` + ContextAppAddr DoubleQuotedString `yaml:"context_app"` + TestDappAddr DoubleQuotedString `yaml:"test_dapp"` } // DefaultConfig returns the default config using values for localnet testing @@ -137,6 +181,21 @@ func WriteConfig(file string, config Config) error { return nil } +// AsSlice gets all accounts as a slice rather than a +// struct +func (a AdditionalAccounts) AsSlice() []Account { + return []Account{ + a.UserERC20, + a.UserZetaTest, + a.UserZEVMMPTest, + a.UserBitcoin, + a.UserEther, + a.UserMisc, + a.UserAdmin, + a.UserFungibleAdmin, + } +} + // Validate validates the config func (c Config) Validate() error { if c.RPCs.Bitcoin.Params != Mainnet && @@ -144,6 +203,105 @@ func (c Config) Validate() error { c.RPCs.Bitcoin.Params != Regnet { return errors.New("invalid bitcoin params") } + + err := c.DefaultAccount.Validate() + if err != nil { + return fmt.Errorf("validating deployer account: %w", err) + } + + accounts := c.AdditionalAccounts.AsSlice() + for i, account := range accounts { + if account.RawEVMAddress == "" { + continue + } + err := account.Validate() + if err != nil { + return fmt.Errorf("validating account %d: %w", i, err) + } + } + return nil +} + +// GenerateKeys generates new key pairs for all accounts +func (c *Config) GenerateKeys() error { + var err error + c.DefaultAccount, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserERC20, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserZetaTest, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserZEVMMPTest, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserBitcoin, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserEther, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserMisc, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserAdmin, err = generateAccount() + if err != nil { + return err + } + c.AdditionalAccounts.UserFungibleAdmin, err = generateAccount() + if err != nil { + return err + } + return nil +} + +func (a Account) EVMAddress() ethcommon.Address { + return ethcommon.HexToAddress(a.RawEVMAddress.String()) +} + +func (a Account) PrivateKey() (*ecdsa.PrivateKey, error) { + return crypto.HexToECDSA(a.RawPrivateKey.String()) +} + +// Validate that the address and the private key specified in the +// config actually match +func (a Account) Validate() error { + privateKey, err := a.PrivateKey() + if err != nil { + return fmt.Errorf("invalid private key: %w", err) + } + privateKeyAddress := crypto.PubkeyToAddress(privateKey.PublicKey) + if a.RawEVMAddress.String() != privateKeyAddress.Hex() { + return fmt.Errorf( + "address derived from private key (%s) does not match configured address (%s)", + privateKeyAddress, + a.RawEVMAddress, + ) + } + _, _, err = bech32.DecodeAndConvert(a.RawBech32Address.String()) + if err != nil { + return fmt.Errorf("decoding bech32 address: %w", err) + } + bech32PrivateKeyAddress, err := bech32.ConvertAndEncode("zeta", privateKeyAddress.Bytes()) + if err != nil { + return fmt.Errorf("encoding private key to bech32: %w", err) + } + if a.RawBech32Address.String() != bech32PrivateKeyAddress { + return fmt.Errorf( + "address derived from private key (%s) does not match configured address (%s)", + bech32PrivateKeyAddress, + a.RawBech32Address, + ) + } return nil } @@ -170,3 +328,25 @@ func (bnt BitcoinNetworkType) GetParams() (chaincfg.Params, error) { return chaincfg.Params{}, fmt.Errorf("invalid bitcoin params %s", bnt) } } + +func generateAccount() (Account, error) { + privateKey, err := crypto.GenerateKey() + if err != nil { + return Account{}, fmt.Errorf("generating private key: %w", err) + } + // encode private key and strip 0x prefix + encodedPrivateKey := hexutil.Encode(crypto.FromECDSA(privateKey)) + encodedPrivateKey = strings.TrimPrefix(encodedPrivateKey, "0x") + + evmAddress := crypto.PubkeyToAddress(privateKey.PublicKey) + bech32Address, err := bech32.ConvertAndEncode("zeta", evmAddress.Bytes()) + if err != nil { + return Account{}, fmt.Errorf("bech32 convert and encode: %w", err) + } + + return Account{ + RawEVMAddress: DoubleQuotedString(evmAddress.String()), + RawPrivateKey: DoubleQuotedString(encodedPrivateKey), + RawBech32Address: DoubleQuotedString(bech32Address), + }, nil +} diff --git a/e2e/config/config_test.go b/e2e/config/config_test.go new file mode 100644 index 0000000000..033efb81b6 --- /dev/null +++ b/e2e/config/config_test.go @@ -0,0 +1,39 @@ +package config + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" +) + +// TestAdditionalAccountsSlicesSynced ensures than if any new accounts are added the +// AccountsSlice() function is updated +func TestConfigAdditionalAccountsSliceSynced(t *testing.T) { + additionalAccountsType := reflect.TypeOf(AdditionalAccounts{}) + numberOfAdditionalAccounts := additionalAccountsType.NumField() + + require.Greater(t, numberOfAdditionalAccounts, 0) + + conf := Config{} + err := conf.GenerateKeys() + require.NoError(t, err) + + additionalAccountsSlice := conf.AdditionalAccounts.AsSlice() + require.Len(t, additionalAccountsSlice, numberOfAdditionalAccounts) + + for _, account := range additionalAccountsSlice { + require.NoError(t, account.Validate()) + } +} + +func TestConfigInvalidAccount(t *testing.T) { + conf := Config{ + DefaultAccount: Account{ + RawEVMAddress: "asdf", + RawPrivateKey: "asdf", + }, + } + err := conf.Validate() + require.Error(t, err) +} diff --git a/e2e/e2etests/test_context_upgrade.go b/e2e/e2etests/test_context_upgrade.go index 4d06ee84d1..4a71b07428 100644 --- a/e2e/e2etests/test_context_upgrade.go +++ b/e2e/e2etests/test_context_upgrade.go @@ -57,7 +57,7 @@ func TestContextUpgrade(r *runner.E2ERunner, args []string) { r.Logger.Info(" msgsender: %s", eventIter.Event.MsgSender.Hex()) found = true - require.Equal(r, 0, bytes.Compare(eventIter.Event.Origin, r.DeployerAddress.Bytes()), "origin mismatch") + require.Equal(r, 0, bytes.Compare(eventIter.Event.Origin, r.EVMAddress().Bytes()), "origin mismatch") chainID, err := r.EVMClient.ChainID(r.Ctx) require.NoError(r, err) diff --git a/e2e/e2etests/test_crosschain_swap.go b/e2e/e2etests/test_crosschain_swap.go index f1fe6f54aa..798958a652 100644 --- a/e2e/e2etests/test_crosschain_swap.go +++ b/e2e/e2etests/test_crosschain_swap.go @@ -58,7 +58,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()), ) require.NoError(r, err) @@ -80,7 +80,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 @@ -110,7 +110,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()) require.NoError(r, err) memo = append(r.ZEVMSwapAppAddr.Bytes(), memo...) @@ -138,7 +138,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()) require.NoError(r, err) memo = append(r.ZEVMSwapAppAddr.Bytes(), memo...) diff --git a/e2e/e2etests/test_erc20_deposit.go b/e2e/e2etests/test_erc20_deposit.go index 2f763f34b0..c7f1d4fc5f 100644 --- a/e2e/e2etests/test_erc20_deposit.go +++ b/e2e/e2etests/test_erc20_deposit.go @@ -15,7 +15,7 @@ func TestERC20Deposit(r *runner.E2ERunner, args []string) { amount, ok := big.NewInt(0).SetString(args[0], 10) require.True(r, ok, "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 ad0a962507..5e8d1173ef 100644 --- a/e2e/e2etests/test_erc20_deposit_refund.go +++ b/e2e/e2etests/test_erc20_deposit_refund.go @@ -17,7 +17,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()) require.NoError(r, err) r.Logger.Info("Sending a deposit that should revert without a liquidity pool makes the cctx aborted") @@ -36,13 +36,13 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { r.Logger.CCTX(*cctx, "deposit") r.Logger.Info("Refunding the cctx via admin") - msg := types.NewMsgRefundAbortedCCTX(r.ZetaTxServer.GetAccountAddress(0), cctx.Index, r.DeployerAddress.String()) + msg := types.NewMsgRefundAbortedCCTX(r.ZetaTxServer.GetAccountAddress(0), cctx.Index, r.EVMAddress().String()) _, err = r.ZetaTxServer.BroadcastTx(utils.FungibleAdminName, msg) require.NoError(r, 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()) require.NoError(r, err) expectedBalance := initialBal.Add(initialBal, amount) @@ -65,7 +65,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()) require.NoError(r, err) // send the deposit @@ -87,7 +87,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { utils.RequireTxSuccessful(r, receipt) // 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()) require.NoError(r, err) // the new balance must be higher than the previous one because of the revert refund @@ -118,7 +118,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)) @@ -138,7 +138,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 @@ -163,7 +163,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 a99642f356..87b8309924 100644 --- a/e2e/e2etests/test_erc20_multiple_deposits.go +++ b/e2e/e2etests/test_erc20_multiple_deposits.go @@ -22,7 +22,7 @@ func TestMultipleERC20Deposit(r *runner.E2ERunner, args []string) { require.True(r, ok) require.NotZero(r, numberOfDeposits.Int64()) - initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) require.NoError(r, err) txhash := multipleDeposits(r, depositAmount, numberOfDeposits) @@ -37,7 +37,7 @@ func TestMultipleERC20Deposit(r *runner.E2ERunner, args []string) { require.Len(r, cctxs, 3) // 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()) require.NoError(r, err) diff := big.NewInt(0).Sub(bal, initialBal) @@ -61,7 +61,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) require.NoError(r, err) receipt = utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) diff --git a/e2e/e2etests/test_erc20_multiple_withdraws.go b/e2e/e2etests/test_erc20_multiple_withdraws.go index 14bbb176ca..53a45d1b41 100644 --- a/e2e/e2etests/test_erc20_multiple_withdraws.go +++ b/e2e/e2etests/test_erc20_multiple_withdraws.go @@ -56,7 +56,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()) require.NoError(r, err) r.Logger.Info("balance of deployer on ERC20 ZRC20: %d", bal) @@ -65,7 +65,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 0d7734fbdb..7fd928266d 100644 --- a/e2e/e2etests/test_eth_deposit_call.go +++ b/e2e/e2etests/test_eth_deposit_call.go @@ -5,7 +5,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/stretchr/testify/require" "github.com/zeta-chain/zetacore/e2e/runner" @@ -33,7 +32,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) { gasPrice, err := evmClient.SuggestGasPrice(r.Ctx) require.NoError(r, err) - nonce, err := evmClient.PendingNonceAt(r.Ctx, r.DeployerAddress) + nonce, err := evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) require.NoError(r, err) data := append(exampleAddr.Bytes(), []byte("hello sailors")...) @@ -41,7 +40,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) { chainID, err := evmClient.NetworkID(r.Ctx) require.NoError(r, err) - deployerPrivkey, err := crypto.HexToECDSA(r.DeployerPrivateKey) + deployerPrivkey, err := r.Account.PrivateKey() require.NoError(r, err) signedTx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(chainID), deployerPrivkey) @@ -80,7 +79,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) { gasPrice, err = evmClient.SuggestGasPrice(r.Ctx) require.NoError(r, err) - nonce, err = evmClient.PendingNonceAt(r.Ctx, r.DeployerAddress) + nonce, err = evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) require.NoError(r, err) data = append(reverterAddr.Bytes(), []byte("hello sailors")...) diff --git a/e2e/e2etests/test_eth_deposit_liquidity_cap.go b/e2e/e2etests/test_eth_deposit_liquidity_cap.go index f64b041478..2f03c7a568 100644 --- a/e2e/e2etests/test_eth_deposit_liquidity_cap.go +++ b/e2e/e2etests/test_eth_deposit_liquidity_cap.go @@ -47,7 +47,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()) require.NoError(r, err) signedTx, err = r.SendEther(r.TSSAddress, amountLessThanCap, nil) @@ -61,7 +61,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()) require.NoError(r, err) require.Equal(r, 0, bal.Cmp(expectedBalance)) @@ -79,7 +79,7 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) { 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()) require.NoError(r, err) signedTx, err = r.SendEther(r.TSSAddress, amountMoreThanCap, nil) @@ -91,7 +91,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()) require.NoError(r, err) require.Equal(r, 0, diff --git a/e2e/e2etests/test_eth_deposit_refund.go b/e2e/e2etests/test_eth_deposit_refund.go index 394ffdd8e4..946c457927 100644 --- a/e2e/e2etests/test_eth_deposit_refund.go +++ b/e2e/e2etests/test_eth_deposit_refund.go @@ -5,7 +5,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/stretchr/testify/require" "github.com/zeta-chain/zetacore/e2e/runner" @@ -21,7 +20,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()) require.NoError(r, err) gasLimit := uint64(23000) // in units @@ -33,7 +32,7 @@ func TestEtherDepositAndCallRefund(r *runner.E2ERunner, args []string) { chainID, err := evmClient.NetworkID(r.Ctx) require.NoError(r, err) - deployerPrivkey, err := crypto.HexToECDSA(r.DeployerPrivateKey) + deployerPrivkey, err := r.Account.PrivateKey() require.NoError(r, err) signedTx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(chainID), deployerPrivkey) @@ -66,7 +65,7 @@ func TestEtherDepositAndCallRefund(r *runner.E2ERunner, args []string) { utils.RequireCCTXStatus(r, cctx, types.CctxStatus_Reverted) utils.RequireTxSuccessful(r, receipt) - require.Equal(r, r.DeployerAddress, *tx.To(), "expected tx to %s; got %s", r.DeployerAddress.Hex(), tx.To().Hex()) + require.Equal(r, r.EVMAddress(), *tx.To(), "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 // we check that the value is still greater than 0 diff --git a/e2e/e2etests/test_message_passing_external_chains.go b/e2e/e2etests/test_message_passing_external_chains.go index 317665920b..2c2ed65997 100644 --- a/e2e/e2etests/test_message_passing_external_chains.go +++ b/e2e/e2etests/test_message_passing_external_chains.go @@ -39,7 +39,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 3950a8cdd5..9cc1ee8d8f 100644 --- a/e2e/e2etests/test_message_passing_external_chains_revert_fail.go +++ b/e2e/e2etests/test_message_passing_external_chains_revert_fail.go @@ -39,7 +39,7 @@ func TestMessagePassingRevertFailExternalChains(r *runner.E2ERunner, args []stri 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 848335ddef..07f49a5815 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -9,12 +9,12 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" "github.com/fatih/color" "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" + "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/txserver" "github.com/zeta-chain/zetacore/e2e/utils" @@ -38,7 +38,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"}) @@ -120,7 +120,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) utils.RequiredTxFailed(r, receipt) @@ -199,8 +199,7 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { r.Ctx, "admin-evm2", r.CtxCancel, - r.DeployerAddress, - r.DeployerPrivateKey, + r.Account, r.EVMClient, r.ZEVMClient, r.CctxClient, @@ -217,7 +216,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) if err != nil { return nil, err } @@ -243,7 +242,11 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { } // getEVMClient get evm client from rpc and private key -func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client, *bind.TransactOpts, error) { +func getEVMClient( + ctx context.Context, + rpc string, + account config.Account, +) (*ethclient.Client, *bind.TransactOpts, error) { evmClient, err := ethclient.Dial(rpc) if err != nil { return nil, nil, err @@ -253,7 +256,7 @@ func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client, if err != nil { return nil, nil, err } - deployerPrivkey, err := crypto.HexToECDSA(privKey) + deployerPrivkey, err := account.PrivateKey() if err != nil { return nil, nil, err } diff --git a/e2e/e2etests/test_rate_limiter.go b/e2e/e2etests/test_rate_limiter.go index 446d49a6b2..739d7821dc 100644 --- a/e2e/e2etests/test_rate_limiter.go +++ b/e2e/e2etests/test_rate_limiter.go @@ -221,7 +221,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 3a67ca8f94..2abd036a25 100644 --- a/e2e/e2etests/test_stress_eth_withdraw.go +++ b/e2e/e2etests/test_stress_eth_withdraw.go @@ -40,7 +40,7 @@ func TestStressEtherWithdraw(r *runner.E2ERunner, args []string) { 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) require.NoError(r, err) receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) diff --git a/e2e/e2etests/test_update_bytecode_zrc20.go b/e2e/e2etests/test_update_bytecode_zrc20.go index ba914655d1..8205b88d9c 100644 --- a/e2e/e2etests/test_update_bytecode_zrc20.go +++ b/e2e/e2etests/test_update_bytecode_zrc20.go @@ -60,10 +60,10 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) { totalSupply, err := r.ETHZRC20.TotalSupply(&bind.CallOpts{}) require.NoError(r, err) - balance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + balance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) require.NoError(r, err) - approval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.DeployerAddress, approved) + approval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.EVMAddress(), approved) require.NoError(r, err) r.Logger.Info("Updating the bytecode of the ZRC20") @@ -95,11 +95,11 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) { require.NoError(r, err) require.Equal(r, 0, totalSupply.Cmp(newTotalSupply)) - newBalance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + newBalance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) require.NoError(r, err) require.Equal(r, 0, balance.Cmp(newBalance)) - newApproval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.DeployerAddress, approved) + newApproval, err := r.ETHZRC20.Allowance(&bind.CallOpts{}, r.EVMAddress(), approved) require.NoError(r, err) require.Equal(r, 0, approval.Cmp(newApproval)) diff --git a/e2e/e2etests/test_zeta_deposit.go b/e2e/e2etests/test_zeta_deposit.go index 056ee5709f..eb8021876d 100644 --- a/e2e/e2etests/test_zeta_deposit.go +++ b/e2e/e2etests/test_zeta_deposit.go @@ -15,7 +15,7 @@ func TestZetaDeposit(r *runner.E2ERunner, args []string) { amount, ok := big.NewInt(0).SetString(args[0], 10) require.True(r, ok, "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 ae34058c94..3685dccfb3 100644 --- a/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go +++ b/e2e/e2etests/test_zeta_withdraw_bitcoin_revert.go @@ -41,7 +41,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 661d2fc40f..14febbe800 100644 --- a/e2e/e2etests/test_zrc20_swap.go +++ b/e2e/e2etests/test_zrc20_swap.go @@ -56,7 +56,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()), ) require.NoError(r, err) @@ -64,7 +64,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()) require.NoError(r, err) ethOutAmout := big.NewInt(1) @@ -73,7 +73,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()), ) require.NoError(r, err) @@ -81,7 +81,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()) require.NoError(r, err) ethDiff := big.NewInt(0).Sub(balETHAfter, balETHBefore) diff --git a/e2e/runner/balances.go b/e2e/runner/balances.go index 8a0c37782a..d1e19d4c61 100644 --- a/e2e/runner/balances.go +++ b/e2e/runner/balances.go @@ -33,37 +33,37 @@ type AccountBalancesDiff struct { // GetAccountBalances returns the account balances of the accounts used in the E2E test func (r *E2ERunner) GetAccountBalances(skipBTC bool) (AccountBalances, error) { // zevm - zetaZeta, err := r.ZEVMClient.BalanceAt(r.Ctx, r.DeployerAddress, nil) + zetaZeta, err := r.ZEVMClient.BalanceAt(r.Ctx, r.EVMAddress(), nil) if err != nil { return AccountBalances{}, err } - zetaWZeta, err := r.WZeta.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + zetaWZeta, err := r.WZeta.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { return AccountBalances{}, err } - zetaEth, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + zetaEth, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { return AccountBalances{}, err } - zetaErc20, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + zetaErc20, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { return AccountBalances{}, err } - zetaBtc, err := r.BTCZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + zetaBtc, err := r.BTCZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { return AccountBalances{}, err } // evm - evmEth, err := r.EVMClient.BalanceAt(r.Ctx, r.DeployerAddress, nil) + evmEth, err := r.EVMClient.BalanceAt(r.Ctx, r.EVMAddress(), nil) if err != nil { return AccountBalances{}, err } - evmZeta, err := r.ZetaEth.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + evmZeta, err := r.ZetaEth.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { return AccountBalances{}, err } - evmErc20, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + evmErc20, err := r.ERC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) if err != nil { return AccountBalances{}, err } @@ -129,7 +129,7 @@ func (r *E2ERunner) GetBitcoinBalanceByAddress(address btcutil.Address) (btcutil // 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 (r *E2ERunner) PrintAccountBalances(balances AccountBalances) { - r.Logger.Print(" ---💰 Account info %s ---", r.DeployerAddress.Hex()) + r.Logger.Print(" ---💰 Account info %s ---", r.EVMAddress().Hex()) // zevm r.Logger.Print("ZetaChain:") diff --git a/e2e/runner/bitcoin.go b/e2e/runner/bitcoin.go index c096bfc748..3165d745ca 100644 --- a/e2e/runner/bitcoin.go +++ b/e2e/runner/bitcoin.go @@ -141,7 +141,7 @@ func (r *E2ERunner) DepositBTC(testHeader bool) { ) utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) - balance, err := r.BTCZRC20.BalanceOf(&bind.CallOpts{}, r.DeployerAddress) + balance, err := r.BTCZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) require.NoError(r, err) require.Equal(r, 1, balance.Sign(), "balance should be positive") @@ -156,7 +156,7 @@ func (r *E2ERunner) SendToTSSFromDeployerToDeposit(amount float64, inputUTXOs [] *chainhash.Hash, error, ) { - return r.SendToTSSFromDeployerWithMemo(amount, inputUTXOs, r.DeployerAddress.Bytes()) + return r.SendToTSSFromDeployerWithMemo(amount, inputUTXOs, r.EVMAddress().Bytes()) } func (r *E2ERunner) SendToTSSFromDeployerWithMemo( diff --git a/e2e/runner/evm.go b/e2e/runner/evm.go index 523e01e207..88c1e100bf 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/stretchr/testify/require" @@ -66,7 +65,7 @@ func (r *E2ERunner) SendERC20OnEvm(address ethcommon.Address, amountERC20 int64) func (r *E2ERunner) DepositERC20() ethcommon.Hash { r.Logger.Print("⏳ depositing ERC20 into ZEVM") - return r.DepositERC20WithAmountAndMessage(r.DeployerAddress, big.NewInt(1e18), []byte{}) + return r.DepositERC20WithAmountAndMessage(r.EVMAddress(), big.NewInt(1e18), []byte{}) } func (r *E2ERunner) DepositERC20WithAmountAndMessage(to ethcommon.Address, amount *big.Int, msg []byte) ethcommon.Hash { @@ -143,7 +142,7 @@ func (r *E2ERunner) DepositEtherWithAmount(testHeader bool, amount *big.Int) eth func (r *E2ERunner) SendEther(_ ethcommon.Address, value *big.Int, data []byte) (*ethtypes.Transaction, error) { evmClient := r.EVMClient - nonce, err := evmClient.PendingNonceAt(r.Ctx, r.DeployerAddress) + nonce, err := evmClient.PendingNonceAt(r.Ctx, r.EVMAddress()) if err != nil { return nil, err } @@ -160,7 +159,7 @@ func (r *E2ERunner) SendEther(_ ethcommon.Address, value *big.Int, data []byte) return nil, err } - deployerPrivkey, err := crypto.HexToECDSA(r.DeployerPrivateKey) + deployerPrivkey, err := r.Account.PrivateKey() if err != nil { return nil, err } diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index e27de63247..a9c5c11d00 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -25,6 +25,7 @@ import ( "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol" uniswapv2router "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol" + "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/contracts/contextapp" "github.com/zeta-chain/zetacore/e2e/contracts/erc20" "github.com/zeta-chain/zetacore/e2e/contracts/zevmswap" @@ -49,8 +50,7 @@ func WithZetaTxServer(txServer *txserver.ZetaTxServer) E2ERunnerOption { // It also provides some helper functions type E2ERunner struct { // accounts - DeployerAddress ethcommon.Address - DeployerPrivateKey string + Account config.Account TSSAddress ethcommon.Address BTCTSSAddress btcutil.Address BTCDeployerAddress *btcutil.AddressWitnessPubKeyHash @@ -128,8 +128,7 @@ func NewE2ERunner( ctx context.Context, name string, ctxCancel context.CancelFunc, - deployerAddress ethcommon.Address, - deployerPrivateKey string, + account config.Account, evmClient *ethclient.Client, zevmClient *ethclient.Client, cctxClient crosschaintypes.QueryClient, @@ -148,8 +147,7 @@ func NewE2ERunner( Name: name, CtxCancel: ctxCancel, - DeployerAddress: deployerAddress, - DeployerPrivateKey: deployerPrivateKey, + Account: account, ZEVMClient: zevmClient, EVMClient: evmClient, @@ -314,3 +312,8 @@ func (r *E2ERunner) FailNow() { func (r *E2ERunner) requireTxSuccessful(receipt *ethtypes.Receipt, msgAndArgs ...any) { utils.RequireTxSuccessful(r, receipt, msgAndArgs...) } + +// EVMAddress is shorthand to get the EVM address of the account +func (r *E2ERunner) EVMAddress() ethcommon.Address { + return r.Account.EVMAddress() +} diff --git a/e2e/runner/setup_bitcoin.go b/e2e/runner/setup_bitcoin.go index 92a7eac428..15b6d4a11d 100644 --- a/e2e/runner/setup_bitcoin.go +++ b/e2e/runner/setup_bitcoin.go @@ -40,7 +40,7 @@ func (r *E2ERunner) SetupBitcoinAccount(initNetwork bool) { // GetBtcAddress returns the BTC address of the deployer from its EVM private key func (r *E2ERunner) GetBtcAddress() (string, string, error) { - skBytes, err := hex.DecodeString(r.DeployerPrivateKey) + skBytes, err := hex.DecodeString(r.Account.RawPrivateKey.String()) if err != nil { return "", "", err } @@ -65,7 +65,7 @@ func (r *E2ERunner) GetBtcAddress() (string, string, error) { // SetBtcAddress imports the deployer's private key into the Bitcoin node func (r *E2ERunner) SetBtcAddress(name string, rescan bool) { - skBytes, err := hex.DecodeString(r.DeployerPrivateKey) + skBytes, err := hex.DecodeString(r.Account.RawPrivateKey.String()) require.NoError(r, err) sk, _ := btcec.PrivKeyFromBytes(btcec.S256(), skBytes) diff --git a/e2e/runner/setup_evm.go b/e2e/runner/setup_evm.go index ff5b2e0ddc..7b61d43163 100644 --- a/e2e/runner/setup_evm.go +++ b/e2e/runner/setup_evm.go @@ -28,12 +28,12 @@ func (r *E2ERunner) SetEVMContractsFromConfig() { require.NoError(r, err) // Set ZetaEthAddr - r.ZetaEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ZetaEthAddress) + 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) + r.ConnectorEthAddr = ethcommon.HexToAddress(conf.Contracts.EVM.ConnectorEthAddr.String()) r.ConnectorEth, err = zetaconnectoreth.NewZetaConnectorEth(r.ConnectorEthAddr, r.EVMClient) require.NoError(r, err) } @@ -66,14 +66,14 @@ func (r *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { zetaEthAddr, txZetaEth, ZetaEth, err := zetaeth.DeployZetaEth( r.EVMAuth, r.EVMClient, - r.DeployerAddress, + r.EVMAddress(), big.NewInt(21_000_000_000), ) require.NoError(r, err) r.ZetaEth = ZetaEth r.ZetaEthAddr = zetaEthAddr - conf.Contracts.EVM.ZetaEthAddress = zetaEthAddr.String() + conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(zetaEthAddr.String()) r.Logger.Info("ZetaEth contract address: %s, tx hash: %s", zetaEthAddr.Hex(), zetaEthAddr.Hash().Hex()) r.Logger.Info("Deploying ZetaConnectorEth contract") @@ -82,14 +82,14 @@ func (r *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { r.EVMClient, zetaEthAddr, r.TSSAddress, - r.DeployerAddress, - r.DeployerAddress, + r.EVMAddress(), + r.EVMAddress(), ) require.NoError(r, err) r.ConnectorEth = ConnectorEth r.ConnectorEthAddr = connectorEthAddr - conf.Contracts.EVM.ConnectorEthAddr = connectorEthAddr.String() + conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(connectorEthAddr.String()) r.Logger.Info( "ZetaConnectorEth contract address: %s, tx hash: %s", @@ -101,8 +101,8 @@ func (r *E2ERunner) SetupEVM(contractsDeployed bool, whitelistERC20 bool) { erc20CustodyAddr, txCustody, ERC20Custody, err := erc20custody.DeployERC20Custody( r.EVMAuth, r.EVMClient, - r.DeployerAddress, - r.DeployerAddress, + r.EVMAddress(), + r.EVMAddress(), big.NewInt(0), big.NewInt(1e18), ethcommon.HexToAddress("0x"), diff --git a/e2e/runner/zeta.go b/e2e/runner/zeta.go index 726f3f5cb6..732104afe1 100644 --- a/e2e/runner/zeta.go +++ b/e2e/runner/zeta.go @@ -66,7 +66,7 @@ func (r *E2ERunner) DepositZeta() ethcommon.Hash { amount := big.NewInt(1e18) amount = amount.Mul(amount, big.NewInt(100)) // 100 Zeta - return r.DepositZetaWithAmount(r.DeployerAddress, amount) + return r.DepositZetaWithAmount(r.EVMAddress(), amount) } // DepositZetaWithAmount deposits ZETA on ZetaChain from the ZETA smart contract on EVM with the specified amount @@ -149,7 +149,7 @@ func (r *E2ERunner) WithdrawZeta(amount *big.Int, waitReceipt bool) *ethtypes.Tr tx, err := r.ConnectorZEVM.Send(r.ZEVMAuth, connectorzevm.ZetaInterfacesSendInput{ DestinationChainId: chainID, - DestinationAddress: r.DeployerAddress.Bytes(), + DestinationAddress: r.EVMAddress().Bytes(), DestinationGasLimit: big.NewInt(400_000), Message: nil, ZetaValueAndGas: amount, @@ -182,7 +182,7 @@ func (r *E2ERunner) WithdrawZeta(amount *big.Int, waitReceipt bool) *ethtypes.Tr // 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.DeployerAddress.Bytes(), amount) + tx, err := r.ETHZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount) require.NoError(r, err) r.Logger.EVMTransaction(*tx, "withdraw") @@ -198,7 +198,7 @@ func (r *E2ERunner) WithdrawEther(amount *big.Int) *ethtypes.Transaction { // 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.DeployerAddress.Bytes(), amount) + tx, err := r.ERC20ZRC20.Withdraw(r.ZEVMAuth, r.EVMAddress().Bytes(), amount) require.NoError(r, err) r.Logger.EVMTransaction(*tx, "withdraw")