-
Notifications
You must be signed in to change notification settings - Fork 244
/
test_helpers.go
101 lines (81 loc) · 2.91 KB
/
test_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package api
import (
"encoding/json"
"path/filepath"
"testing"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/params"
"github.com/stretchr/testify/require"
)
func setupWalletTest(t *testing.T, password string) (backend *GethStatusBackend, defersFunc func(), err error) {
tmpdir := t.TempDir()
defers := make([]func(), 0)
defersFunc = func() {
for _, f := range defers {
f()
}
}
if err != nil {
return
}
backend = NewGethStatusBackend()
backend.UpdateRootDataDir(tmpdir)
err = backend.AccountManager().InitKeystore(filepath.Join(tmpdir, "keystore"))
if err != nil {
return
}
// Create master account
const pathWalletRoot = "m/44'/60'/0'/0"
accs, err := backend.AccountManager().
AccountsGenerator().
GenerateAndDeriveAddresses(12, 1, "", []string{pathWalletRoot})
if err != nil {
return
}
masterAccInfo := accs[0]
_, err = backend.AccountManager().AccountsGenerator().StoreDerivedAccounts(masterAccInfo.ID, password, []string{pathWalletRoot})
if err != nil {
return
}
account := multiaccounts.Account{
Name: "foo",
Timestamp: 1,
KeycardPairing: "pairing",
KeyUID: masterAccInfo.KeyUID,
}
err = backend.ensureAppDBOpened(account, password)
require.NoError(t, err)
walletRootAddress := masterAccInfo.Derived[pathWalletRoot].Address
config, err := params.NewNodeConfig(tmpdir, 178733)
require.NoError(t, err)
networks := json.RawMessage("{}")
s := settings.Settings{
Address: types.HexToAddress(walletRootAddress),
DisplayName: "UserDisplayName",
CurrentNetwork: "mainnet_rpc",
DappsAddress: types.HexToAddress(walletRootAddress),
EIP1581Address: types.HexToAddress(walletRootAddress),
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
KeyUID: account.KeyUID,
LatestDerivedPath: 0,
Name: "Jittery Cornflowerblue Kingbird",
Networks: &networks,
PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==",
PreviewPrivacy: false,
PublicKey: masterAccInfo.PublicKey,
SigningPhrase: "yurt joey vibe",
WalletRootAddress: types.HexToAddress(walletRootAddress)}
err = backend.saveAccountsAndSettings(s, config, nil)
require.Error(t, err)
require.True(t, err == accounts.ErrKeypairWithoutAccounts)
// this is for StatusNode().Config() call inside of the getVerifiedWalletAccount
err = backend.StartNode(config)
require.NoError(t, err)
defers = append(defers, func() {
require.NoError(t, backend.StopNode())
})
return
}