diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index a325621621..18c40190e1 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -2,15 +2,12 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" - "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -56,23 +53,15 @@ 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, - utils.FungibleAdminName, // placeholder value, not used - local.FungibleAdminMnemonic, // placeholder value, not used + config.Deployer, + utils.FungibleAdminName, // placeholder value, not used + conf.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index b2a4525637..332bd67422 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -2,15 +2,12 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" - "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -56,23 +53,15 @@ 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, - utils.FungibleAdminName, // placeholder value, not used - local.FungibleAdminMnemonic, // placeholder value, not used + config.UserBitcoin, + utils.FungibleAdminName, // placeholder value, not used + conf.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/config/clients.go b/cmd/zetae2e/config/clients.go index ae56eaa9dd..4e23a73a82 100644 --- a/cmd/zetae2e/config/clients.go +++ b/cmd/zetae2e/config/clients.go @@ -2,13 +2,13 @@ package config import ( "context" + "crypto/ecdsa" "fmt" "github.com/btcsuite/btcd/rpcclient" 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 +20,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, accountName config.AccountName) ( *rpcclient.Client, *ethclient.Client, *bind.TransactOpts, @@ -34,6 +34,10 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st *bind.TransactOpts, error, ) { + evmPrivKey, err := conf.Accounts[accountName].PrivateKey() + if err != nil { + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm private key for %s: %w", accountName, err) + } btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin) if err != nil { return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err) @@ -91,7 +95,7 @@ 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, privateKey *ecdsa.PrivateKey) (*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 +105,7 @@ 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) - 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(privateKey, 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 b18ca9922b..579e40eea9 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" "github.com/zeta-chain/zetacore/e2e/txserver" @@ -17,8 +15,7 @@ func RunnerFromConfig( name string, ctxCancel context.CancelFunc, conf config.Config, - evmUserAddr ethcommon.Address, - evmUserPrivKey string, + account config.AccountName, zetaUserName string, zetaUserMnemonic string, logger *runner.Logger, @@ -35,7 +32,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) } @@ -55,8 +52,8 @@ func RunnerFromConfig( ctx, name, ctxCancel, - evmUserAddr, - evmUserPrivKey, + conf.Accounts[account].Address(), + conf.Accounts[account].RawPrivateKey, zetaUserMnemonic, evmClient, zevmClient, diff --git a/cmd/zetae2e/config/config_test.go b/cmd/zetae2e/config/config_test.go new file mode 100644 index 0000000000..32ada11e4e --- /dev/null +++ b/cmd/zetae2e/config/config_test.go @@ -0,0 +1,15 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/e2e/config" +) + +// test that the local config can be read, parsed, and validated +func TestReadLocalConfig(t *testing.T) { + config, err := config.ReadConfig("local.yml") + require.NoError(t, err) + require.Greater(t, len(config.Accounts), 0) +} diff --git a/cmd/zetae2e/config/local.yml b/cmd/zetae2e/config/local.yml index ae2638ace7..de78236646 100644 --- a/cmd/zetae2e/config/local.yml +++ b/cmd/zetae2e/config/local.yml @@ -1,7 +1,29 @@ zeta_chain_id: "athens_7001-1" accounts: - evm_address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC" - evm_priv_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263" + deployer: + address: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC" + private_key: "d87baf7bf6dc560a252596678c12e41f7d1682837f05b29d411bc3f78ae2c263" + user_erc20: + address: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6" + private_key: "fda3be1b1517bdf48615bdadacc1e6463d2865868dc8077d2cdcfa4709a16894" + user_zeta_test: + address: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd" + private_key: "729a6cdc5c925242e7df92fdeeb94dadbf2d0b9950d4db8f034ab27a3b114ba7" + user_zevm_mp_test: + address: "0x8Ae229198eCE3c889C07DB648Ec7C30E6051592c" + private_key: "105460aebf71b10bfdb710ef5aa6d2932ee6ff6fc317ac9c24e0979903b10a5d" + user_bitcoin: + address: "0x283d810090EdF4043E75247eAeBcE848806237fD" + private_key: "7bb523963ee2c78570fb6113d886a4184d42565e8847f1cb639f5f5e2ef5b37a" + user_ether: + address: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A" + private_key: "098e74a1c2261fa3c1b8cfca8ef2b4ff96c73ce36710d208d1f6535aef42545d" + user_misc: + address: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf" + private_key: "853c0945b8035a501b1161df65a17a0a20fc848bda8975a8b4e9222cc6f84cd4" + user_admin: + address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + private_key: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" rpcs: zevm: "http://0.0.0.0:9545" evm: "http://0.0.0.0:8545" @@ -28,4 +50,5 @@ contracts: zeta_eth: "0x733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" connector_eth: "0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca" custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a" - erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564" \ No newline at end of file + erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564" +fungible_admin_mnemonic: "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" \ No newline at end of file diff --git a/cmd/zetae2e/local/accounts.go b/cmd/zetae2e/local/accounts.go deleted file mode 100644 index daf10eabc2..0000000000 --- a/cmd/zetae2e/local/accounts.go +++ /dev/null @@ -1,42 +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 - - FungibleAdminMnemonic = "snow grace federal cupboard arrive fancy gym lady uniform rotate exercise either leave alien grass" // #nosec G101 - used for testing -) diff --git a/cmd/zetae2e/local/admin.go b/cmd/zetae2e/local/admin.go index 6b360ecb7d..a244f5b2e2 100644 --- a/cmd/zetae2e/local/admin.go +++ b/cmd/zetae2e/local/admin.go @@ -36,8 +36,7 @@ func adminTestRoutine( "admin", conf, deployerRunner, - UserAdminAddress, - UserAdminPrivateKey, + config.UserAdmin, runner.NewLogger(verbose, color.FgHiGreen, "admin"), ) if err != nil { @@ -47,10 +46,12 @@ func adminTestRoutine( adminRunner.Logger.Print("🏃 starting admin tests") startTime := time.Now() + userAdminAddress := conf.Accounts[config.UserAdmin].Address() + // 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(userAdminAddress, 20_500_000_000) + txERC20Send := deployerRunner.SendERC20OnEvm(userAdminAddress, 1000) adminRunner.WaitForTxReceiptOnEvm(txZetaSend) adminRunner.WaitForTxReceiptOnEvm(txERC20Send) diff --git a/cmd/zetae2e/local/bitcoin.go b/cmd/zetae2e/local/bitcoin.go index d0f4d8bb12..2fd430b327 100644 --- a/cmd/zetae2e/local/bitcoin.go +++ b/cmd/zetae2e/local/bitcoin.go @@ -39,8 +39,7 @@ func bitcoinTestRoutine( "bitcoin", conf, deployerRunner, - UserBitcoinAddress, - UserBitcoinPrivateKey, + config.UserBitcoin, runner.NewLogger(verbose, color.FgYellow, "bitcoin"), ) if err != nil { @@ -50,8 +49,10 @@ func bitcoinTestRoutine( bitcoinRunner.Logger.Print("🏃 starting Bitcoin tests") startTime := time.Now() + userBitcoinAddress := conf.Accounts[config.UserBitcoin].Address() + // funding the account - txERC20Send := deployerRunner.SendERC20OnEvm(UserBitcoinAddress, 1000) + txERC20Send := deployerRunner.SendERC20OnEvm(userBitcoinAddress, 1000) bitcoinRunner.WaitForTxReceiptOnEvm(txERC20Send) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/local/erc20.go b/cmd/zetae2e/local/erc20.go index 5d0e7a5ac9..fe6b058f65 100644 --- a/cmd/zetae2e/local/erc20.go +++ b/cmd/zetae2e/local/erc20.go @@ -37,8 +37,7 @@ func erc20TestRoutine( "erc20", conf, deployerRunner, - UserERC20Address, - UserERC20PrivateKey, + config.UserERC20, runner.NewLogger(verbose, color.FgGreen, "erc20"), ) if err != nil { @@ -48,8 +47,10 @@ func erc20TestRoutine( erc20Runner.Logger.Print("🏃 starting erc20 tests") startTime := time.Now() + userERC20Address := conf.Accounts[config.UserERC20].Address() + // funding the account - txERC20Send := deployerRunner.SendERC20OnEvm(UserERC20Address, 10) + txERC20Send := deployerRunner.SendERC20OnEvm(userERC20Address, 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 efb37f1fa1..ecee9e903b 100644 --- a/cmd/zetae2e/local/ethereum.go +++ b/cmd/zetae2e/local/ethereum.go @@ -38,8 +38,7 @@ func ethereumTestRoutine( "ether", conf, deployerRunner, - UserEtherAddress, - UserEtherPrivateKey, + config.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 c1ab0f4431..15489bef3b 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -172,10 +172,9 @@ func localE2ETest(cmd *cobra.Command, _ []string) { "deployer", cancel, conf, - DeployerAddress, - DeployerPrivateKey, + config.Deployer, utils.FungibleAdminName, - FungibleAdminMnemonic, + conf.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/local/misc.go b/cmd/zetae2e/local/misc.go index 081905b5ee..2cf0939681 100644 --- a/cmd/zetae2e/local/misc.go +++ b/cmd/zetae2e/local/misc.go @@ -37,8 +37,7 @@ func miscTestRoutine( "misc", conf, deployerRunner, - UserMiscAddress, - UserMiscPrivateKey, + config.UserMisc, runner.NewLogger(verbose, color.FgCyan, "misc"), ) if err != nil { @@ -48,8 +47,10 @@ func miscTestRoutine( miscRunner.Logger.Print("🏃 starting miscellaneous tests") startTime := time.Now() + userMiscAddress := conf.Accounts[config.UserMisc].Address() + // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(UserMiscAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(userMiscAddress, 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 4b83d66307..cafde8164a 100644 --- a/cmd/zetae2e/local/performance.go +++ b/cmd/zetae2e/local/performance.go @@ -40,8 +40,7 @@ func ethereumDepositPerformanceRoutine( "ether", conf, deployerRunner, - UserERC20Address, - UserERC20PrivateKey, + config.UserERC20, runner.NewLogger(verbose, color.FgHiMagenta, "perf_eth_deposit"), ) if err != nil { @@ -94,8 +93,7 @@ func ethereumWithdrawPerformanceRoutine( "ether", conf, deployerRunner, - UserEtherAddress, - UserEtherPrivateKey, + config.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 6896c4c865..021cd1279f 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" @@ -15,8 +13,7 @@ func initTestRunner( name string, conf config.Config, deployerRunner *runner.E2ERunner, - userAddress ethcommon.Address, - userPrivKey string, + accountName config.AccountName, logger *runner.Logger, ) (*runner.E2ERunner, error) { // initialize runner for test @@ -25,10 +22,9 @@ func initTestRunner( name, deployerRunner.CtxCancel, conf, - userAddress, - userPrivKey, + accountName, utils.FungibleAdminName, - FungibleAdminMnemonic, + conf.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/local/zeta.go b/cmd/zetae2e/local/zeta.go index 1f95c5f6d6..054903ada6 100644 --- a/cmd/zetae2e/local/zeta.go +++ b/cmd/zetae2e/local/zeta.go @@ -37,8 +37,7 @@ func zetaTestRoutine( "zeta", conf, deployerRunner, - UserZetaTestAddress, - UserZetaTestPrivateKey, + config.UserZetaTest, runner.NewLogger(verbose, color.FgBlue, "zeta"), ) if err != nil { @@ -48,8 +47,10 @@ func zetaTestRoutine( zetaRunner.Logger.Print("🏃 starting Zeta tests") startTime := time.Now() + userZetaTestAddress := conf.Accounts[config.UserZetaTest].Address() + // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(UserZetaTestAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(userZetaTestAddress, 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 969dcfda64..0a6c3ed565 100644 --- a/cmd/zetae2e/local/zevm_mp.go +++ b/cmd/zetae2e/local/zevm_mp.go @@ -37,8 +37,7 @@ func zevmMPTestRoutine( "zevm_mp", conf, deployerRunner, - UserZEVMMPTestAddress, - UserZEVMMPTestPrivateKey, + config.UserZEVMMPTest, runner.NewLogger(verbose, color.FgHiRed, "zevm_mp"), ) if err != nil { @@ -48,8 +47,10 @@ func zevmMPTestRoutine( zevmMPRunner.Logger.Print("🏃 starting ZEVM Message Passing tests") startTime := time.Now() + userZEVMMPTestAddress := conf.Accounts[config.UserZEVMMPTest].Address() + // funding the account - txZetaSend := deployerRunner.SendZetaOnEvm(UserZEVMMPTestAddress, 1000) + txZetaSend := deployerRunner.SendZetaOnEvm(userZEVMMPTestAddress, 1000) zevmMPRunner.WaitForTxReceiptOnEvm(txZetaSend) // depositing the necessary tokens on ZetaChain diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index e97e9e576b..f92a95cbf9 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -6,13 +6,11 @@ import ( "strings" "time" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" - "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/e2etests" "github.com/zeta-chain/zetacore/e2e/runner" @@ -78,23 +76,15 @@ func runE2ETest(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 testRunner, err := zetae2econfig.RunnerFromConfig( ctx, "e2e", cancel, conf, - ethcommon.HexToAddress(evmAddr), - conf.Accounts.EVMPrivKey, - utils.FungibleAdminName, // placeholder value, not used - local.FungibleAdminMnemonic, // placeholder value, not used + config.Deployer, + utils.FungibleAdminName, // placeholder value, not used + conf.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index 407a80e429..688cc864e7 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -2,15 +2,12 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" - "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -44,22 +41,15 @@ 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, - utils.FungibleAdminName, // placeholder value, not used - local.FungibleAdminMnemonic, // placeholder value, not used + config.Deployer, + utils.FungibleAdminName, // placeholder value, not used + conf.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index 6c1ed0092c..1412960a12 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -2,15 +2,12 @@ package main import ( "context" - "errors" - ethcommon "github.com/ethereum/go-ethereum/common" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" - "github.com/zeta-chain/zetacore/cmd/zetae2e/local" "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -44,23 +41,15 @@ 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, - utils.FungibleAdminName, // placeholder value, not used - local.FungibleAdminMnemonic, // placeholder value, not used + config.Deployer, + utils.FungibleAdminName, // placeholder value, not used + conf.FungibleAdminMnemonic, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index 20e7ff494f..edc09e560c 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -11,7 +11,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" @@ -21,6 +20,7 @@ import ( "github.com/zeta-chain/zetacore/app" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" "github.com/zeta-chain/zetacore/cmd/zetae2e/local" + "github.com/zeta-chain/zetacore/e2e/config" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -53,10 +53,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]") @@ -65,8 +61,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 } @@ -98,11 +92,13 @@ func StressTest(cmd *cobra.Command, _ []string) { panic(err) } - bal, err := evmClient.BalanceAt(context.TODO(), local.DeployerAddress, nil) + deployerAddress := conf.Accounts[config.Deployer].Address() + + bal, err := evmClient.BalanceAt(context.TODO(), deployerAddress, nil) if err != nil { panic(err) } - fmt.Printf("Deployer address: %s, balance: %d Wei\n", local.DeployerAddress.Hex(), bal) + fmt.Printf("Deployer address: %s, balance: %d Wei\n", deployerAddress.Hex(), bal) grpcConn, err := grpc.Dial(conf.RPCs.ZetaCoreGRPC, grpc.WithInsecure()) if err != nil { @@ -147,10 +143,9 @@ func StressTest(cmd *cobra.Command, _ []string) { "deployer", cancel, conf, - local.DeployerAddress, - local.DeployerPrivateKey, + config.Deployer, utils.FungibleAdminName, - local.FungibleAdminMnemonic, + conf.FungibleAdminMnemonic, logger, ) if err != nil { @@ -188,7 +183,7 @@ func StressTest(cmd *cobra.Command, _ []string) { } // Check zrc20 balance of Deployer address - ethZRC20Balance, err := e2eTest.ETHZRC20.BalanceOf(nil, local.DeployerAddress) + ethZRC20Balance, err := e2eTest.ETHZRC20.BalanceOf(nil, deployerAddress) if err != nil { panic(err) } @@ -211,7 +206,7 @@ func StressTest(cmd *cobra.Command, _ []string) { } // #nosec G701 e2eTest - always in range - nonce, err := e2eTest.ZEVMClient.NonceAt(context.Background(), local.DeployerAddress, big.NewInt(int64(blockNum))) + nonce, err := e2eTest.ZEVMClient.NonceAt(context.Background(), deployerAddress, big.NewInt(int64(blockNum))) if err != nil { panic(err) } @@ -332,7 +327,7 @@ func WithdrawETHZRC20(runner *runner.E2ERunner) { ethZRC20 := runner.ETHZRC20 runner.ZEVMAuth.Nonce = zevmNonce - _, err := ethZRC20.Withdraw(runner.ZEVMAuth, local.DeployerAddress.Bytes(), big.NewInt(100)) + _, err := ethZRC20.Withdraw(runner.ZEVMAuth, runner.DeployerAddress.Bytes(), big.NewInt(100)) if err != nil { panic(err) } diff --git a/e2e/config/config.go b/e2e/config/config.go index 450b02c5a3..13d7088b9b 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -1,26 +1,30 @@ package config import ( + "crypto/ecdsa" "errors" "fmt" "os" "github.com/btcsuite/btcd/chaincfg" + ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "gopkg.in/yaml.v2" ) // 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"` + Accounts map[AccountName]Account `yaml:"accounts"` + RPCs RPCs `yaml:"rpcs"` + Contracts Contracts `yaml:"contracts"` + ZetaChainID string `yaml:"zeta_chain_id"` + FungibleAdminMnemonic string `yaml:"fungible_admin_mnemonic"` } -// Accounts contains the configuration for the accounts -type Accounts struct { - EVMAddress string `yaml:"evm_address"` - EVMPrivKey string `yaml:"evm_priv_key"` +// Account contains configuration for an account +type Account struct { + RawAddress string `yaml:"address"` + RawPrivateKey string `yaml:"private_key"` } // RPCs contains the configuration for the RPC endpoints @@ -144,9 +148,34 @@ func (c Config) Validate() error { c.RPCs.Bitcoin.Params != Regnet { return errors.New("invalid bitcoin params") } + // validate that the address and the private key specified in the + // config actually match + for accountType, account := range c.Accounts { + privateKey, err := account.PrivateKey() + if err != nil { + return fmt.Errorf("invalid private key for %s: %w", accountType, err) + } + privateKeyAddress := crypto.PubkeyToAddress(privateKey.PublicKey).Hex() + if account.RawAddress != privateKeyAddress { + return fmt.Errorf( + "%s: address derived from private key (%s) does not match configured address (%s)", + accountType, + privateKeyAddress, + account.RawAddress, + ) + } + } return nil } +func (a Account) Address() ethcommon.Address { + return ethcommon.HexToAddress(a.RawAddress) +} + +func (a Account) PrivateKey() (*ecdsa.PrivateKey, error) { + return crypto.HexToECDSA(a.RawPrivateKey) +} + // BitcoinNetworkType is a custom type to represent allowed network types type BitcoinNetworkType string @@ -170,3 +199,16 @@ func (bnt BitcoinNetworkType) GetParams() (chaincfg.Params, error) { return chaincfg.Params{}, fmt.Errorf("invalid bitcoin params %s", bnt) } } + +type AccountName string + +const ( + Deployer AccountName = "deployer" + UserERC20 AccountName = "user_erc_20" + UserZetaTest AccountName = "user_zeta_test" + UserZEVMMPTest AccountName = "user_zevm_mp" + UserBitcoin AccountName = "user_bitcoin" + UserEther AccountName = "user_ether" + UserMisc AccountName = "user_misc" + UserAdmin AccountName = "user_admin" +)