2020-12-07 14:03:18 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
2022-05-30 06:19:49 +00:00
|
|
|
"encoding/json"
|
2020-12-07 14:03:18 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-02 15:06:51 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/multiaccounts/common"
|
2020-12-07 14:03:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsOwnAccount(t *testing.T) {
|
2023-11-17 15:28:37 +00:00
|
|
|
account := Account{Wallet: true, Type: AccountTypeGenerated}
|
2023-11-17 11:55:10 +00:00
|
|
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
2020-12-07 14:03:18 +00:00
|
|
|
|
|
|
|
account = Account{
|
2022-07-06 16:12:49 +00:00
|
|
|
Type: AccountTypeGenerated,
|
2020-12-07 14:03:18 +00:00
|
|
|
}
|
2023-11-17 11:55:10 +00:00
|
|
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
2020-12-07 14:03:18 +00:00
|
|
|
|
|
|
|
account = Account{
|
2022-07-06 16:12:49 +00:00
|
|
|
Type: AccountTypeKey,
|
2020-12-07 14:03:18 +00:00
|
|
|
}
|
2023-11-17 11:55:10 +00:00
|
|
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
2020-12-07 14:03:18 +00:00
|
|
|
|
|
|
|
account = Account{
|
2022-07-06 16:12:49 +00:00
|
|
|
Type: AccountTypeSeed,
|
2020-12-07 14:03:18 +00:00
|
|
|
}
|
2023-11-17 11:55:10 +00:00
|
|
|
require.True(t, account.IsWalletNonWatchOnlyAccount())
|
2020-12-07 14:03:18 +00:00
|
|
|
|
|
|
|
account = Account{
|
2022-05-18 10:42:51 +00:00
|
|
|
Type: AccountTypeWatch,
|
2020-12-07 14:03:18 +00:00
|
|
|
}
|
2023-11-17 11:55:10 +00:00
|
|
|
require.False(t, account.IsWalletNonWatchOnlyAccount())
|
2020-12-07 14:03:18 +00:00
|
|
|
|
|
|
|
account = Account{}
|
2023-11-17 11:55:10 +00:00
|
|
|
require.False(t, account.IsWalletNonWatchOnlyAccount())
|
2020-12-07 14:03:18 +00:00
|
|
|
}
|
2022-05-30 06:19:49 +00:00
|
|
|
|
|
|
|
func TestUnmarshal(t *testing.T) {
|
|
|
|
data := `
|
|
|
|
{
|
2023-05-16 10:50:04 +00:00
|
|
|
"key-uid": "0xbc14c321b74652e57c7f26eb30d597ea27cbdf36cba5c85d24f12748153a035e",
|
2022-05-30 06:19:49 +00:00
|
|
|
"public-key": "0x0465f6d4f1172524fc057954c8a3f8e34f991558b3d1097189975062f67adda7835da61acb5cda3348b41d211ed0cb07aba668eb12e19e29d98745bebf68d93b61",
|
|
|
|
"address": "0xf09c9f5Fb9faa22d0C6C593e7157Ceac8B2b0fe4",
|
2023-06-02 15:06:51 +00:00
|
|
|
"colorId": "primary",
|
2022-05-30 06:19:49 +00:00
|
|
|
"wallet": true,
|
2023-05-16 10:50:04 +00:00
|
|
|
"chat": true,
|
2022-05-30 06:19:49 +00:00
|
|
|
"path": "m/44'/60'/0'/0/0",
|
|
|
|
"name": "Status account",
|
2023-05-16 10:50:04 +00:00
|
|
|
"type": "generated",
|
|
|
|
"emoji": "some-emoji",
|
|
|
|
"hidden": true,
|
|
|
|
"clock": 1234,
|
|
|
|
"removed": true,
|
|
|
|
"operable": "fully"
|
2022-05-30 06:19:49 +00:00
|
|
|
}
|
|
|
|
`
|
|
|
|
var account Account
|
|
|
|
err := json.Unmarshal([]byte(data), &account)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
require.Equal(t, "0xbc14c321b74652e57c7f26eb30d597ea27cbdf36cba5c85d24f12748153a035e", account.KeyUID)
|
2022-05-30 06:19:49 +00:00
|
|
|
require.Equal(t, []byte("0x0465f6d4f1172524fc057954c8a3f8e34f991558b3d1097189975062f67adda7835da61acb5cda3348b41d211ed0cb07aba668eb12e19e29d98745bebf68d93b61"), account.PublicKey.Bytes())
|
|
|
|
require.Equal(t, "0xf09c9f5Fb9faa22d0C6C593e7157Ceac8B2b0fe4", account.Address.String())
|
2023-06-02 15:06:51 +00:00
|
|
|
require.Equal(t, common.CustomizationColorPrimary, account.ColorID)
|
2022-05-30 06:19:49 +00:00
|
|
|
require.Equal(t, true, account.Wallet)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.Equal(t, true, account.Chat)
|
2022-05-30 06:19:49 +00:00
|
|
|
require.Equal(t, "m/44'/60'/0'/0/0", account.Path)
|
|
|
|
require.Equal(t, "Status account", account.Name)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.Equal(t, "generated", account.Type.String())
|
|
|
|
require.Equal(t, "some-emoji", account.Emoji)
|
|
|
|
require.Equal(t, true, account.Hidden)
|
|
|
|
require.Equal(t, uint64(1234), account.Clock)
|
|
|
|
require.Equal(t, true, account.Removed)
|
|
|
|
require.Equal(t, "fully", account.Operable.String())
|
2022-05-30 06:19:49 +00:00
|
|
|
}
|