From 9dddbddfe9ced85da0178f7a41816c07fdfd6106 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 5 Jun 2024 14:00:14 -0700 Subject: [PATCH] import private key rather than mnemonic --- cmd/zetae2e/balances.go | 3 +-- cmd/zetae2e/bitcoin_address.go | 3 +-- cmd/zetae2e/config/config.go | 4 +--- cmd/zetae2e/local/local.go | 1 - cmd/zetae2e/local/test_runner.go | 1 - cmd/zetae2e/run.go | 3 +-- cmd/zetae2e/setup_bitcoin.go | 3 +-- cmd/zetae2e/show_tss.go | 3 +-- cmd/zetae2e/stress.go | 1 - e2e/e2etests/test_migrate_chain_support.go | 1 - e2e/runner/runner.go | 8 +++----- e2e/txserver/zeta_tx_server.go | 21 +++++---------------- 12 files changed, 14 insertions(+), 38 deletions(-) diff --git a/cmd/zetae2e/balances.go b/cmd/zetae2e/balances.go index cf52b65f40..9d619ec4b3 100644 --- a/cmd/zetae2e/balances.go +++ b/cmd/zetae2e/balances.go @@ -60,8 +60,7 @@ func runBalances(cmd *cobra.Command, args []string) error { cancel, conf, conf.Accounts.Deployer, - utils.FungibleAdminName, // placeholder value, not used - conf.FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/bitcoin_address.go b/cmd/zetae2e/bitcoin_address.go index 1832bc76b9..adccaff988 100644 --- a/cmd/zetae2e/bitcoin_address.go +++ b/cmd/zetae2e/bitcoin_address.go @@ -60,8 +60,7 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error { cancel, conf, conf.AdditionalAccounts.UserBitcoin, - utils.FungibleAdminName, // placeholder value, not used - conf.FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 71724f2b6f..b83e1c9f7a 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -17,7 +17,6 @@ func RunnerFromConfig( conf config.Config, account config.Account, zetaUserName string, - zetaUserMnemonic string, logger *runner.Logger, ) (*runner.E2ERunner, error) { // initialize clients @@ -40,7 +39,7 @@ func RunnerFromConfig( zetaTxServer, err := txserver.NewZetaTxServer( conf.RPCs.ZetaCoreRPC, []string{zetaUserName}, - []string{zetaUserMnemonic}, + []string{account.RawPrivateKey.String()}, conf.ZetaChainID, ) if err != nil { @@ -53,7 +52,6 @@ func RunnerFromConfig( name, ctxCancel, account, - zetaUserMnemonic, evmClient, zevmClient, cctxClient, diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index dbdb8ac062..d031c97266 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -174,7 +174,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) { conf, conf.Accounts.Deployer, utils.FungibleAdminName, - conf.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/local/test_runner.go b/cmd/zetae2e/local/test_runner.go index eaf30e6416..584661cb60 100644 --- a/cmd/zetae2e/local/test_runner.go +++ b/cmd/zetae2e/local/test_runner.go @@ -24,7 +24,6 @@ func initTestRunner( conf, account, utils.FungibleAdminName, - conf.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/cmd/zetae2e/run.go b/cmd/zetae2e/run.go index 566488853b..2c936e99bd 100644 --- a/cmd/zetae2e/run.go +++ b/cmd/zetae2e/run.go @@ -83,8 +83,7 @@ func runE2ETest(cmd *cobra.Command, args []string) error { cancel, conf, conf.Accounts.Deployer, - utils.FungibleAdminName, // placeholder value, not used - conf.FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/setup_bitcoin.go b/cmd/zetae2e/setup_bitcoin.go index f4c470309a..a52dab082a 100644 --- a/cmd/zetae2e/setup_bitcoin.go +++ b/cmd/zetae2e/setup_bitcoin.go @@ -48,8 +48,7 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error { cancel, conf, conf.Accounts.Deployer, - utils.FungibleAdminName, // placeholder value, not used - conf.FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/show_tss.go b/cmd/zetae2e/show_tss.go index e52454141b..913a1f4eb9 100644 --- a/cmd/zetae2e/show_tss.go +++ b/cmd/zetae2e/show_tss.go @@ -48,8 +48,7 @@ func runShowTSS(_ *cobra.Command, args []string) error { cancel, conf, conf.Accounts.Deployer, - utils.FungibleAdminName, // placeholder value, not used - conf.FungibleAdminMnemonic, // placeholder value, not used + utils.FungibleAdminName, // placeholder value, not used logger, ) if err != nil { diff --git a/cmd/zetae2e/stress.go b/cmd/zetae2e/stress.go index 2fcdb0444c..d5c488dc0e 100644 --- a/cmd/zetae2e/stress.go +++ b/cmd/zetae2e/stress.go @@ -141,7 +141,6 @@ func StressTest(cmd *cobra.Command, _ []string) { conf, conf.Accounts.Deployer, utils.FungibleAdminName, - conf.FungibleAdminMnemonic, logger, ) if err != nil { diff --git a/e2e/e2etests/test_migrate_chain_support.go b/e2e/e2etests/test_migrate_chain_support.go index 183e1b72a4..e2b6d62d52 100644 --- a/e2e/e2etests/test_migrate_chain_support.go +++ b/e2e/e2etests/test_migrate_chain_support.go @@ -237,7 +237,6 @@ func configureEVM2(r *runner.E2ERunner) (*runner.E2ERunner, error) { "admin-evm2", r.CtxCancel, r.DeployerAccount, - r.FungibleAdminMnemonic, r.EVMClient, r.ZEVMClient, r.CctxClient, diff --git a/e2e/runner/runner.go b/e2e/runner/runner.go index eab3c50b3a..32aaf7ba08 100644 --- a/e2e/runner/runner.go +++ b/e2e/runner/runner.go @@ -120,7 +120,6 @@ func NewE2ERunner( name string, ctxCancel context.CancelFunc, account config.Account, - fungibleAdminMnemonic string, evmClient *ethclient.Client, zevmClient *ethclient.Client, cctxClient crosschaintypes.QueryClient, @@ -140,10 +139,9 @@ func NewE2ERunner( Ctx: ctx, CtxCancel: ctxCancel, - DeployerAccount: account, - DeployerAddress: account.EVMAddress(), - DeployerPrivateKey: account.RawPrivateKey.String(), - FungibleAdminMnemonic: fungibleAdminMnemonic, + DeployerAccount: account, + DeployerAddress: account.EVMAddress(), + DeployerPrivateKey: account.RawPrivateKey.String(), ZEVMClient: zevmClient, EVMClient: evmClient, diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index 24478e78dd..b412f13102 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -57,21 +56,20 @@ type ZetaTxServer struct { clientCtx client.Context txFactory tx.Factory name []string - mnemonic []string address []string blockTimeout time.Duration } // NewZetaTxServer returns a new TxServer with provided account -func NewZetaTxServer(rpcAddr string, names []string, mnemonics []string, chainID string) (ZetaTxServer, error) { +func NewZetaTxServer(rpcAddr string, names []string, privateKeys []string, chainID string) (ZetaTxServer, error) { ctx := context.Background() if len(names) == 0 { return ZetaTxServer{}, errors.New("no account provided") } - if len(names) != len(mnemonics) { - return ZetaTxServer{}, errors.New("invalid names and mnemonics") + if len(names) != len(privateKeys) { + return ZetaTxServer{}, errors.New("invalid names and privateKeys") } // initialize rpc and check status @@ -93,10 +91,11 @@ func NewZetaTxServer(rpcAddr string, names []string, mnemonics []string, chainID // create accounts for i := range names { - r, err := kr.NewAccount(names[i], mnemonics[i], "", sdktypes.FullFundraiserPath, hd.Secp256k1) + err = kr.ImportPrivKeyHex(names[i], privateKeys[i], "secp256k1") if err != nil { return ZetaTxServer{}, fmt.Errorf("failed to create account: %s", err.Error()) } + r, err := kr.Key(names[i]) accAddr, err := r.GetAddress() if err != nil { return ZetaTxServer{}, fmt.Errorf("failed to get account address: %s", err.Error()) @@ -112,7 +111,6 @@ func NewZetaTxServer(rpcAddr string, names []string, mnemonics []string, chainID clientCtx: clientCtx, txFactory: txf, name: names, - mnemonic: mnemonics, address: addresses, blockTimeout: 1 * time.Minute, }, nil @@ -155,15 +153,6 @@ func (zts ZetaTxServer) GetAllAccountAddress() []string { } -// GetAccountMnemonic returns the account name from the given index -// returns empty string if index is out of bound, error should be handled by caller -func (zts ZetaTxServer) GetAccountMnemonic(index int) string { - if index >= len(zts.mnemonic) { - return "" - } - return zts.mnemonic[index] -} - // BroadcastTx broadcasts a tx to ZetaChain with the provided msg from the account // and waiting for blockTime for tx to be included in the block func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes.TxResponse, error) {