2022-07-06 16:12:49 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
2023-05-16 10:50:04 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-07-06 16:12:49 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
|
|
|
"github.com/status-im/status-go/params"
|
2024-07-04 10:48:40 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2024-10-28 20:54:17 +00:00
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
2022-07-06 16:12:49 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setupWalletTest(t *testing.T, password string) (backend *GethStatusBackend, defersFunc func(), err error) {
|
2023-04-26 20:39:51 +00:00
|
|
|
tmpdir := t.TempDir()
|
2022-07-06 16:12:49 +00:00
|
|
|
|
|
|
|
defers := make([]func(), 0)
|
|
|
|
defersFunc = func() {
|
|
|
|
for _, f := range defers {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-10-28 20:54:17 +00:00
|
|
|
backend = NewGethStatusBackend(tt.MustCreateTestLogger())
|
2022-07-06 16:12:49 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2023-08-11 11:25:14 +00:00
|
|
|
err = backend.ensureDBsOpened(account, password)
|
2022-07-06 16:12:49 +00:00
|
|
|
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),
|
2023-03-27 14:33:00 +00:00
|
|
|
DisplayName: "UserDisplayName",
|
2022-07-06 16:12:49 +00:00
|
|
|
CurrentNetwork: "mainnet_rpc",
|
|
|
|
DappsAddress: types.HexToAddress(walletRootAddress),
|
|
|
|
EIP1581Address: types.HexToAddress(walletRootAddress),
|
|
|
|
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
|
|
|
|
KeyUID: account.KeyUID,
|
2023-05-08 15:14:46 +00:00
|
|
|
LatestDerivedPath: 0,
|
2022-07-06 16:12:49 +00:00
|
|
|
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)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.True(t, err == accounts.ErrKeypairWithoutAccounts)
|
2022-07-06 16:12:49 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2024-07-04 10:48:40 +00:00
|
|
|
|
|
|
|
// Only for tests
|
|
|
|
func overrideApiConfigTest(nodeConfig *params.NodeConfig, config *requests.APIConfig) {
|
|
|
|
overrideApiConfigProd(nodeConfig, config)
|
|
|
|
nodeConfig.HTTPVirtualHosts = config.HTTPVirtualHosts
|
|
|
|
}
|
|
|
|
|
|
|
|
func OverrideApiConfigTest() {
|
|
|
|
overrideApiConfig = overrideApiConfigTest
|
|
|
|
}
|