diff --git a/client/keys/add.go b/client/keys/add.go index 6f847a7fe4f8..1e8783550098 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -88,12 +88,8 @@ func runAddCmdPrepare(cmd *cobra.Command, args []string) error { return err } -<<<<<<< HEAD - return RunAddCmd(clientCtx, cmd, args, buf) -======= buf := bufio.NewReader(clientCtx.Input) - return runAddCmd(clientCtx, cmd, args, buf) ->>>>>>> f479b515a (fix: file keyring fails to add/import/export keys when input is not stdin (fix #9566) (#9821)) + return RunAddCmd(clientCtx, cmd, args, buf) } /* diff --git a/client/keys/add_test.go b/client/keys/add_test.go index 4e513884189b..6c8af3867da6 100644 --- a/client/keys/add_test.go +++ b/client/keys/add_test.go @@ -115,118 +115,6 @@ func Test_runAddCmdBasic(t *testing.T) { mockIn.Reset("\n" + password + "\n" + "fail" + "\n") require.Error(t, cmd.ExecuteContext(ctx)) } -<<<<<<< HEAD -======= - -func Test_runAddCmdDryRun(t *testing.T) { - pubkey1 := `{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AtObiFVE4s+9+RX5SP8TN9r2mxpoaT4eGj9CJfK7VRzN"}` - pubkey2 := `{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/se1vkqgdQ7VJQCM4mxN+L+ciGhnnJ4XYsQCRBMrdRi"}` - - testData := []struct { - name string - args []string - added bool - }{ - { - name: "account is added", - args: []string{ - "testkey", - fmt.Sprintf("--%s=%s", flags.FlagDryRun, "false"), - }, - added: true, - }, - { - name: "account is not added with dry run", - args: []string{ - "testkey", - fmt.Sprintf("--%s=%s", flags.FlagDryRun, "true"), - }, - added: false, - }, - { - name: "multisig account is added", - args: []string{ - "testkey", - fmt.Sprintf("--%s=%s", flags.FlagDryRun, "false"), - fmt.Sprintf("--%s=%s", flagMultisig, "subkey"), - }, - added: true, - }, - { - name: "multisig account is not added with dry run", - args: []string{ - "testkey", - fmt.Sprintf("--%s=%s", flags.FlagDryRun, "true"), - fmt.Sprintf("--%s=%s", flagMultisig, "subkey"), - }, - added: false, - }, - { - name: "pubkey account is added", - args: []string{ - "testkey", - fmt.Sprintf("--%s=%s", flags.FlagDryRun, "false"), - fmt.Sprintf("--%s=%s", FlagPublicKey, pubkey1), - }, - added: true, - }, - { - name: "pubkey account is not added with dry run", - args: []string{ - "testkey", - fmt.Sprintf("--%s=%s", flags.FlagDryRun, "true"), - fmt.Sprintf("--%s=%s", FlagPublicKey, pubkey2), - }, - added: false, - }, - } - for _, tt := range testData { - tt := tt - t.Run(tt.name, func(t *testing.T) { - cmd := AddKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) - - kbHome := t.TempDir() - mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) - require.NoError(t, err) - - appCodec := simapp.MakeTestEncodingConfig().Codec - clientCtx := client.Context{}. - WithCodec(appCodec). - WithKeyringDir(kbHome). - WithKeyring(kb) - ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) - - path := sdk.GetConfig().GetFullBIP44Path() - _, err = kb.NewAccount("subkey", testutil.TestMnemonic, "", path, hd.Secp256k1) - require.NoError(t, err) - - t.Cleanup(func() { - _ = kb.Delete("subkey") - }) - - b := bytes.NewBufferString("") - cmd.SetOut(b) - - cmd.SetArgs(tt.args) - require.NoError(t, cmd.ExecuteContext(ctx)) - - if tt.added { - _, err = kb.Key("testkey") - require.NoError(t, err) - - out, err := ioutil.ReadAll(b) - require.NoError(t, err) - require.Contains(t, string(out), "name: testkey") - } else { - _, err = kb.Key("testkey") - require.Error(t, err) - require.Equal(t, "testkey.info: key not found", err.Error()) - } - }) - } -} func TestAddRecoverFileBackend(t *testing.T) { cmd := AddKeyCommand() @@ -271,4 +159,3 @@ func TestAddRecoverFileBackend(t *testing.T) { require.NoError(t, err) require.Equal(t, "keyname1", info.GetName()) } ->>>>>>> f479b515a (fix: file keyring fails to add/import/export keys when input is not stdin (fix #9566) (#9821)) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index 3508db5bf0f5..7b07bbc6dbd5 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -18,31 +18,6 @@ import ( ) func Test_runExportCmd(t *testing.T) { -<<<<<<< HEAD - cmd := ExportKeyCommand() - cmd.Flags().AddFlagSet(Commands("home").PersistentFlags()) - mockIn := testutil.ApplyMockIODiscardOutErr(cmd) - - // Now add a temporary keybase - kbHome := t.TempDir() - - // create a key - kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) - require.NoError(t, err) - t.Cleanup(func() { - kb.Delete("keyname1") // nolint:errcheck - }) - - path := sdk.GetConfig().GetFullFundraiserPath() - _, err = kb.NewAccount("keyname1", testutil.TestMnemonic, "", path, hd.Secp256k1) - require.NoError(t, err) - - // Now enter password - args := []string{ - "keyname1", - fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome), - fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendTest), -======= testCases := []struct { name string keyringBackend string @@ -88,7 +63,6 @@ func Test_runExportCmd(t *testing.T) { mustFail: false, expectedOutput: "2485e33678db4175dc0ecef2d6e1fc493d4a0d7f7ce83324b6ed70afe77f3485\n", }, ->>>>>>> f479b515a (fix: file keyring fails to add/import/export keys when input is not stdin (fix #9566) (#9821)) } for _, tc := range testCases { @@ -116,7 +90,7 @@ func Test_runExportCmd(t *testing.T) { kb.Delete("keyname1") // nolint:errcheck }) - path := sdk.GetConfig().GetFullBIP44Path() + path := sdk.GetConfig().GetFullFundraiserPath() _, err = kb.NewAccount("keyname1", testutil.TestMnemonic, "", path, hd.Secp256k1) require.NoError(t, err)