client: fix signing algorithm (#6405)
* crypto/keyring: fix signing algorithm * client: tests * minor fixes * changelog * address @alexanderbez comments * Update crypto/keyring/keyring.go * Update crypto/keyring/signing_algorithms.go * Update crypto/keyring/keyring.go * Update crypto/keyring/signing_algorithms.go Co-authored-by: Alessio Treglia <alessio@tendermint.com> * fix test Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
co-authored by
Alessio Treglia
parent
4ecbd00436
commit
0215b5c6cd
+3
-2
@@ -120,9 +120,10 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
|
||||
interactive := viper.GetBool(flagInteractive)
|
||||
showMnemonic := !viper.GetBool(flagNoBackup)
|
||||
|
||||
algo, err := keyring.NewSigningAlgoFromString(viper.GetString(flagKeyAlgo))
|
||||
keyringAlgos, _ := kb.SupportedAlgorithms()
|
||||
algo, err := keyring.NewSigningAlgoFromString(viper.GetString(flagKeyAlgo), keyringAlgos)
|
||||
if err != nil {
|
||||
algo = hd.Secp256k1
|
||||
return err
|
||||
}
|
||||
|
||||
if !viper.GetBool(flags.FlagDryRun) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -45,8 +46,10 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
|
||||
viper.Set(flagIndex, "0")
|
||||
viper.Set(flagCoinType, "330")
|
||||
|
||||
/// Test Text
|
||||
// Test Text
|
||||
viper.Set(cli.OutputFlag, OutputFormatText)
|
||||
// set algo flag value to the default
|
||||
viper.Set(flagKeyAlgo, string(hd.Secp256k1Type))
|
||||
// Now enter password
|
||||
mockIn, _, _ := tests.ApplyMockIO(cmd)
|
||||
mockIn.Reset("test1234\ntest1234\n")
|
||||
@@ -57,7 +60,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, kb)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1")
|
||||
_ = kb.Delete("keyname1")
|
||||
})
|
||||
mockIn.Reset("test1234\n")
|
||||
key1, err := kb.Key("keyname1")
|
||||
@@ -89,8 +92,10 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
viper.Set(flags.FlagUseLedger, true)
|
||||
|
||||
/// Test Text
|
||||
// Test Text
|
||||
viper.Set(cli.OutputFlag, OutputFormatText)
|
||||
// set algo flag value to the default
|
||||
viper.Set(flagKeyAlgo, string(hd.Secp256k1Type))
|
||||
// Now enter password
|
||||
mockIn.Reset("test1234\ntest1234\n")
|
||||
viper.Set(flagCoinType, sdk.CoinType)
|
||||
@@ -101,7 +106,7 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, kb)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1")
|
||||
_ = kb.Delete("keyname1")
|
||||
})
|
||||
mockIn.Reset("test1234\n")
|
||||
key1, err := kb.Key("keyname1")
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
func Test_runAddCmdBasic(t *testing.T) {
|
||||
cmd := AddKeyCommand()
|
||||
require.NotNil(t, cmd)
|
||||
|
||||
mockIn, _, _ := tests.ApplyMockIO(cmd)
|
||||
|
||||
kbHome, kbCleanUp := tests.NewTestCaseDir(t)
|
||||
@@ -27,11 +29,14 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
viper.Set(flags.FlagUseLedger, false)
|
||||
|
||||
mockIn.Reset("y\n")
|
||||
// set algo flag value to the default
|
||||
viper.Set(flagKeyAlgo, string(hd.Secp256k1Type))
|
||||
|
||||
kb, err := keyring.New(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1") // nolint:errcheck
|
||||
kb.Delete("keyname2") // nolint:errcheck
|
||||
_ = kb.Delete("keyname1")
|
||||
_ = kb.Delete("keyname2")
|
||||
})
|
||||
require.NoError(t, runAddCmd(cmd, []string{"keyname1"}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user