Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yenda committed Dec 19, 2019
1 parent 4a8e579 commit c1facdf
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 79 deletions.
18 changes: 17 additions & 1 deletion api/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ import (
"github.com/stretchr/testify/require"
)

var (
settings = accounts.Settings{
Address: common.HexToAddress("0xdC540f3745Ff2964AFC1171a5A0DD726d1F6B472"),
DappsAddress: common.HexToAddress("0xD1300f99fDF7346986CbC766903245087394ecd0"),
EIP1581Address: common.HexToAddress("0xB1DDDE9235a541d1344550d969715CF43982de9f"),
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
KeyUID: "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab",
LatestDerivedPath: 0,
Name: "Jittery Cornflowerblue Kingbird",
PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==",
PreviewPrivacy: false,
PublicKey: "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0",
SigningPhrase: "yurt joey vibe",
WalletRootAddress: common.HexToAddress("0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")}
)

func TestBackendStartNodeConcurrently(t *testing.T) {
utils.Init()

Expand Down Expand Up @@ -586,7 +602,7 @@ func TestLoginWithKey(t *testing.T) {
require.NoError(t, b.OpenAccounts())

address := crypto.PubkeyToAddress(walletKey.PublicKey)
require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", conf, []accounts.Account{{Address: address, Wallet: true}}, keyhex))
require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", settings, conf, []accounts.Account{{Address: address, Wallet: true}}, keyhex))
require.NoError(t, b.Logout())
require.NoError(t, b.StopNode())

Expand Down
6 changes: 3 additions & 3 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (b *GethStatusBackend) StartNodeWithAccount(acc multiaccounts.Account, pass
return err
}

func (b *GethStatusBackend) SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, settings accounts.Settings, conf *params.NodeConfig, subaccs []accounts.Account, keyHex string) error {
func (b *GethStatusBackend) SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, settings accounts.Settings, nodecfg *params.NodeConfig, subaccs []accounts.Account, keyHex string) error {
err := b.SaveAccount(acc)
if err != nil {
return err
Expand Down Expand Up @@ -338,11 +338,11 @@ func (b *GethStatusBackend) StartNodeWithAccountAndConfig(account multiaccounts.
}


func (b *GethStatusBackend) saveAccountsAndSettings(settings accounts.Settings, config *params.NodeConfig, subaccs []accounts.Account) error {
func (b *GethStatusBackend) saveAccountsAndSettings(settings accounts.Settings, nodecfg *params.NodeConfig, subaccs []accounts.Account) error {
b.mu.Lock()
defer b.mu.Unlock()
accdb := accounts.NewDB(b.appDB)
err = accdb.CreateSettings(settings, conf)
err := accdb.CreateSettings(settings, nodecfg)
if err != nil {
return err
}
Expand Down
18 changes: 14 additions & 4 deletions mobile/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,17 @@ func Login(accountData, password string) string {
}

// SaveAccountAndLogin saves account in status-go database..
func SaveAccountAndLogin(accountData, password, configJSON, subaccountData string) string {
func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subaccountData string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
var settings accounts.Settings
err = json.Unmarshal([]byte(settingsJSON), &settings)
if err != nil {
return makeJSONResponse(err)
}
var conf params.NodeConfig
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
Expand All @@ -358,7 +363,7 @@ func SaveAccountAndLogin(accountData, password, configJSON, subaccountData strin
}
api.RunAsync(func() error {
log.Debug("starting a node, and saving account with configuration", "key-uid", account.KeyUID)
err := statusBackend.StartNodeWithAccountAndConfig(account, password, &conf, subaccs)
err := statusBackend.StartNodeWithAccountAndConfig(account, password, settings, &conf, subaccs)
if err != nil {
log.Error("failed to start node and save account", "key-uid", account.KeyUID, "error", err)
return err
Expand All @@ -376,12 +381,17 @@ func InitKeystore(keydir string) string {
}

// SaveAccountAndLoginWithKeycard saves account in status-go database..
func SaveAccountAndLoginWithKeycard(accountData, password, configJSON, subaccountData string, keyHex string) string {
func SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJSON, subaccountData string, keyHex string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
var settings accounts.Settings
err = json.Unmarshal([]byte(settingsJSON), &settings)
if err != nil {
return makeJSONResponse(err)
}
var conf params.NodeConfig
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
Expand All @@ -394,7 +404,7 @@ func SaveAccountAndLoginWithKeycard(accountData, password, configJSON, subaccoun
}
api.RunAsync(func() error {
log.Debug("starting a node, and saving account with configuration", "key-uid", account.KeyUID)
err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, &conf, subaccs, keyHex)
err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, settings, &conf, subaccs, keyHex)
if err != nil {
log.Error("failed to start node and save account", "key-uid", account.KeyUID, "error", err)
return err
Expand Down
82 changes: 47 additions & 35 deletions multiaccounts/accounts/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,52 @@ type Account struct {
}

type Settings struct {
// required
Address common.Address `json:"address"`
ChaosMode *bool `json:"chaos-mode,omitempty"`
Currency *string `json:currency,omitempty`
CustomBootnodes *json.RawMessage `json:custom-boot-nodes,omitempty`
CustomBootnodesEnabled *json.RawMessage `json:custom-boot-nodes-enabled,omitempty`
DappsAddress common.Address `json:dapps-address`
EIP1581Address common.Address `json:eip1581-address`
Fleet *string `json:fleet,omitempty`
HideHomeTooltip *bool `json:hide-home-tooltip,omitempty`
InstallationID string `json:installation-id`
KeyUID string `json:key-uid`
KeycardInstanceUID *string `json:keycard-instance-uid,omitempty`
KeycardPAiredOn *time.Time `json:keycard-paired-on,omitempty`
KeycardPairing *string `json:keycard-pairing,omitempty`
LatestDerivedPath uint `json:last-derived-path`
LogLevel *string `json:log-level,omitempty`
Mnemonic *string `json:mnemonic,omitempty`
Name string `json:name,omitempty`
NotificationsEnabled *bool `json:notification-enabled,omitempty`
PhotoPath string `json:photo-path`
PinnedMailserver *json.RawMessage `json:pinned-mailserver,omitempty`
PreferredName *string `json:preferred-name,omitempty`
PreviewPrivacy bool `json:preview-privacy`
PublicKey string `json:public-key`
RememberSyncingChoice *bool `json:remember-syncing-choice,omitempty`
ShowName *bool `json:show-name,omitempty`
SigningPhrase string `json:signing-phrase`
StickerPacksInstalled *json.RawMessage `json:stickers-packs-installed,omitempty`
StickersRecentStickers *json.RawMessage `json:stickers-recent-stickers,omitempty`
SyncingOnMobileNetwork *bool `json:syncing-on-mobile-network,omitempty`
Usernames *[]string `json:usernames,omitempty`
WalletRootAddress common.Address `json:wallet-root-address,omitempty`
WalletSetupPassed *bool `json:wallet-setup-passed,omitempty`
WalletVisibleTokens *[]string `json:wallet-visible-tokens,omitempty`
ChaosMode bool `json:"chaos-mode,omitempty"`
Currency string `json:"currency,omitempty"`
CustomBootnodes *json.RawMessage `json:"custom-boot-nodes,omitempty"`
CustomBootnodesEnabled *json.RawMessage `json:"custom-boot-nodes-enabled,omitempty"`
// required
DappsAddress common.Address `json:"dapps-address"`
// required
EIP1581Address common.Address `json:"eip1581-address"`
Fleet string `json:"fleet,omitempty"`
HideHomeTooltip bool `json:"hide-home-tooltip,omitempty"`
// required
InstallationID string `json:"installation-id"`
// required
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn time.Time `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
// required
LatestDerivedPath uint `json:"last-derived-path"`
LogLevel string `json:"log-level,omitempty"`
Mnemonic string `json:"mnemonic,omitempty"`
// required
Name string `json:"name,omitempty"`
NotificationsEnabled bool `json:"notification-enabled,omitempty"`
// required
PhotoPath string `json:"photo-path"`
PinnedMailserver *json.RawMessage `json:"pinned-mailserver,omitempty"`
PreferredName string `json:"preferred-name,omitempty"`
// required
PreviewPrivacy bool `json:"preview-privacy"`
// required
PublicKey string `json:"public-key"`
RememberSyncingChoice bool `json:"remember-syncing-choice,omitempty"`
ShowName bool `json:"show-name,omitempty"`
// required
SigningPhrase string `json:"signing-phrase"`
StickerPacksInstalled *json.RawMessage `json:"stickers-packs-installed,omitempty"`
StickersRecentStickers *json.RawMessage `json:"stickers-recent-stickers,omitempty"`
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network,omitempty"`
Usernames []string `json:"usernames,omitempty"`
// required
WalletRootAddress common.Address `json:"wallet-root-address,omitempty"`
WalletSetupPassed bool `json:"wallet-setup-passed,omitempty"`
WalletVisibleTokens []string `json:"wallet-visible-tokens,omitempty"`
}

func NewDB(db *sql.DB) *Database {
Expand All @@ -124,7 +136,7 @@ func (db Database) Close() error {
return db.db.Close()
}

func (db *Database) CreateSettings(s Settings, NodeConfig params.NodeConfig) error {
func (db *Database) CreateSettings(s Settings, NodeConfig *params.NodeConfig) error {
_, err := db.db.Exec(`
INSERT INTO settings (
address,
Expand Down Expand Up @@ -160,7 +172,7 @@ INSERT INTO settings (
s.LatestDerivedPath,
s.Mnemonic,
s.Name,
NodeConfig,
&NodeConfig,
s.PhotoPath,
s.PreviewPrivacy,
s.PublicKey,
Expand Down
51 changes: 16 additions & 35 deletions multiaccounts/accounts/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ package accounts

import (
"database/sql"
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/params"
"github.com/stretchr/testify/require"
)

var (
addr = common.Address{1}
settings = &accounts.Settings{
Address: common.Address{0xdC540f3745Ff2964AFC1171a5A0DD726d1F6B472},
DappsAddress: common.Address{0xD1300f99fDF7346986CbC766903245087394ecd0},
EIP1581Address: common.Address{0xB1DDDE9235a541d1344550d969715CF43982de9f},
config = params.NodeConfig{}
settings = Settings{
Address: common.HexToAddress("0xdC540f3745Ff2964AFC1171a5A0DD726d1F6B472"),
DappsAddress: common.HexToAddress("0xD1300f99fDF7346986CbC766903245087394ecd0"),
EIP1581Address: common.HexToAddress("0xB1DDDE9235a541d1344550d969715CF43982de9f"),
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
KeyUID: "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab",
LatestDerivedPath: 0,
Mnemonic: "danger ritual muscle point announce vocal foster during tree keep blade pledge",
Name: "Jittery Cornflowerblue Kingbird",
PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==",
PreviewPrivacy: false,
PublicKey: "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0",
SigningPhrase: "yurt joey vibe",
WalletRootAddress: common.Address{0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6}}
WalletRootAddress: common.HexToAddress("0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")}
)

func setupTestDB(t *testing.T) (*Database, func()) {
Expand All @@ -47,52 +47,33 @@ func TestCreateSettings(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.CreateSettings(settings))
require.NoError(t, db.CreateSettings(settings, &config))

var rst string
require.NoError(t, db.GetSetting("currency", &rst))
require.Equal(t, "USD", rst)
_, err := db.GetSettings()
require.NoError(t, err)
}

func TestSaveSetting(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.SaveSetting("name", "Some Name"))
require.NoError(t, db.SaveSetting("currency", "USD"))

var rst string
require.NoError(t, db.GetSetting("currency", &rst))
require.Equal(t, "USD", rst)
}

func TestGetNodeConfig(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.SaveSettings(settings))
require.NoError(t, db.CreateSettings(settings, &config))
require.NoError(t, db.SaveSetting("currency", "usd"))

expected, err := json.Marshal(settings["photo_path"])
require.NoError(t, err)
rst, err := db.GetSettings()
_, err := db.GetSettings()
require.NoError(t, err)
require.Equal(t, json.RawMessage(expected), rst)
}

func TestGetSettings(t *testing.T) {
func TestGetNodeConfig(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.SaveSettings(cfg))
require.NoError(t, db.CreateSettings(settings, &config))

expected, err := json.Marshal(cfg["photo_path"])
require.NoError(t, err)
rst, err := db.GetSettings()
_, err := db.GetSettings()
require.NoError(t, err)
require.Equal(t, json.RawMessage(expected), rst)
}


func TestSaveAccounts(t *testing.T) {
type testCase struct {
description string
Expand Down
3 changes: 2 additions & 1 deletion t/devtests/devnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *DevNodeSuite) SetupTest() {
s.dir,
1337,
)
settings := accounts.Settings{}
s.Require().NoError(err)
config.WhisperConfig.Enabled = false
config.LightEthConfig.Enabled = false
Expand All @@ -69,7 +70,7 @@ func (s *DevNodeSuite) SetupTest() {
s.Require().NoError(s.backend.StartNodeWithAccountAndConfig(multiaccounts.Account{
Name: "main",
KeyUID: keyUID,
}, "test", config, []accounts.Account{{Address: s.DevAccountAddress, Wallet: true, Chat: true}}))
}, "test", settings, config, []accounts.Account{{Address: s.DevAccountAddress, Wallet: true, Chat: true}}))
s.Remote, err = s.miner.Attach()
s.Require().NoError(err)
s.Eth = ethclient.NewClient(s.Remote)
Expand Down

0 comments on commit c1facdf

Please sign in to comment.