Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom mnemonics in in-process testing network (backport #10922) #10935

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
updates
  • Loading branch information
alexanderbez committed Jan 13, 2022
commit 1a5be54e337089622f0cdb04df313c6c6a46b50f
52 changes: 23 additions & 29 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ import (
// phrase to recover the private key.
func GenerateCoinKey(algo keyring.SignatureAlgo) (sdk.AccAddress, string, error) {
// generate a private key, with recovery phrase
info, secret, err := keyring.NewInMemory().NewMnemonic("name", keyring.English, sdk.GetConfig().GetFullBIP44Path(), keyring.DefaultBIP39Passphrase, algo)
info, secret, err := keyring.NewInMemory().NewMnemonic(
"name",
keyring.English,
sdk.GetConfig().GetFullBIP44Path(),
keyring.DefaultBIP39Passphrase,
algo)
if err != nil {
return sdk.AccAddress{}, "", err
}
<<<<<<< HEAD
return sdk.AccAddress(info.GetPubKey().Address()), secret, nil
=======

addr, err := k.GetAddress()
if err != nil {
return nil, "", err
}

return addr, secret, nil
>>>>>>> b0190834c (feat: support custom mnemonics in in-process testing network (#10922))
return sdk.AccAddress(info.GetPubKey().Address()), secret, nil
}

// GenerateSaveCoinKey returns the address of a public key, along with the secret
Expand All @@ -50,39 +46,37 @@ func GenerateSaveCoinKey(

// remove the old key by name if it exists
if exists {
if err = keybase.Delete(keyName); err != nil {
if err := keybase.Delete(keyName); err != nil {
return sdk.AccAddress{}, "", fmt.Errorf("failed to overwrite key")
}
}

<<<<<<< HEAD
info, secret, err := keybase.NewMnemonic(keyName, keyring.English, sdk.GetConfig().GetFullBIP44Path(), keyring.DefaultBIP39Passphrase, algo)
=======
var (
record *keyring.Record
info keyring.Info
secret string
)

// generate or recover a new account
if mnemonic != "" {
secret = mnemonic
record, err = keybase.NewAccount(keyName, mnemonic, keyring.DefaultBIP39Passphrase, sdk.GetConfig().GetFullBIP44Path(), algo)
info, err = keybase.NewAccount(
keyName,
mnemonic,
keyring.DefaultBIP39Passphrase,
sdk.GetConfig().GetFullBIP44Path(),
algo,
)
} else {
record, secret, err = keybase.NewMnemonic(keyName, keyring.English, sdk.GetConfig().GetFullBIP44Path(), keyring.DefaultBIP39Passphrase, algo)
info, secret, err = keybase.NewMnemonic(
keyName,
keyring.English,
sdk.GetConfig().GetFullBIP44Path(),
keyring.DefaultBIP39Passphrase,
algo,
)
}
>>>>>>> b0190834c (feat: support custom mnemonics in in-process testing network (#10922))
if err != nil {
return sdk.AccAddress{}, "", err
}

<<<<<<< HEAD
return sdk.AccAddress(info.GetPubKey().Address()), secret, nil
=======
addr, err := record.GetAddress()
if err != nil {
return nil, "", err
}

return addr, secret, nil
>>>>>>> b0190834c (feat: support custom mnemonics in in-process testing network (#10922))
}
27 changes: 1 addition & 26 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,15 @@ func New(t *testing.T, cfg Config) *Network {
tmCfg.ProxyApp = proxyAddr

p2pAddr, _, err := server.FreeTCPAddr()
<<<<<<< HEAD
require.NoError(t, err)
=======
if err != nil {
return nil, err
}

>>>>>>> b0190834c (feat: support custom mnemonics in in-process testing network (#10922))
tmCfg.P2P.ListenAddress = p2pAddr
tmCfg.P2P.AddrBookStrict = false
tmCfg.P2P.AllowDuplicateIP = true

nodeID, pubKey, err := genutil.InitializeNodeValidatorFiles(tmCfg)
<<<<<<< HEAD
require.NoError(t, err)
=======
if err != nil {
return nil, err
}

>>>>>>> b0190834c (feat: support custom mnemonics in in-process testing network (#10922))
nodeIDs[i] = nodeID
valPubKeys[i] = pubKey

Expand All @@ -296,26 +284,13 @@ func New(t *testing.T, cfg Config) *Network {
algo, err := keyring.NewSigningAlgoFromString(cfg.SigningAlgo, keyringAlgos)
require.NoError(t, err)

<<<<<<< HEAD
addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, true, algo)
require.NoError(t, err)
=======
var mnemonic string
if i < len(cfg.Mnemonics) {
mnemonic = cfg.Mnemonics[i]
}

addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, mnemonic, true, algo)
if err != nil {
return nil, err
}

// if PrintMnemonic is set to true, we print the first validator node's secret to the network's logger
// for debugging and manual testing
if cfg.PrintMnemonic && i == 0 {
printMnemonic(l, secret)
}
>>>>>>> b0190834c (feat: support custom mnemonics in in-process testing network (#10922))
require.NoError(t, err)

info := map[string]string{"secret": secret}
infoBz, err := json.Marshal(info)
Expand Down