Skip to content

Commit

Permalink
import private key rather than mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jun 18, 2024
1 parent 5d41166 commit 9dddbdd
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 38 deletions.
3 changes: 1 addition & 2 deletions cmd/zetae2e/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/bitcoin_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func RunnerFromConfig(
conf config.Config,
account config.Account,
zetaUserName string,
zetaUserMnemonic string,
logger *runner.Logger,
) (*runner.E2ERunner, error) {
// initialize clients
Expand All @@ -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 {
Expand All @@ -53,7 +52,6 @@ func RunnerFromConfig(
name,
ctxCancel,
account,
zetaUserMnemonic,
evmClient,
zevmClient,
cctxClient,
Expand Down
1 change: 0 additions & 1 deletion cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
conf,
conf.Accounts.Deployer,
utils.FungibleAdminName,
conf.FungibleAdminMnemonic,
logger,
)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/zetae2e/local/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func initTestRunner(
conf,
account,
utils.FungibleAdminName,
conf.FungibleAdminMnemonic,
logger,
)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/setup_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/show_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion cmd/zetae2e/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func StressTest(cmd *cobra.Command, _ []string) {
conf,
conf.Accounts.Deployer,
utils.FungibleAdminName,
conf.FungibleAdminMnemonic,
logger,
)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion e2e/e2etests/test_migrate_chain_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions e2e/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
21 changes: 5 additions & 16 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9dddbdd

Please sign in to comment.