diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb322561df..a40f1b63d8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (client) [#17197](https://github.com/cosmos/cosmos-sdk/pull/17197) `keys.Commands` does not take a home directory anymore. It is inferred from the root command. * (x/staking) [#17098](https://github.com/cosmos/cosmos-sdk/pull/17098) `NewMsgCreateValidator`, `NewValidator`, `NewMsgCancelUnbondingDelegation`, `NewMsgUndelegate`, `NewMsgBeginRedelegate`, `NewMsgDelegate` and `NewMsgEditValidator` takes a string instead of `sdk.ValAddress` or `sdk.AccAddress`: * `NewMsgCreateValidator.Validate()` takes an address codec in order to decode the address. * `NewRedelegationResponse` takes a string instead of `sdk.ValAddress` or `sdk.AccAddress`. diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index 289200e3fe2..797c0452dfb 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -38,7 +38,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { config.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub) cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) // Prepare a keybase kbHome := t.TempDir() @@ -91,7 +91,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { func Test_runAddCmdLedger(t *testing.T) { cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() @@ -166,7 +166,7 @@ func Test_runAddCmdLedgerDryRun(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) kbHome := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) diff --git a/client/keys/add_test.go b/client/keys/add_test.go index c69c1b81bec..719473aa88e 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -22,7 +22,7 @@ import ( func Test_runAddCmdBasic(t *testing.T) { cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() @@ -41,7 +41,7 @@ func Test_runAddCmdBasic(t *testing.T) { cmd.SetArgs([]string{ "keyname1", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText), fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), @@ -54,7 +54,7 @@ func Test_runAddCmdBasic(t *testing.T) { cmd.SetArgs([]string{ "keyname2", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText), fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), @@ -68,7 +68,7 @@ func Test_runAddCmdBasic(t *testing.T) { cmd.SetArgs([]string{ "keyname4", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText), fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), @@ -79,7 +79,7 @@ func Test_runAddCmdBasic(t *testing.T) { cmd.SetArgs([]string{ "keyname5", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=true", flags.FlagDryRun), fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText), fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type), @@ -186,7 +186,7 @@ func Test_runAddCmdDryRun(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) kbHome := t.TempDir() mockIn := testutil.ApplyMockIODiscardOutErr(cmd) @@ -232,7 +232,7 @@ func Test_runAddCmdDryRun(t *testing.T) { func TestAddRecoverFileBackend(t *testing.T) { cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) cdc := moduletestutil.MakeTestEncodingConfig().Codec mockIn := testutil.ApplyMockIODiscardOutErr(cmd) @@ -243,7 +243,7 @@ func TestAddRecoverFileBackend(t *testing.T) { cmd.SetArgs([]string{ "keyname1", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagOutput, flags.OutputFormatText), fmt.Sprintf("--%s=%s", flags.FlagKeyType, hd.Secp256k1Type), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendFile), diff --git a/client/keys/delete_test.go b/client/keys/delete_test.go index 49f897aece4..29246b1095d 100644 --- a/client/keys/delete_test.go +++ b/client/keys/delete_test.go @@ -21,7 +21,7 @@ func Test_runDeleteCmd(t *testing.T) { // Now add a temporary keybase kbHome := t.TempDir() cmd := DeleteKeyCommand() - cmd.Flags().AddFlagSet(Commands(kbHome).PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) yesF, _ := cmd.Flags().GetBool(flagYes) @@ -36,7 +36,7 @@ func Test_runDeleteCmd(t *testing.T) { path := sdk.GetConfig().GetFullBIP44Path() cdc := moduletestutil.MakeTestEncodingConfig().Codec - cmd.SetArgs([]string{"blah", fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome)}) + cmd.SetArgs([]string{"blah", fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome)}) kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn, cdc) require.NoError(t, err) @@ -59,7 +59,7 @@ func Test_runDeleteCmd(t *testing.T) { // User confirmation missing cmd.SetArgs([]string{ fakeKeyName1, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) err = cmd.Execute() @@ -72,7 +72,7 @@ func Test_runDeleteCmd(t *testing.T) { // Now there is a confirmation cmd.SetArgs([]string{ fakeKeyName1, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=true", flagYes), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) @@ -86,7 +86,7 @@ func Test_runDeleteCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=true", flagYes), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index 9edd5aedf39..d7e4126f6a7 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -72,12 +72,12 @@ func Test_runExportCmd(t *testing.T) { kbHome := t.TempDir() defaultArgs := []string{ "keyname1", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, tc.keyringBackend), } cmd := ExportKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) cmd.SetArgs(append(defaultArgs, tc.extraArgs...)) mockIn, mockOut := testutil.ApplyMockIO(cmd) diff --git a/client/keys/import_test.go b/client/keys/import_test.go index d9b9d0fee79..a64d0ee898f 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -76,7 +76,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { cmd := ImportKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) // Now add a temporary keybase diff --git a/client/keys/list_test.go b/client/keys/list_test.go index 9fd0b70fb27..21f00cd0d44 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -31,7 +31,7 @@ func cleanupKeys(t *testing.T, kb keyring.Keyring, keys ...string) func() { func Test_runListCmd(t *testing.T) { cmd := ListKeysCmd() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) kbHome1 := t.TempDir() kbHome2 := t.TempDir() @@ -62,7 +62,7 @@ func Test_runListCmd(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { cmd.SetArgs([]string{ - fmt.Sprintf("--%s=%s", flags.FlagHome, tt.kbDir), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, tt.kbDir), fmt.Sprintf("--%s=false", flagListNames), }) @@ -71,7 +71,7 @@ func Test_runListCmd(t *testing.T) { } cmd.SetArgs([]string{ - fmt.Sprintf("--%s=%s", flags.FlagHome, tt.kbDir), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, tt.kbDir), fmt.Sprintf("--%s=true", flagListNames), }) diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index 8878f61755c..bacbbacc741 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -61,7 +61,7 @@ func (s *MigrateTestSuite) Test_runListAndShowCmd() { // run test simd keys list - to see that the migrated key is there cmd := ListKeysCmd() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kb, err := keyring.New(s.appName, keyring.BackendTest, s.dir, mockIn, s.cdc) @@ -75,7 +75,7 @@ func (s *MigrateTestSuite) Test_runListAndShowCmd() { ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) cmd.SetArgs([]string{ - fmt.Sprintf("--%s=%s", flags.FlagHome, s.dir), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, s.dir), fmt.Sprintf("--%s=false", flagListNames), }) diff --git a/client/keys/rename_test.go b/client/keys/rename_test.go index 40d7d579330..8df5d641ba0 100644 --- a/client/keys/rename_test.go +++ b/client/keys/rename_test.go @@ -21,7 +21,7 @@ func Test_runRenameCmd(t *testing.T) { // temp keybase kbHome := t.TempDir() cmd := RenameKeyCommand() - cmd.Flags().AddFlagSet(Commands(kbHome).PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) yesF, _ := cmd.Flags().GetBool(flagYes) @@ -47,7 +47,7 @@ func Test_runRenameCmd(t *testing.T) { ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) // rename a key 'blah' which doesnt exist - cmd.SetArgs([]string{"blah", "blaah", fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome)}) + cmd.SetArgs([]string{"blah", "blaah", fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome)}) err = cmd.ExecuteContext(ctx) require.Error(t, err) require.EqualError(t, err, "blah.info: key not found") @@ -56,7 +56,7 @@ func Test_runRenameCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, "nokey", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) err = cmd.Execute() @@ -70,7 +70,7 @@ func Test_runRenameCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=true", flagYes), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) @@ -100,7 +100,7 @@ func Test_runRenameCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=true", flagYes), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) diff --git a/client/keys/root.go b/client/keys/root.go index 92fd3ae2e33..4cadecbc181 100644 --- a/client/keys/root.go +++ b/client/keys/root.go @@ -8,7 +8,7 @@ import ( // Commands registers a sub-tree of commands to interact with // local private key storage. -func Commands(defaultNodeHome string) *cobra.Command { +func Commands() *cobra.Command { cmd := &cobra.Command{ Use: "keys", Short: "Manage your application's keys", @@ -50,7 +50,6 @@ The pass backend requires GnuPG: https://gnupg.org/ MigrateCommand(), ) - cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory") cmd.PersistentFlags().String(flags.FlagOutput, "text", "Output format (text|json)") flags.AddKeyringFlags(cmd.PersistentFlags()) diff --git a/client/keys/root_test.go b/client/keys/root_test.go index 20b3f1a2347..bb204a47499 100644 --- a/client/keys/root_test.go +++ b/client/keys/root_test.go @@ -7,7 +7,7 @@ import ( ) func TestCommands(t *testing.T) { - rootCommands := Commands("home") + rootCommands := Commands() assert.Assert(t, rootCommands != nil) // Commands are registered diff --git a/client/keys/show_test.go b/client/keys/show_test.go index 7a180c1a10c..59d3b2a3247 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -49,7 +49,7 @@ func Test_showKeysCmd(t *testing.T) { func Test_runShowCmd(t *testing.T) { cmd := ShowKeysCmd() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) + cmd.Flags().AddFlagSet(Commands().PersistentFlags()) mockIn := testutil.ApplyMockIODiscardOutErr(cmd) kbHome := t.TempDir() @@ -87,7 +87,7 @@ func Test_runShowCmd(t *testing.T) { // Now try single key cmd.SetArgs([]string{ fakeKeyName1, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=", FlagBechPrefix), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) @@ -95,7 +95,7 @@ func Test_runShowCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", FlagBechPrefix, sdk.PrefixAccount), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) @@ -110,7 +110,7 @@ func Test_runShowCmd(t *testing.T) { require.NoError(t, err) cmd.SetArgs([]string{ addr.String(), - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", FlagBechPrefix, sdk.PrefixAccount), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), }) @@ -120,7 +120,7 @@ func Test_runShowCmd(t *testing.T) { // Now try multisig key - set bech to acc cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", FlagBechPrefix, sdk.PrefixAccount), fmt.Sprintf("--%s=0", flagMultiSigThreshold), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), @@ -129,7 +129,7 @@ func Test_runShowCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=%s", FlagBechPrefix, sdk.PrefixAccount), fmt.Sprintf("--%s=2", flagMultiSigThreshold), fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), @@ -139,7 +139,7 @@ func Test_runShowCmd(t *testing.T) { // Now try multisig key - set bech to acc + threshold=2 cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=acc", FlagBechPrefix), fmt.Sprintf("--%s=true", FlagDevice), fmt.Sprintf("--%s=2", flagMultiSigThreshold), @@ -149,7 +149,7 @@ func Test_runShowCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=val", FlagBechPrefix), fmt.Sprintf("--%s=true", FlagDevice), fmt.Sprintf("--%s=2", flagMultiSigThreshold), @@ -159,7 +159,7 @@ func Test_runShowCmd(t *testing.T) { cmd.SetArgs([]string{ fakeKeyName1, fakeKeyName2, - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), + fmt.Sprintf("--%s=%s", flags.FlagKeyringDir, kbHome), fmt.Sprintf("--%s=val", FlagBechPrefix), fmt.Sprintf("--%s=true", FlagDevice), fmt.Sprintf("--%s=2", flagMultiSigThreshold), diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index a392ec87216..70f1cf9f2af 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -209,7 +209,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b genesisCommand(encodingConfig, basicManager), txCommand(), queryCommand(), - keys.Commands(simapp.DefaultNodeHome), + keys.Commands(), ) } diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 72f5dff29d7..bdad9390bc2 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -225,7 +225,7 @@ func initRootCmd( genesisCommand(txConfig, basicManager), queryCommand(), txCommand(), - keys.Commands(simapp.DefaultNodeHome), + keys.Commands(), ) }