fix: account unmarshaling
JSON deserialization hasn't worked correctly, resulting in empty publicKey. That led to an account created with nil color hash and color id.
This commit is contained in:
parent
ee7025a573
commit
a471fed6a6
|
@ -282,9 +282,16 @@ func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subacc
|
||||||
|
|
||||||
for _, acc := range subaccs {
|
for _, acc := range subaccs {
|
||||||
if acc.Chat {
|
if acc.Chat {
|
||||||
colorHash, _ := colorhash.GenerateFor(string(acc.PublicKey.Bytes()))
|
colorHash, err := colorhash.GenerateFor(string(acc.PublicKey.Bytes()))
|
||||||
colorID, _ := identityUtils.ToColorID(string(acc.PublicKey.Bytes()))
|
if err != nil {
|
||||||
|
return makeJSONResponse(err)
|
||||||
|
}
|
||||||
account.ColorHash = colorHash
|
account.ColorHash = colorHash
|
||||||
|
|
||||||
|
colorID, err := identityUtils.ToColorID(string(acc.PublicKey.Bytes()))
|
||||||
|
if err != nil {
|
||||||
|
return makeJSONResponse(err)
|
||||||
|
}
|
||||||
account.ColorID = colorID
|
account.ColorID = colorID
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package accounts
|
package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -33,3 +34,28 @@ func TestIsOwnAccount(t *testing.T) {
|
||||||
account = Account{}
|
account = Account{}
|
||||||
require.False(t, account.IsOwnAccount())
|
require.False(t, account.IsOwnAccount())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshal(t *testing.T) {
|
||||||
|
data := `
|
||||||
|
{
|
||||||
|
"public-key": "0x0465f6d4f1172524fc057954c8a3f8e34f991558b3d1097189975062f67adda7835da61acb5cda3348b41d211ed0cb07aba668eb12e19e29d98745bebf68d93b61",
|
||||||
|
"address": "0xf09c9f5Fb9faa22d0C6C593e7157Ceac8B2b0fe4",
|
||||||
|
"color": "#4360df",
|
||||||
|
"wallet": true,
|
||||||
|
"path": "m/44'/60'/0'/0/0",
|
||||||
|
"name": "Status account",
|
||||||
|
"derived-from": "0x6f015A79890Dcb38eFeC1D83772d57159D2eb58b"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
var account Account
|
||||||
|
err := json.Unmarshal([]byte(data), &account)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, []byte("0x0465f6d4f1172524fc057954c8a3f8e34f991558b3d1097189975062f67adda7835da61acb5cda3348b41d211ed0cb07aba668eb12e19e29d98745bebf68d93b61"), account.PublicKey.Bytes())
|
||||||
|
require.Equal(t, "0xf09c9f5Fb9faa22d0C6C593e7157Ceac8B2b0fe4", account.Address.String())
|
||||||
|
require.Equal(t, "#4360df", account.Color)
|
||||||
|
require.Equal(t, true, account.Wallet)
|
||||||
|
require.Equal(t, "m/44'/60'/0'/0/0", account.Path)
|
||||||
|
require.Equal(t, "Status account", account.Name)
|
||||||
|
require.Equal(t, "0x6f015A79890Dcb38eFeC1D83772d57159D2eb58b", account.DerivedFrom)
|
||||||
|
}
|
||||||
|
|
|
@ -19,20 +19,20 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Address types.Address
|
Address types.Address `json:"address"`
|
||||||
Wallet bool
|
Wallet bool `json:"wallet"`
|
||||||
Chat bool
|
Chat bool `json:"chat"`
|
||||||
Type string
|
Type string `json:"type,omitempty"`
|
||||||
Storage string
|
Storage string `json:"storage,omitempty"`
|
||||||
Path string
|
Path string `json:"path,omitempty"`
|
||||||
PublicKey types.HexBytes
|
PublicKey types.HexBytes `json:"public-key,omitempty"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Emoji string
|
Emoji string `json:"emoji"`
|
||||||
Color string
|
Color string `json:"color"`
|
||||||
Hidden bool
|
Hidden bool `json:"hidden"`
|
||||||
DerivedFrom string
|
DerivedFrom string `json:"derived-from,omitempty"`
|
||||||
Clock uint64
|
Clock uint64 `json:"clock,omitempty"`
|
||||||
Removed bool
|
Removed bool `json:"removed,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
Loading…
Reference in New Issue