Fabo/Switch key creation REST output to bech32 address (#1522)

* switch new key output to bech32
* changelog
* fixed tests
* Update LCD TestKeys failure message
This commit is contained in:
Fabian 2018-07-03 21:31:15 +02:00 committed by Christopher Goes
parent 3f438cdbc2
commit a118229fcb
3 changed files with 14 additions and 8 deletions

View File

@ -36,6 +36,7 @@ BREAKING CHANGES
to an infraction, slash them proportional to their stake at the time
* Add REST endpoint to unrevoke a validator previously revoked for downtime
* Add REST endpoint to retrieve liveness signing information for a validator
* [lcd] Switch key creation output to return bech32
FEATURES
* [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag

View File

@ -7,6 +7,7 @@ import (
"net/http"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -215,8 +216,14 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(err.Error()))
return
}
bech32Account, err := sdk.Bech32ifyAcc(sdk.Address(info.GetPubKey().Address().Bytes()))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
bz, err := json.Marshal(NewKeyResponse{
Address: info.GetPubKey().Address().String(),
Address: bech32Account,
Mnemonic: mnemonic,
})
if err != nil {

View File

@ -8,7 +8,6 @@ import (
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cryptoKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
@ -59,9 +58,11 @@ func TestKeys(t *testing.T) {
require.Equal(t, http.StatusOK, res.StatusCode, body)
var resp keys.NewKeyResponse
err = wire.Cdc.UnmarshalJSON([]byte(body), &resp)
require.Nil(t, err)
addr2 := resp.Address
assert.Len(t, addr2, 40, "Returned address has wrong format", addr2)
require.Nil(t, err, body)
addr2Bech32 := resp.Address
_, err = sdk.GetAccAddressBech32(addr2Bech32)
require.NoError(t, err, "Failed to return a correct bech32 address")
// existing keys
res, body = Request(t, port, "GET", "/keys", nil)
@ -70,9 +71,6 @@ func TestKeys(t *testing.T) {
err = cdc.UnmarshalJSON([]byte(body), &m)
require.Nil(t, err)
addr2Acc, err := sdk.GetAccAddressHex(addr2)
require.Nil(t, err)
addr2Bech32 := sdk.MustBech32ifyAcc(addr2Acc)
addrBech32 := sdk.MustBech32ifyAcc(addr)
require.Equal(t, name, m[0].Name, "Did not serve keys name correctly")