From e400e83c43d6ec0b1f938d0fd8218bdba380e0c9 Mon Sep 17 00:00:00 2001 From: Fabian Weber Date: Thu, 12 Jul 2018 15:28:28 +0200 Subject: [PATCH 1/4] fix key import creating random account --- client/keys/add.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/keys/add.go b/client/keys/add.go index 1bd13dd0a299..d462db1c0697 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -161,6 +161,7 @@ func printCreate(info keys.Info, seed string) { type NewKeyBody struct { Name string `json:"name"` Password string `json:"password"` + Seed string `json:"seed"` } // add new key REST handler @@ -205,7 +206,11 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { } // create account - info, mnemonic, err := kb.CreateMnemonic(m.Name, keys.English, m.Password, keys.Secp256k1) + seed := m.Seed + if seed == "" { + seed = getSeed(keys.Secp256k1) + } + info, err := kb.CreateKey(m.Name, seed, m.Password) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(err.Error())) @@ -219,7 +224,7 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { return } - keyOutput.Seed = mnemonic + keyOutput.Seed = seed bz, err := json.Marshal(keyOutput) if err != nil { From f8f46b2b8c670d53649a5c160b992d0aa27e6c69 Mon Sep 17 00:00:00 2001 From: Fabian Weber Date: Thu, 12 Jul 2018 16:19:20 +0200 Subject: [PATCH 2/4] added test for account importing --- client/lcd/lcd_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 48c1529c5760..8d1a030a05c3 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/spf13/viper" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys" @@ -52,7 +53,7 @@ func TestKeys(t *testing.T) { newPassword := "0987654321" // add key - jsonStr := []byte(fmt.Sprintf(`{"name":"%s", "password":"%s"}`, newName, newPassword)) + jsonStr := []byte(fmt.Sprintf(`{"name":"%s", "password":"%s", "seed":"%s"}`, newName, newPassword, seed)) res, body = Request(t, port, "POST", "/keys", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -64,6 +65,11 @@ func TestKeys(t *testing.T) { _, err = sdk.AccAddressFromBech32(addr2Bech32) require.NoError(t, err, "Failed to return a correct bech32 address") + // test if created account is the correct account + expectedInfo, _ := GetKB(t).CreateKey(newName, seed, newPassword) + expectedAccount := sdk.AccAddress(expectedInfo.GetPubKey().Address().Bytes()) + assert.Equal(t, expectedAccount.String(), addr2Bech32) + // existing keys res, body = Request(t, port, "GET", "/keys", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) From c3bbb37df3e37c8c3903a00a9587f98f18af9902 Mon Sep 17 00:00:00 2001 From: Fabian Weber Date: Thu, 12 Jul 2018 16:22:26 +0200 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4adaecaa781a..6396fe586198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,7 @@ BUG FIXES * \#1287 - prevent zero power validators at genesis * [x/stake] fix bug when unbonding/redelegating using `--shares-percent` * \#1010 - two validators can't bond with the same pubkey anymore +* [lcd] importing an account would create a random account ## 0.19.0 From 8b9f5396de2831347dfcfea932e60e84286613d6 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 12 Jul 2018 19:45:09 +0200 Subject: [PATCH 4/4] Move changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6396fe586198..7e57b8a32415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ FEATURES BUG FIXES * [keys] \#1629 - updating password no longer asks for a new password when the first entered password was incorrect +* [lcd] importing an account would create a random account ## 0.20.0 @@ -151,7 +152,6 @@ BUG FIXES * \#1287 - prevent zero power validators at genesis * [x/stake] fix bug when unbonding/redelegating using `--shares-percent` * \#1010 - two validators can't bond with the same pubkey anymore -* [lcd] importing an account would create a random account ## 0.19.0