Skip to content

Commit

Permalink
fix: merge conflict backporting pr-9821 (#9888)
Browse files Browse the repository at this point in the history
  • Loading branch information
daeMOn63 authored Aug 9, 2021
1 parent f6ad78f commit 30e4471
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 145 deletions.
6 changes: 1 addition & 5 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/*
Expand Down
113 changes: 0 additions & 113 deletions client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
28 changes: 1 addition & 27 deletions client/keys/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 30e4471

Please sign in to comment.