Merge PR #1651: Fabo/fix account creation lcd
This commit is contained in:
commit
b3e45413ed
|
@ -15,6 +15,7 @@ FEATURES
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
* [keys] \#1629 - updating password no longer asks for a new password when the first entered password was incorrect
|
* [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
|
## 0.20.0
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,7 @@ func printCreate(info keys.Info, seed string) {
|
||||||
type NewKeyBody struct {
|
type NewKeyBody struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
Seed string `json:"seed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// add new key REST handler
|
// add new key REST handler
|
||||||
|
@ -205,7 +206,11 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create account
|
// 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 {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
|
@ -219,7 +224,7 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
keyOutput.Seed = mnemonic
|
keyOutput.Seed = seed
|
||||||
|
|
||||||
bz, err := json.Marshal(keyOutput)
|
bz, err := json.Marshal(keyOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||||
|
@ -52,7 +53,7 @@ func TestKeys(t *testing.T) {
|
||||||
newPassword := "0987654321"
|
newPassword := "0987654321"
|
||||||
|
|
||||||
// add key
|
// 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)
|
res, body = Request(t, port, "POST", "/keys", jsonStr)
|
||||||
|
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
@ -64,6 +65,11 @@ func TestKeys(t *testing.T) {
|
||||||
_, err = sdk.AccAddressFromBech32(addr2Bech32)
|
_, err = sdk.AccAddressFromBech32(addr2Bech32)
|
||||||
require.NoError(t, err, "Failed to return a correct bech32 address")
|
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
|
// existing keys
|
||||||
res, body = Request(t, port, "GET", "/keys", nil)
|
res, body = Request(t, port, "GET", "/keys", nil)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
Loading…
Reference in New Issue