2018-04-20 15:39:53 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2024-02-27 07:58:12 +00:00
|
|
|
"context"
|
2019-12-05 08:00:57 +00:00
|
|
|
"crypto/sha256"
|
2023-03-27 14:33:00 +00:00
|
|
|
"database/sql"
|
2019-01-24 15:44:46 +00:00
|
|
|
"encoding/hex"
|
2019-03-28 14:56:21 +00:00
|
|
|
"encoding/json"
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
"errors"
|
2018-04-20 15:39:53 +00:00
|
|
|
"fmt"
|
2019-08-29 08:06:22 +00:00
|
|
|
"io/ioutil"
|
2018-04-20 15:39:53 +00:00
|
|
|
"math/rand"
|
2019-08-29 08:06:22 +00:00
|
|
|
"os"
|
2022-05-04 14:46:49 +00:00
|
|
|
"path"
|
2019-08-29 08:06:22 +00:00
|
|
|
"path/filepath"
|
2022-11-08 13:30:33 +00:00
|
|
|
"strings"
|
2018-04-20 15:39:53 +00:00
|
|
|
"sync"
|
|
|
|
"testing"
|
2023-09-27 17:26:10 +00:00
|
|
|
"time"
|
2018-04-20 15:39:53 +00:00
|
|
|
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
|
|
|
|
2020-01-02 09:10:19 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-11 13:59:37 +00:00
|
|
|
gethcrypto "github.com/ethereum/go-ethereum/crypto"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2023-03-27 14:33:00 +00:00
|
|
|
"github.com/status-im/status-go/appdatabase"
|
2021-05-14 10:55:42 +00:00
|
|
|
"github.com/status-im/status-go/connection"
|
2019-12-11 13:59:37 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-08-29 08:06:22 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-03-23 18:47:00 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/node"
|
|
|
|
"github.com/status-im/status-go/params"
|
2023-08-02 07:39:58 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2018-08-02 07:07:55 +00:00
|
|
|
"github.com/status-im/status-go/rpc"
|
2019-03-28 14:56:21 +00:00
|
|
|
"github.com/status-im/status-go/services/typeddata"
|
2024-06-26 11:14:27 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet"
|
2024-02-27 07:58:12 +00:00
|
|
|
walletservice "github.com/status-im/status-go/services/wallet"
|
2023-09-27 17:26:10 +00:00
|
|
|
"github.com/status-im/status-go/signal"
|
2023-08-10 11:41:04 +00:00
|
|
|
"github.com/status-im/status-go/sqlite"
|
2023-08-11 11:28:45 +00:00
|
|
|
"github.com/status-im/status-go/t/helpers"
|
2018-09-13 16:31:29 +00:00
|
|
|
"github.com/status-im/status-go/t/utils"
|
2019-08-29 08:06:22 +00:00
|
|
|
"github.com/status-im/status-go/transactions"
|
2023-08-11 11:28:45 +00:00
|
|
|
"github.com/status-im/status-go/walletdatabase"
|
2018-04-20 15:39:53 +00:00
|
|
|
)
|
|
|
|
|
2019-12-27 09:58:25 +00:00
|
|
|
var (
|
2022-03-23 18:47:00 +00:00
|
|
|
networks = json.RawMessage("{}")
|
|
|
|
testSettings = settings.Settings{
|
2019-12-27 09:58:25 +00:00
|
|
|
Address: types.HexToAddress("0xeC540f3745Ff2964AFC1171a5A0DD726d1F6B472"),
|
2023-03-27 14:33:00 +00:00
|
|
|
DisplayName: "UserDisplayName",
|
2019-12-27 09:58:25 +00:00
|
|
|
CurrentNetwork: "mainnet_rpc",
|
|
|
|
DappsAddress: types.HexToAddress("0xe1300f99fDF7346986CbC766903245087394ecd0"),
|
|
|
|
EIP1581Address: types.HexToAddress("0xe1DDDE9235a541d1344550d969715CF43982de9f"),
|
|
|
|
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
|
|
|
|
KeyUID: "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab",
|
2023-05-08 15:14:46 +00:00
|
|
|
LatestDerivedPath: 0,
|
2019-12-27 09:58:25 +00:00
|
|
|
Name: "Jittery Cornflowerblue Kingbird",
|
|
|
|
Networks: &networks,
|
|
|
|
PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==",
|
|
|
|
PreviewPrivacy: false,
|
|
|
|
PublicKey: "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0",
|
|
|
|
SigningPhrase: "yurt joey vibe",
|
|
|
|
WalletRootAddress: types.HexToAddress("0xeB591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")}
|
|
|
|
)
|
|
|
|
|
2023-03-27 14:33:00 +00:00
|
|
|
func setupTestDB() (*sql.DB, func() error, error) {
|
2023-08-11 11:28:45 +00:00
|
|
|
return helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "tests")
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupTestWalletDB() (*sql.DB, func() error, error) {
|
|
|
|
return helpers.SetupTestSQLDB(walletdatabase.DbInitializer{}, "tests")
|
2023-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
|
|
|
|
tmpfile, err := ioutil.TempFile("", "tests")
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
db, err := multiaccounts.InitializeDB(tmpfile.Name())
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
return db, func() error {
|
|
|
|
err := db.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return os.Remove(tmpfile.Name())
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
func setupGethStatusBackend() (*GethStatusBackend, func() error, func() error, func() error, error) {
|
2023-03-27 14:33:00 +00:00
|
|
|
db, stop1, err := setupTestDB()
|
|
|
|
if err != nil {
|
2023-08-11 11:28:45 +00:00
|
|
|
return nil, nil, nil, nil, err
|
2023-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
backend := NewGethStatusBackend()
|
|
|
|
backend.StatusNode().SetAppDB(db)
|
|
|
|
|
|
|
|
ma, stop2, err := setupTestMultiDB()
|
2023-08-11 11:28:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, err
|
|
|
|
}
|
2023-03-27 14:33:00 +00:00
|
|
|
backend.StatusNode().SetMultiaccountsDB(ma)
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
walletDb, stop3, err := setupTestWalletDB()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, nil, err
|
|
|
|
}
|
|
|
|
backend.StatusNode().SetWalletDB(walletDb)
|
|
|
|
|
|
|
|
return backend, stop1, stop2, stop3, err
|
2023-03-27 14:33:00 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 15:39:53 +00:00
|
|
|
func TestBackendStartNodeConcurrently(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stop3, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop3()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
2018-04-20 15:39:53 +00:00
|
|
|
count := 2
|
|
|
|
resultCh := make(chan error)
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(count)
|
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
go func() {
|
2018-09-13 16:31:29 +00:00
|
|
|
resultCh <- backend.StartNode(config)
|
2018-04-20 15:39:53 +00:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// close channel as otherwise for loop never finishes
|
|
|
|
go func() { wg.Wait(); close(resultCh) }()
|
|
|
|
|
|
|
|
var results []error
|
|
|
|
for err := range resultCh {
|
|
|
|
results = append(results, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Contains(t, results, nil)
|
|
|
|
require.Contains(t, results, node.ErrNodeRunning)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
err = backend.StopNode()
|
2018-04-20 15:39:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackendRestartNodeConcurrently(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2018-04-20 15:39:53 +00:00
|
|
|
count := 3
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
|
|
|
require.NoError(t, backend.StartNode(config))
|
2018-04-20 15:39:53 +00:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}()
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(count)
|
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
go func(idx int) {
|
|
|
|
assert.NoError(t, backend.RestartNode())
|
|
|
|
wg.Done()
|
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(adam): add concurrent tests for ResetChainData()
|
|
|
|
|
|
|
|
func TestBackendGettersConcurrently(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
2018-09-13 16:31:29 +00:00
|
|
|
err = backend.StartNode(config)
|
2018-04-20 15:39:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}()
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
assert.NotNil(t, backend.StatusNode())
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
assert.NotNil(t, backend.AccountManager())
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2018-06-27 08:11:45 +00:00
|
|
|
assert.NotNil(t, backend.personalAPI)
|
2018-04-20 15:39:53 +00:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
assert.NotNil(t, backend.Transactor())
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
assert.True(t, backend.IsNodeRunning())
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
assert.True(t, backend.IsNodeRunning())
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackendConnectionChangesConcurrently(t *testing.T) {
|
2021-05-14 10:55:42 +00:00
|
|
|
connections := [...]string{connection.Wifi, connection.Cellular, connection.Unknown}
|
2019-11-23 17:57:05 +00:00
|
|
|
backend := NewGethStatusBackend()
|
2018-04-20 15:39:53 +00:00
|
|
|
count := 3
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
2020-12-28 09:09:45 +00:00
|
|
|
connIdx := rand.Intn(len(connections)) // nolint: gosec
|
2018-04-23 13:34:49 +00:00
|
|
|
backend.ConnectionChange(connections[connIdx], false)
|
2018-04-20 15:39:53 +00:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
2018-06-27 08:11:45 +00:00
|
|
|
func TestBackendConnectionChangesToOffline(t *testing.T) {
|
2019-11-23 17:57:05 +00:00
|
|
|
b := NewGethStatusBackend()
|
2021-05-14 10:55:42 +00:00
|
|
|
b.ConnectionChange(connection.None, false)
|
2018-06-27 08:11:45 +00:00
|
|
|
assert.True(t, b.connectionState.Offline)
|
|
|
|
|
2021-05-14 10:55:42 +00:00
|
|
|
b.ConnectionChange(connection.Wifi, false)
|
2018-06-27 08:11:45 +00:00
|
|
|
assert.False(t, b.connectionState.Offline)
|
|
|
|
|
|
|
|
b.ConnectionChange("unknown-state", false)
|
|
|
|
assert.False(t, b.connectionState.Offline)
|
|
|
|
}
|
|
|
|
|
2018-04-20 15:39:53 +00:00
|
|
|
func TestBackendCallRPCConcurrently(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
2018-04-20 15:39:53 +00:00
|
|
|
count := 3
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
err = backend.StartNode(config)
|
2018-04-20 15:39:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}()
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(idx int) {
|
2018-12-20 08:31:17 +00:00
|
|
|
result, err := backend.CallRPC(fmt.Sprintf(
|
2018-04-20 15:39:53 +00:00
|
|
|
`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":%d}`,
|
|
|
|
idx+1,
|
|
|
|
))
|
2018-12-20 08:31:17 +00:00
|
|
|
assert.NoError(t, err)
|
2018-04-20 15:39:53 +00:00
|
|
|
assert.NotContains(t, result, "error")
|
|
|
|
wg.Done()
|
|
|
|
}(i)
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func(idx int) {
|
2018-12-20 08:31:17 +00:00
|
|
|
result, err := backend.CallPrivateRPC(fmt.Sprintf(
|
2018-04-20 15:39:53 +00:00
|
|
|
`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":%d}`,
|
|
|
|
idx+1,
|
|
|
|
))
|
2018-12-20 08:31:17 +00:00
|
|
|
assert.NoError(t, err)
|
2018-04-20 15:39:53 +00:00
|
|
|
assert.NotContains(t, result, "error")
|
|
|
|
wg.Done()
|
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
2018-06-27 08:11:45 +00:00
|
|
|
func TestAppStateChange(t *testing.T) {
|
2019-11-23 17:57:05 +00:00
|
|
|
backend := NewGethStatusBackend()
|
2018-06-27 08:11:45 +00:00
|
|
|
|
|
|
|
var testCases = []struct {
|
|
|
|
name string
|
|
|
|
fromState appState
|
|
|
|
toState appState
|
|
|
|
expectedState appState
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "success",
|
|
|
|
fromState: appStateInactive,
|
|
|
|
toState: appStateBackground,
|
|
|
|
expectedState: appStateBackground,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid state",
|
|
|
|
fromState: appStateInactive,
|
|
|
|
toState: "unexisting",
|
|
|
|
expectedState: appStateInactive,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
backend.appState = tc.fromState
|
|
|
|
backend.AppStateChange(tc.toState.String())
|
|
|
|
assert.Equal(t, tc.expectedState.String(), backend.appState.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 07:07:55 +00:00
|
|
|
func TestBlockedRPCMethods(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
2018-09-13 16:31:29 +00:00
|
|
|
err = backend.StartNode(config)
|
2018-08-02 07:07:55 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() { require.NoError(t, backend.StopNode()) }()
|
|
|
|
|
|
|
|
for idx, m := range rpc.BlockedMethods() {
|
2018-12-20 08:31:17 +00:00
|
|
|
result, err := backend.CallRPC(fmt.Sprintf(
|
2018-08-02 07:07:55 +00:00
|
|
|
`{"jsonrpc":"2.0","method":"%s","params":[],"id":%d}`,
|
|
|
|
m,
|
|
|
|
idx+1,
|
|
|
|
))
|
2018-12-20 08:31:17 +00:00
|
|
|
assert.NoError(t, err)
|
2018-08-02 07:07:55 +00:00
|
|
|
assert.Contains(t, result, fmt.Sprintf(`{"code":-32700,"message":"%s"}`, rpc.ErrMethodNotFound))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 08:31:17 +00:00
|
|
|
func TestCallRPCWithStoppedNode(t *testing.T) {
|
2019-11-23 17:57:05 +00:00
|
|
|
backend := NewGethStatusBackend()
|
2018-12-20 08:31:17 +00:00
|
|
|
|
|
|
|
resp, err := backend.CallRPC(
|
|
|
|
`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}`,
|
|
|
|
)
|
|
|
|
assert.Equal(t, ErrRPCClientUnavailable, err)
|
|
|
|
assert.Equal(t, "", resp)
|
|
|
|
|
|
|
|
resp, err = backend.CallPrivateRPC(
|
|
|
|
`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}`,
|
|
|
|
)
|
|
|
|
assert.Equal(t, ErrRPCClientUnavailable, err)
|
|
|
|
assert.Equal(t, "", resp)
|
|
|
|
}
|
|
|
|
|
2018-08-16 11:37:53 +00:00
|
|
|
// TODO(adam): add concurrent tests for: SendTransaction
|
2019-01-17 11:02:45 +00:00
|
|
|
|
|
|
|
func TestStartStopMultipleTimes(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-01-17 11:02:45 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
2019-01-17 11:02:45 +00:00
|
|
|
config.NoDiscovery = false
|
|
|
|
// doesn't have to be running. just any valid enode to bypass validation.
|
|
|
|
config.ClusterConfig.BootNodes = []string{
|
|
|
|
"enode://e8a7c03b58911e98bbd66accb2a55d57683f35b23bf9dfca89e5e244eb5cc3f25018b4112db507faca34fb69ffb44b362f79eda97a669a8df29c72e654416784@0.0.0.0:30404",
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, backend.StartNode(config))
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
require.NoError(t, backend.StartNode(config))
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
2019-03-28 14:56:21 +00:00
|
|
|
|
|
|
|
func TestHashTypedData(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-03-28 14:56:21 +00:00
|
|
|
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
|
|
|
|
require.NoError(t, err)
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(config.KeyStoreDir))
|
2019-03-28 14:56:21 +00:00
|
|
|
err = backend.StartNode(config)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}()
|
|
|
|
|
|
|
|
eip712Domain := "EIP712Domain"
|
|
|
|
mytypes := typeddata.Types{
|
|
|
|
eip712Domain: []typeddata.Field{
|
|
|
|
{Name: "name", Type: "string"},
|
|
|
|
{Name: "version", Type: "string"},
|
|
|
|
{Name: "chainId", Type: "uint256"},
|
|
|
|
{Name: "verifyingContract", Type: "address"},
|
|
|
|
},
|
|
|
|
"Text": []typeddata.Field{
|
|
|
|
{Name: "body", Type: "string"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
domain := map[string]json.RawMessage{
|
|
|
|
"name": json.RawMessage(`"Ether Text"`),
|
|
|
|
"version": json.RawMessage(`"1"`),
|
|
|
|
"chainId": json.RawMessage(fmt.Sprintf("%d", params.StatusChainNetworkID)),
|
|
|
|
"verifyingContract": json.RawMessage(`"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"`),
|
|
|
|
}
|
|
|
|
msg := map[string]json.RawMessage{
|
|
|
|
"body": json.RawMessage(`"Hello, Bob!"`),
|
|
|
|
}
|
|
|
|
|
|
|
|
typed := typeddata.TypedData{
|
|
|
|
Types: mytypes,
|
|
|
|
PrimaryType: "Text",
|
|
|
|
Domain: domain,
|
|
|
|
Message: msg,
|
|
|
|
}
|
|
|
|
|
|
|
|
hash, err := backend.HashTypedData(typed)
|
|
|
|
require.NoError(t, err)
|
2019-11-23 17:57:05 +00:00
|
|
|
assert.NotEqual(t, types.Hash{}, hash)
|
2019-03-28 14:56:21 +00:00
|
|
|
}
|
2019-08-29 08:06:22 +00:00
|
|
|
|
|
|
|
func TestBackendGetVerifiedAccount(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2019-08-29 08:06:22 +00:00
|
|
|
password := "test"
|
2022-07-06 16:12:49 +00:00
|
|
|
backend, defers, err := setupWalletTest(t, password)
|
2019-08-29 08:06:22 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 16:12:49 +00:00
|
|
|
defer defers()
|
2019-08-29 08:06:22 +00:00
|
|
|
|
|
|
|
t.Run("AccountDoesntExist", func(t *testing.T) {
|
2019-12-11 13:59:37 +00:00
|
|
|
pkey, err := gethcrypto.GenerateKey()
|
2019-08-29 08:06:22 +00:00
|
|
|
require.NoError(t, err)
|
2019-12-11 13:59:37 +00:00
|
|
|
address := gethcrypto.PubkeyToAddress(pkey.PublicKey)
|
2019-08-29 08:06:22 +00:00
|
|
|
key, err := backend.getVerifiedWalletAccount(address.String(), password)
|
|
|
|
require.EqualError(t, err, transactions.ErrAccountDoesntExist.Error())
|
|
|
|
require.Nil(t, key)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("PasswordDoesntMatch", func(t *testing.T) {
|
|
|
|
pkey, err := crypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
address := crypto.PubkeyToAddress(pkey.PublicKey)
|
2023-05-16 10:50:04 +00:00
|
|
|
keyUIDHex := sha256.Sum256(gethcrypto.FromECDSAPub(&pkey.PublicKey))
|
|
|
|
keyUID := types.EncodeHex(keyUIDHex[:])
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
db, err := accounts.NewDB(backend.appDB)
|
2022-07-06 16:12:49 +00:00
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
require.NoError(t, err)
|
2019-11-23 17:57:05 +00:00
|
|
|
_, err = backend.AccountManager().ImportAccount(pkey, password)
|
2019-08-29 08:06:22 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.NoError(t, db.SaveOrUpdateKeypair(&accounts.Keypair{
|
|
|
|
KeyUID: keyUID,
|
|
|
|
Name: "private key keypair",
|
|
|
|
Type: accounts.KeypairTypeKey,
|
|
|
|
Accounts: []*accounts.Account{
|
|
|
|
&accounts.Account{
|
|
|
|
Address: address,
|
|
|
|
KeyUID: keyUID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
2019-08-29 08:06:22 +00:00
|
|
|
key, err := backend.getVerifiedWalletAccount(address.String(), "wrong-password")
|
2019-10-04 15:21:24 +00:00
|
|
|
require.EqualError(t, err, "could not decrypt key with given password")
|
2019-08-29 08:06:22 +00:00
|
|
|
require.Nil(t, key)
|
|
|
|
})
|
|
|
|
|
2022-07-06 16:12:49 +00:00
|
|
|
t.Run("PartialAccount", func(t *testing.T) {
|
|
|
|
// Create a derived wallet account without storing the keys
|
|
|
|
db, err := accounts.NewDB(backend.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
newPath := "m/0"
|
|
|
|
walletRootAddress, err := db.GetWalletRootAddress()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
walletInfo, err := backend.AccountManager().AccountsGenerator().LoadAccount(walletRootAddress.String(), password)
|
|
|
|
require.NoError(t, err)
|
|
|
|
derivedInfos, err := backend.AccountManager().AccountsGenerator().DeriveAddresses(walletInfo.ID, []string{newPath})
|
|
|
|
require.NoError(t, err)
|
|
|
|
derivedInfo := derivedInfos[newPath]
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
keypair := &accounts.Keypair{
|
|
|
|
KeyUID: walletInfo.KeyUID,
|
|
|
|
Name: "profile keypair",
|
|
|
|
Type: accounts.KeypairTypeProfile,
|
|
|
|
Accounts: []*accounts.Account{
|
|
|
|
&accounts.Account{
|
|
|
|
Address: types.HexToAddress(derivedInfo.Address),
|
|
|
|
KeyUID: walletInfo.KeyUID,
|
|
|
|
Type: accounts.AccountTypeGenerated,
|
|
|
|
PublicKey: types.Hex2Bytes(derivedInfo.PublicKey),
|
|
|
|
Path: newPath,
|
|
|
|
Wallet: false,
|
|
|
|
Name: "PartialAccount",
|
|
|
|
},
|
|
|
|
},
|
2022-07-06 16:12:49 +00:00
|
|
|
}
|
2023-05-16 10:50:04 +00:00
|
|
|
require.NoError(t, db.SaveOrUpdateKeypair(keypair))
|
2022-07-06 16:12:49 +00:00
|
|
|
|
|
|
|
// With partial account we need to dynamically generate private key
|
2023-05-16 10:50:04 +00:00
|
|
|
key, err := backend.getVerifiedWalletAccount(keypair.Accounts[0].Address.Hex(), password)
|
2022-07-06 16:12:49 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.Equal(t, keypair.Accounts[0].Address, key.Address)
|
2022-07-06 16:12:49 +00:00
|
|
|
})
|
|
|
|
|
2019-08-29 08:06:22 +00:00
|
|
|
t.Run("Success", func(t *testing.T) {
|
|
|
|
pkey, err := crypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
address := crypto.PubkeyToAddress(pkey.PublicKey)
|
2023-05-16 10:50:04 +00:00
|
|
|
keyUIDHex := sha256.Sum256(gethcrypto.FromECDSAPub(&pkey.PublicKey))
|
|
|
|
keyUID := types.EncodeHex(keyUIDHex[:])
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
db, err := accounts.NewDB(backend.appDB)
|
|
|
|
require.NoError(t, err)
|
2022-07-06 16:12:49 +00:00
|
|
|
defer db.Close()
|
2019-11-23 17:57:05 +00:00
|
|
|
_, err = backend.AccountManager().ImportAccount(pkey, password)
|
2019-08-29 08:06:22 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.NoError(t, db.SaveOrUpdateKeypair(&accounts.Keypair{
|
|
|
|
KeyUID: keyUID,
|
|
|
|
Name: "private key keypair",
|
|
|
|
Type: accounts.KeypairTypeKey,
|
|
|
|
Accounts: []*accounts.Account{
|
|
|
|
&accounts.Account{
|
|
|
|
Address: address,
|
|
|
|
KeyUID: keyUID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
2019-08-29 08:06:22 +00:00
|
|
|
key, err := backend.getVerifiedWalletAccount(address.String(), password)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, address, key.Address)
|
|
|
|
})
|
|
|
|
}
|
2019-09-02 19:03:15 +00:00
|
|
|
|
2024-02-02 21:08:48 +00:00
|
|
|
func TestRuntimeLogLevelIsNotWrittenToDatabase(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
chatKey, err := gethcrypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
walletKey, err := gethcrypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
keyUIDHex := sha256.Sum256(gethcrypto.FromECDSAPub(&chatKey.PublicKey))
|
|
|
|
keyUID := types.EncodeHex(keyUIDHex[:])
|
|
|
|
main := multiaccounts.Account{
|
|
|
|
KeyUID: keyUID,
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
json := `{
|
|
|
|
"NetworkId": 3,
|
|
|
|
"DataDir": "` + tmpdir + `",
|
|
|
|
"KeyStoreDir": "` + tmpdir + `",
|
|
|
|
"KeycardPairingDataFile": "` + path.Join(tmpdir, "keycard/pairings.json") + `",
|
|
|
|
"NoDiscovery": true,
|
|
|
|
"TorrentConfig": {
|
|
|
|
"Port": 9025,
|
|
|
|
"Enabled": false,
|
|
|
|
"DataDir": "` + tmpdir + `/archivedata",
|
|
|
|
"TorrentDir": "` + tmpdir + `/torrents"
|
|
|
|
},
|
|
|
|
"RuntimeLogLevel": "INFO",
|
|
|
|
"LogLevel": "DEBUG"
|
|
|
|
}`
|
|
|
|
|
|
|
|
conf, err := params.NewConfigFromJSON(json)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "INFO", conf.RuntimeLogLevel)
|
|
|
|
keyhex := hex.EncodeToString(gethcrypto.FromECDSA(chatKey))
|
|
|
|
|
|
|
|
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
|
|
|
|
b.UpdateRootDataDir(conf.DataDir)
|
|
|
|
require.NoError(t, b.OpenAccounts())
|
|
|
|
require.NotNil(t, b.statusNode.HTTPServer())
|
|
|
|
|
|
|
|
address := crypto.PubkeyToAddress(walletKey.PublicKey)
|
|
|
|
|
|
|
|
settings := testSettings
|
|
|
|
settings.KeyUID = keyUID
|
|
|
|
settings.Address = crypto.PubkeyToAddress(walletKey.PublicKey)
|
|
|
|
|
|
|
|
chatPubKey := crypto.FromECDSAPub(&chatKey.PublicKey)
|
|
|
|
require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", settings, conf,
|
|
|
|
[]*accounts.Account{
|
|
|
|
{Address: address, KeyUID: keyUID, Wallet: true},
|
|
|
|
{Address: crypto.PubkeyToAddress(chatKey.PublicKey), KeyUID: keyUID, Chat: true, PublicKey: chatPubKey}}, keyhex))
|
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
require.NoError(t, b.StopNode())
|
|
|
|
|
|
|
|
require.NoError(t, b.StartNodeWithKey(main, "test-pass", keyhex, conf))
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(t, b.Logout())
|
|
|
|
assert.NoError(t, b.StopNode())
|
|
|
|
}()
|
|
|
|
|
|
|
|
c, err := b.GetNodeConfig()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "", c.RuntimeLogLevel)
|
|
|
|
require.Equal(t, "DEBUG", c.LogLevel)
|
|
|
|
}
|
|
|
|
|
2019-09-02 19:03:15 +00:00
|
|
|
func TestLoginWithKey(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
b := NewGethStatusBackend()
|
2019-12-11 13:59:37 +00:00
|
|
|
chatKey, err := gethcrypto.GenerateKey()
|
2019-09-02 19:03:15 +00:00
|
|
|
require.NoError(t, err)
|
2019-12-11 13:59:37 +00:00
|
|
|
walletKey, err := gethcrypto.GenerateKey()
|
2019-12-18 15:09:04 +00:00
|
|
|
require.NoError(t, err)
|
2019-12-11 13:59:37 +00:00
|
|
|
keyUIDHex := sha256.Sum256(gethcrypto.FromECDSAPub(&chatKey.PublicKey))
|
2019-12-05 08:00:57 +00:00
|
|
|
keyUID := types.EncodeHex(keyUIDHex[:])
|
2019-09-02 19:03:15 +00:00
|
|
|
main := multiaccounts.Account{
|
2019-12-05 08:00:57 +00:00
|
|
|
KeyUID: keyUID,
|
2019-09-02 19:03:15 +00:00
|
|
|
}
|
2023-04-26 20:39:51 +00:00
|
|
|
tmpdir := t.TempDir()
|
2019-09-02 19:03:15 +00:00
|
|
|
conf, err := params.NewNodeConfig(tmpdir, 1777)
|
|
|
|
require.NoError(t, err)
|
2019-12-11 13:59:37 +00:00
|
|
|
keyhex := hex.EncodeToString(gethcrypto.FromECDSA(chatKey))
|
2019-09-02 19:03:15 +00:00
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
|
2019-09-02 19:03:15 +00:00
|
|
|
b.UpdateRootDataDir(conf.DataDir)
|
|
|
|
require.NoError(t, b.OpenAccounts())
|
2023-05-18 11:22:20 +00:00
|
|
|
require.NotNil(t, b.statusNode.HTTPServer())
|
2019-09-02 19:03:15 +00:00
|
|
|
|
2019-12-18 15:09:04 +00:00
|
|
|
address := crypto.PubkeyToAddress(walletKey.PublicKey)
|
2023-05-16 10:50:04 +00:00
|
|
|
|
|
|
|
settings := testSettings
|
|
|
|
settings.KeyUID = keyUID
|
|
|
|
settings.Address = crypto.PubkeyToAddress(walletKey.PublicKey)
|
|
|
|
|
2023-06-01 12:57:05 +00:00
|
|
|
chatPubKey := crypto.FromECDSAPub(&chatKey.PublicKey)
|
|
|
|
require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", settings, conf,
|
|
|
|
[]*accounts.Account{
|
|
|
|
{Address: address, KeyUID: keyUID, Wallet: true},
|
|
|
|
{Address: crypto.PubkeyToAddress(chatKey.PublicKey), KeyUID: keyUID, Chat: true, PublicKey: chatPubKey}}, keyhex))
|
2019-09-02 19:03:15 +00:00
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
require.NoError(t, b.StopNode())
|
|
|
|
|
2021-07-12 09:44:26 +00:00
|
|
|
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
|
|
|
|
b.UpdateRootDataDir(conf.DataDir)
|
|
|
|
require.NoError(t, b.OpenAccounts())
|
|
|
|
|
2023-07-20 10:08:57 +00:00
|
|
|
require.NoError(t, b.StartNodeWithKey(main, "test-pass", keyhex, conf))
|
2019-09-02 19:03:15 +00:00
|
|
|
defer func() {
|
|
|
|
assert.NoError(t, b.Logout())
|
|
|
|
assert.NoError(t, b.StopNode())
|
|
|
|
}()
|
|
|
|
extkey, err := b.accountManager.SelectedChatAccount()
|
|
|
|
require.NoError(t, err)
|
2019-12-18 15:09:04 +00:00
|
|
|
require.Equal(t, crypto.PubkeyToAddress(chatKey.PublicKey), extkey.Address)
|
2023-06-01 12:57:05 +00:00
|
|
|
|
|
|
|
activeAccount, err := b.GetActiveAccount()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, activeAccount.ColorHash)
|
2019-09-02 19:03:15 +00:00
|
|
|
}
|
2020-07-13 10:45:36 +00:00
|
|
|
|
2023-09-27 17:26:10 +00:00
|
|
|
func TestLoginAccount(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
password := "some-password"
|
|
|
|
tmpdir := t.TempDir()
|
2024-02-27 16:15:11 +00:00
|
|
|
nameserver := "8.8.8.8"
|
2023-09-27 17:26:10 +00:00
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
createAccountRequest := &requests.CreateAccount{
|
2024-06-05 13:03:34 +00:00
|
|
|
DisplayName: "some-display-name",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: password,
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
|
|
|
WakuV2Nameserver: &nameserver,
|
2024-07-11 09:57:56 +00:00
|
|
|
WakuV2Fleet: "status.staging",
|
2023-09-27 17:26:10 +00:00
|
|
|
}
|
|
|
|
c := make(chan interface{}, 10)
|
|
|
|
signal.SetMobileSignalHandler(func(data []byte) {
|
2024-02-27 16:15:11 +00:00
|
|
|
if strings.Contains(string(data), signal.EventLoggedIn) {
|
2024-07-11 09:57:56 +00:00
|
|
|
require.Contains(t, string(data), "status.staging")
|
2023-09-27 17:26:10 +00:00
|
|
|
c <- struct{}{}
|
|
|
|
}
|
|
|
|
})
|
2024-07-11 09:57:56 +00:00
|
|
|
defer signal.SetMobileSignalHandler(nil)
|
2024-02-27 16:15:11 +00:00
|
|
|
waitForLogin := func(chan interface{}) {
|
|
|
|
select {
|
|
|
|
case <-c:
|
|
|
|
break
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-05 00:00:51 +00:00
|
|
|
acc, err := b.CreateAccountAndLogin(createAccountRequest)
|
2023-10-10 16:12:38 +00:00
|
|
|
require.NoError(t, err)
|
2024-02-27 16:15:11 +00:00
|
|
|
require.Equal(t, nameserver, b.config.WakuV2Config.Nameserver)
|
|
|
|
|
|
|
|
waitForLogin(c)
|
2023-09-27 17:26:10 +00:00
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
require.NoError(t, b.StopNode())
|
|
|
|
|
|
|
|
accounts, err := b.GetAccounts()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, accounts, 1)
|
|
|
|
|
2024-06-05 00:00:51 +00:00
|
|
|
require.NotEmpty(t, accounts[0].KeyUID)
|
|
|
|
require.Equal(t, acc.KeyUID, accounts[0].KeyUID)
|
|
|
|
|
2023-09-27 17:26:10 +00:00
|
|
|
loginAccountRequest := &requests.Login{
|
2024-02-27 16:15:11 +00:00
|
|
|
KeyUID: accounts[0].KeyUID,
|
|
|
|
Password: password,
|
|
|
|
WakuV2Nameserver: nameserver,
|
2023-09-27 17:26:10 +00:00
|
|
|
}
|
2024-02-27 16:15:11 +00:00
|
|
|
err = b.LoginAccount(loginAccountRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
waitForLogin(c)
|
|
|
|
|
|
|
|
require.Equal(t, nameserver, b.config.WakuV2Config.Nameserver)
|
2023-09-27 17:26:10 +00:00
|
|
|
}
|
|
|
|
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
func TestEnableInstallationAndPair(t *testing.T) {
|
|
|
|
// create account acc
|
|
|
|
utils.Init()
|
|
|
|
displayName := "some-display-name"
|
|
|
|
password := "some-password"
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
nameserver := "8.8.8.8"
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
createAccountRequest := &requests.CreateAccount{
|
|
|
|
DisplayName: displayName,
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: password,
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
|
|
|
WakuV2Nameserver: &nameserver,
|
|
|
|
WakuV2Fleet: "status.staging",
|
|
|
|
}
|
|
|
|
acc, err := b.CreateAccountAndLogin(createAccountRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, acc)
|
|
|
|
_, err = b.Messenger().Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
s, err := b.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
mn := *s.Mnemonic
|
|
|
|
db, err := accounts.NewDB(b.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
n, err := db.GetSettingLastSynced(settings.DisplayName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, n > 0)
|
|
|
|
|
|
|
|
// restore account acc as acc2 use Mnemonic from acc
|
|
|
|
restoreRequest := &requests.RestoreAccount{
|
|
|
|
Mnemonic: mn,
|
|
|
|
FetchBackup: true,
|
|
|
|
CreateAccount: requests.CreateAccount{
|
|
|
|
Password: password,
|
|
|
|
CustomizationColor: "0x000000",
|
|
|
|
RootDataDir: t.TempDir(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
b2 := NewGethStatusBackend()
|
|
|
|
acc2, err := b2.RestoreAccountAndLogin(restoreRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, acc2)
|
|
|
|
_, err = b2.Messenger().Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
s2, err := b2.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Logf("acc2 settings.name: %s", s2.Name)
|
|
|
|
// should be 3 words random name
|
|
|
|
require.Len(t, strings.Split(s2.Name, " "), 3)
|
|
|
|
require.Empty(t, acc2.Name)
|
|
|
|
require.Empty(t, s2.DisplayName)
|
|
|
|
db2, err := accounts.NewDB(b2.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
n, err = db2.GetSettingLastSynced(settings.DisplayName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, n == 0)
|
|
|
|
|
|
|
|
// pair installation
|
|
|
|
_, err = b2.Messenger().EnableInstallationAndPair(&requests.EnableInstallationAndPair{InstallationID: s.InstallationID})
|
|
|
|
require.NoError(t, err)
|
|
|
|
// ensure acc received the installation from acc2
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
r, err := b.Messenger().RetrieveAll()
|
|
|
|
require.NoError(t, err)
|
|
|
|
if len(r.Installations()) > 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.New("new installation not received yet")
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// sync data from acc to acc2
|
|
|
|
err = b.Messenger().EnableAndSyncInstallation(&requests.EnableAndSyncInstallation{InstallationID: s2.InstallationID})
|
|
|
|
require.NoError(t, err)
|
|
|
|
// ensure acc2's display name get synced
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
r, err := b2.Messenger().RetrieveAll()
|
|
|
|
require.NoError(t, err)
|
|
|
|
for _, ss := range r.Settings {
|
|
|
|
if ss.GetDBName() == "display_name" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errors.New("display name setting not received yet")
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check display name for acc2
|
|
|
|
s2, err = b2.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, displayName, s2.DisplayName)
|
|
|
|
acc2, err = b2.GetActiveAccount()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, displayName, acc2.Name)
|
|
|
|
}
|
|
|
|
|
2021-07-20 11:48:10 +00:00
|
|
|
func TestVerifyDatabasePassword(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
chatKey, err := gethcrypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
walletKey, err := gethcrypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
keyUIDHex := sha256.Sum256(gethcrypto.FromECDSAPub(&chatKey.PublicKey))
|
|
|
|
keyUID := types.EncodeHex(keyUIDHex[:])
|
|
|
|
main := multiaccounts.Account{
|
|
|
|
KeyUID: keyUID,
|
|
|
|
}
|
2023-04-26 20:39:51 +00:00
|
|
|
tmpdir := t.TempDir()
|
2021-07-20 11:48:10 +00:00
|
|
|
conf, err := params.NewNodeConfig(tmpdir, 1777)
|
|
|
|
require.NoError(t, err)
|
|
|
|
keyhex := hex.EncodeToString(gethcrypto.FromECDSA(chatKey))
|
|
|
|
|
|
|
|
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
|
|
|
|
b.UpdateRootDataDir(conf.DataDir)
|
|
|
|
require.NoError(t, b.OpenAccounts())
|
|
|
|
|
|
|
|
address := crypto.PubkeyToAddress(walletKey.PublicKey)
|
2023-05-16 10:50:04 +00:00
|
|
|
|
|
|
|
settings := testSettings
|
|
|
|
settings.KeyUID = keyUID
|
|
|
|
settings.Address = crypto.PubkeyToAddress(walletKey.PublicKey)
|
|
|
|
|
2023-06-01 12:57:05 +00:00
|
|
|
chatPubKey := crypto.FromECDSAPub(&chatKey.PublicKey)
|
|
|
|
|
|
|
|
require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", settings, conf, []*accounts.Account{
|
|
|
|
{Address: address, KeyUID: keyUID, Wallet: true},
|
|
|
|
{Address: crypto.PubkeyToAddress(chatKey.PublicKey), KeyUID: keyUID, Chat: true, PublicKey: chatPubKey}}, keyhex))
|
2021-07-20 11:48:10 +00:00
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
require.NoError(t, b.StopNode())
|
|
|
|
|
|
|
|
require.Error(t, b.VerifyDatabasePassword(main.KeyUID, "wrong-pass"))
|
|
|
|
require.NoError(t, b.VerifyDatabasePassword(main.KeyUID, "test-pass"))
|
|
|
|
}
|
|
|
|
|
2022-07-06 16:12:49 +00:00
|
|
|
func TestDeleteMultiaccount(t *testing.T) {
|
2020-07-13 10:45:36 +00:00
|
|
|
backend := NewGethStatusBackend()
|
|
|
|
|
2023-04-26 20:39:51 +00:00
|
|
|
rootDataDir := t.TempDir()
|
2020-07-13 10:45:36 +00:00
|
|
|
|
|
|
|
keyStoreDir := filepath.Join(rootDataDir, "keystore")
|
|
|
|
|
|
|
|
backend.rootDataDir = rootDataDir
|
|
|
|
|
2023-04-26 20:39:51 +00:00
|
|
|
err := backend.AccountManager().InitKeystore(keyStoreDir)
|
2020-07-13 10:45:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
backend.AccountManager()
|
|
|
|
accs, err := backend.AccountManager().
|
|
|
|
AccountsGenerator().
|
|
|
|
GenerateAndDeriveAddresses(12, 1, "", []string{"m/44'/60'/0'/0"})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
generateAccount := accs[0]
|
|
|
|
accountInfo, err := backend.AccountManager().
|
|
|
|
AccountsGenerator().
|
|
|
|
StoreAccount(generateAccount.ID, "123123")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
account := multiaccounts.Account{
|
|
|
|
Name: "foo",
|
|
|
|
Timestamp: 1,
|
|
|
|
KeycardPairing: "pairing",
|
|
|
|
KeyUID: generateAccount.KeyUID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = backend.ensureAppDBOpened(account, "123123")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
s := settings.Settings{
|
2020-07-13 10:45:36 +00:00
|
|
|
Address: types.HexToAddress(accountInfo.Address),
|
|
|
|
CurrentNetwork: "mainnet_rpc",
|
|
|
|
DappsAddress: types.HexToAddress(accountInfo.Address),
|
|
|
|
EIP1581Address: types.HexToAddress(accountInfo.Address),
|
|
|
|
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
|
|
|
|
KeyUID: account.KeyUID,
|
2023-05-08 15:14:46 +00:00
|
|
|
LatestDerivedPath: 0,
|
2020-07-13 10:45:36 +00:00
|
|
|
Name: "Jittery Cornflowerblue Kingbird",
|
|
|
|
Networks: &networks,
|
|
|
|
PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==",
|
|
|
|
PreviewPrivacy: false,
|
|
|
|
PublicKey: accountInfo.PublicKey,
|
|
|
|
SigningPhrase: "yurt joey vibe",
|
|
|
|
WalletRootAddress: types.HexToAddress(accountInfo.Address)}
|
|
|
|
|
|
|
|
err = backend.saveAccountsAndSettings(
|
2022-03-23 18:47:00 +00:00
|
|
|
s,
|
2020-07-13 10:45:36 +00:00
|
|
|
¶ms.NodeConfig{},
|
|
|
|
nil)
|
2023-05-16 10:50:04 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.True(t, err == accounts.ErrKeypairWithoutAccounts)
|
2020-07-13 10:45:36 +00:00
|
|
|
|
|
|
|
err = backend.OpenAccounts()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = backend.SaveAccount(account)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
files, err := ioutil.ReadDir(rootDataDir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, 3, len(files))
|
|
|
|
|
2022-07-06 16:12:49 +00:00
|
|
|
err = backend.DeleteMultiaccount(account.KeyUID, keyStoreDir)
|
2020-07-13 10:45:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
files, err = ioutil.ReadDir(rootDataDir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 3, len(files))
|
|
|
|
}
|
2021-07-20 11:48:10 +00:00
|
|
|
|
|
|
|
func TestConvertAccount(t *testing.T) {
|
2023-01-26 20:03:01 +00:00
|
|
|
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
|
|
const password = "111111" // represents password for a regular user
|
|
|
|
const keycardPassword = "222222" // represents password for a keycard user
|
2023-05-05 07:43:05 +00:00
|
|
|
const keycardUID = "1234"
|
2023-01-26 20:03:01 +00:00
|
|
|
const pathEIP1581Root = "m/43'/60'/1581'"
|
2024-01-18 18:54:54 +00:00
|
|
|
const pathEIP1581Chat = pathEIP1581Root + "/0'/0"
|
2023-05-05 07:43:05 +00:00
|
|
|
const pathWalletRoot = "m/44'/60'/0'/0"
|
|
|
|
const pathDefaultWalletAccount = pathWalletRoot + "/0"
|
|
|
|
const customWalletPath1 = pathWalletRoot + "/1"
|
|
|
|
const customWalletPath2 = pathWalletRoot + "/2"
|
2023-01-26 20:03:01 +00:00
|
|
|
var allGeneratedPaths []string
|
2023-05-05 07:43:05 +00:00
|
|
|
allGeneratedPaths = append(allGeneratedPaths, pathEIP1581Root, pathEIP1581Chat, pathWalletRoot, pathDefaultWalletAccount, customWalletPath1, customWalletPath2)
|
2023-01-26 20:03:01 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
keystoreContainsFileForAccount := func(keyStoreDir string, hexAddress string) bool {
|
|
|
|
addrWithoutPrefix := strings.ToLower(hexAddress[2:])
|
|
|
|
found := false
|
|
|
|
err = filepath.Walk(keyStoreDir, func(path string, fileInfo os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !fileInfo.IsDir() && strings.Contains(strings.ToUpper(path), strings.ToUpper(addrWithoutPrefix)) {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
2023-04-26 20:39:51 +00:00
|
|
|
rootDataDir := t.TempDir()
|
2021-07-20 11:48:10 +00:00
|
|
|
|
|
|
|
keyStoreDir := filepath.Join(rootDataDir, "keystore")
|
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
utils.Init()
|
2023-03-27 14:33:00 +00:00
|
|
|
|
2023-08-11 11:28:45 +00:00
|
|
|
backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
|
2023-03-27 14:33:00 +00:00
|
|
|
defer func() {
|
|
|
|
err := stop1()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
err := stop2()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-08-11 11:28:45 +00:00
|
|
|
defer func() {
|
|
|
|
err := stopWallet()
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
}
|
|
|
|
}()
|
2023-03-27 14:33:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-20 11:48:10 +00:00
|
|
|
backend.rootDataDir = rootDataDir
|
2023-08-02 07:39:58 +00:00
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(keyStoreDir))
|
|
|
|
err = backend.OpenAccounts()
|
2023-01-26 20:03:01 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-20 11:48:10 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
genAccInfo, err := backend.AccountManager().AccountsGenerator().ImportMnemonic(mnemonic, "")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2023-05-05 07:43:05 +00:00
|
|
|
masterAddress := genAccInfo.Address
|
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
accountInfo, err := backend.AccountManager().AccountsGenerator().StoreAccount(genAccInfo.ID, password)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
found := keystoreContainsFileForAccount(keyStoreDir, accountInfo.Address)
|
|
|
|
require.True(t, found)
|
2021-07-20 11:48:10 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
derivedAccounts, err := backend.AccountManager().AccountsGenerator().StoreDerivedAccounts(genAccInfo.ID, password, allGeneratedPaths)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2023-08-02 07:39:58 +00:00
|
|
|
chatKey := derivedAccounts[pathEIP1581Chat].PrivateKey[2:]
|
2023-05-05 07:43:05 +00:00
|
|
|
chatAddress := derivedAccounts[pathEIP1581Chat].Address
|
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, chatAddress)
|
2023-01-26 20:03:01 +00:00
|
|
|
require.True(t, found)
|
|
|
|
|
2024-06-26 11:14:27 +00:00
|
|
|
defaultSettings, err := defaultSettings(genAccInfo.KeyUID, genAccInfo.Address, derivedAccounts)
|
2023-08-02 07:39:58 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
nodeConfig, err := defaultNodeConfig(defaultSettings.InstallationID, &requests.CreateAccount{
|
2024-03-28 15:01:44 +00:00
|
|
|
LogLevel: defaultSettings.LogLevel,
|
2023-08-02 07:39:58 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
nodeConfig.DataDir = rootDataDir
|
|
|
|
nodeConfig.KeyStoreDir = keyStoreDir
|
|
|
|
|
2023-05-16 10:50:04 +00:00
|
|
|
profileKeypair := &accounts.Keypair{
|
2023-05-05 07:43:05 +00:00
|
|
|
KeyUID: genAccInfo.KeyUID,
|
2023-05-16 10:50:04 +00:00
|
|
|
Name: "Profile Name",
|
|
|
|
Type: accounts.KeypairTypeProfile,
|
|
|
|
DerivedFrom: masterAddress,
|
|
|
|
}
|
|
|
|
|
|
|
|
profileKeypair.Accounts = append(profileKeypair.Accounts, &accounts.Account{
|
|
|
|
Address: types.HexToAddress(chatAddress),
|
|
|
|
KeyUID: profileKeypair.KeyUID,
|
|
|
|
Type: accounts.AccountTypeGenerated,
|
|
|
|
PublicKey: types.Hex2Bytes(accountInfo.PublicKey),
|
|
|
|
Path: pathEIP1581Chat,
|
|
|
|
Wallet: false,
|
|
|
|
Chat: true,
|
|
|
|
Name: "GeneratedAccount",
|
2023-01-26 20:03:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for p, dAccInfo := range derivedAccounts {
|
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, dAccInfo.Address)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, found)
|
|
|
|
|
|
|
|
if p == pathDefaultWalletAccount ||
|
|
|
|
p == customWalletPath1 ||
|
|
|
|
p == customWalletPath2 {
|
2023-08-02 07:39:58 +00:00
|
|
|
wAcc := &accounts.Account{
|
2023-05-16 10:50:04 +00:00
|
|
|
Address: types.HexToAddress(dAccInfo.Address),
|
|
|
|
KeyUID: genAccInfo.KeyUID,
|
|
|
|
Wallet: false,
|
|
|
|
Chat: false,
|
|
|
|
Type: accounts.AccountTypeGenerated,
|
|
|
|
Path: p,
|
|
|
|
Name: "derivacc" + p,
|
|
|
|
Hidden: false,
|
|
|
|
Removed: false,
|
2023-08-02 07:39:58 +00:00
|
|
|
}
|
|
|
|
if p == pathDefaultWalletAccount {
|
|
|
|
wAcc.Wallet = true
|
|
|
|
}
|
|
|
|
profileKeypair.Accounts = append(profileKeypair.Accounts, wAcc)
|
2023-01-26 20:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-20 11:48:10 +00:00
|
|
|
|
|
|
|
account := multiaccounts.Account{
|
2023-05-16 10:50:04 +00:00
|
|
|
Name: profileKeypair.Name,
|
2021-07-20 11:48:10 +00:00
|
|
|
Timestamp: 1,
|
2023-05-16 10:50:04 +00:00
|
|
|
KeyUID: profileKeypair.KeyUID,
|
2021-07-20 11:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = backend.ensureAppDBOpened(account, password)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-26 11:14:27 +00:00
|
|
|
err = backend.StartNodeWithAccountAndInitialConfig(account, password, *defaultSettings, nodeConfig, profileKeypair.Accounts, nil)
|
2021-07-20 11:48:10 +00:00
|
|
|
require.NoError(t, err)
|
2023-08-02 07:39:58 +00:00
|
|
|
multiaccounts, err := backend.GetAccounts()
|
2021-07-20 11:48:10 +00:00
|
|
|
require.NoError(t, err)
|
2023-08-02 07:39:58 +00:00
|
|
|
require.NotEmpty(t, multiaccounts[0].ColorHash)
|
|
|
|
serverMessenger := backend.Messenger()
|
|
|
|
require.NotNil(t, serverMessenger)
|
2021-07-20 11:48:10 +00:00
|
|
|
|
|
|
|
files, err := ioutil.ReadDir(rootDataDir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, 3, len(files))
|
|
|
|
|
|
|
|
keycardAccount := account
|
|
|
|
keycardAccount.KeycardPairing = "pairing"
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
keycardSettings := settings.Settings{
|
2021-07-20 11:48:10 +00:00
|
|
|
KeycardInstanceUID: "0xdeadbeef",
|
2022-08-25 15:09:08 +00:00
|
|
|
KeycardPairedOn: 1,
|
2021-07-20 11:48:10 +00:00
|
|
|
KeycardPairing: "pairing",
|
|
|
|
}
|
|
|
|
|
2023-05-05 07:43:05 +00:00
|
|
|
// Ensure we're able to open the DB
|
|
|
|
err = backend.ensureAppDBOpened(keycardAccount, keycardPassword)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// db creation
|
|
|
|
db, err := accounts.NewDB(backend.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Check that there is no registered keycards
|
2023-07-05 12:41:58 +00:00
|
|
|
keycards, err := db.GetKeycardsWithSameKeyUID(genAccInfo.KeyUID)
|
2023-05-05 07:43:05 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-09 18:48:56 +00:00
|
|
|
require.Equal(t, 0, len(keycards))
|
2023-05-05 07:43:05 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
// Converting to a keycard account
|
2023-05-05 07:43:05 +00:00
|
|
|
err = backend.ConvertToKeycardAccount(keycardAccount, keycardSettings, keycardUID, password, keycardPassword)
|
2023-01-26 20:03:01 +00:00
|
|
|
require.NoError(t, err)
|
2022-11-08 13:30:33 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
// Validating results of converting to a keycard account.
|
|
|
|
// All keystore files for the account which is migrated need to be removed.
|
2023-05-05 07:43:05 +00:00
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, masterAddress)
|
2023-01-26 20:03:01 +00:00
|
|
|
require.False(t, found)
|
|
|
|
|
|
|
|
for _, dAccInfo := range derivedAccounts {
|
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, dAccInfo.Address)
|
|
|
|
require.False(t, found)
|
|
|
|
}
|
2022-09-26 06:50:42 +00:00
|
|
|
|
2023-08-02 07:39:58 +00:00
|
|
|
require.NoError(t, backend.Logout())
|
|
|
|
require.NoError(t, backend.StopNode())
|
|
|
|
|
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(keyStoreDir))
|
|
|
|
require.NoError(t, backend.OpenAccounts())
|
|
|
|
|
|
|
|
require.NoError(t, backend.StartNodeWithKey(account, keycardPassword, chatKey, nodeConfig))
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(t, backend.Logout())
|
|
|
|
assert.NoError(t, backend.StopNode())
|
|
|
|
}()
|
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
// Ensure we're able to open the DB
|
|
|
|
err = backend.ensureAppDBOpened(keycardAccount, keycardPassword)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-05-05 07:43:05 +00:00
|
|
|
// db creation after re-encryption
|
|
|
|
db1, err := accounts.NewDB(backend.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Check that there is a registered keycard
|
2023-07-05 12:41:58 +00:00
|
|
|
keycards, err = db1.GetKeycardsWithSameKeyUID(genAccInfo.KeyUID)
|
2023-05-05 07:43:05 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-09 18:48:56 +00:00
|
|
|
require.Equal(t, 1, len(keycards))
|
2023-05-05 07:43:05 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
// Converting to a regular account
|
|
|
|
err = backend.ConvertToRegularAccount(mnemonic, keycardPassword, password)
|
|
|
|
require.NoError(t, err)
|
2022-11-08 13:30:33 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
// Validating results of converting to a regular account.
|
|
|
|
// All keystore files for need to be created.
|
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, accountInfo.Address)
|
2022-11-08 13:30:33 +00:00
|
|
|
require.True(t, found)
|
2021-07-20 11:48:10 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
for _, dAccInfo := range derivedAccounts {
|
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, dAccInfo.Address)
|
|
|
|
require.True(t, found)
|
|
|
|
}
|
|
|
|
|
|
|
|
found = keystoreContainsFileForAccount(keyStoreDir, masterAddress)
|
|
|
|
require.True(t, found)
|
2022-08-31 16:11:42 +00:00
|
|
|
|
2023-01-26 20:03:01 +00:00
|
|
|
// Ensure we're able to open the DB
|
|
|
|
err = backend.ensureAppDBOpened(keycardAccount, password)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-05-05 07:43:05 +00:00
|
|
|
// db creation after re-encryption
|
|
|
|
db2, err := accounts.NewDB(backend.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Check that there is no registered keycards
|
2023-07-05 12:41:58 +00:00
|
|
|
keycards, err = db2.GetKeycardsWithSameKeyUID(genAccInfo.KeyUID)
|
2023-05-05 07:43:05 +00:00
|
|
|
require.NoError(t, err)
|
2023-05-09 18:48:56 +00:00
|
|
|
require.Equal(t, 0, len(keycards))
|
2021-07-20 11:48:10 +00:00
|
|
|
}
|
2022-05-04 14:46:49 +00:00
|
|
|
|
|
|
|
func copyFile(srcFolder string, dstFolder string, fileName string, t *testing.T) {
|
|
|
|
data, err := ioutil.ReadFile(path.Join(srcFolder, fileName))
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(path.Join(dstFolder, fileName), data, 0600)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func copyDir(srcFolder string, dstFolder string, t *testing.T) {
|
|
|
|
files, err := ioutil.ReadDir(srcFolder)
|
|
|
|
require.NoError(t, err)
|
|
|
|
for _, file := range files {
|
|
|
|
if !file.IsDir() {
|
|
|
|
copyFile(srcFolder, dstFolder, file.Name(), t)
|
|
|
|
} else {
|
|
|
|
childFolder := path.Join(srcFolder, file.Name())
|
|
|
|
newFolder := path.Join(dstFolder, file.Name())
|
|
|
|
err = os.MkdirAll(newFolder, os.ModePerm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
copyDir(childFolder, newFolder, t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-21 02:34:43 +00:00
|
|
|
func loginDesktopUser(t *testing.T, conf *params.NodeConfig) {
|
2022-05-04 14:46:49 +00:00
|
|
|
// The following passwords and DB used in this test unit are only
|
|
|
|
// used to determine if login process works correctly after a migration
|
|
|
|
|
|
|
|
// Expected account data:
|
|
|
|
keyUID := "0x7c46c8f6f059ab72d524f2a6d356904db30bb0392636172ab3929a6bd2220f84" // #nosec G101
|
|
|
|
username := "TestUser"
|
|
|
|
passwd := "0xC888C9CE9E098D5864D3DED6EBCC140A12142263BACE3A23A36F9905F12BD64A" // #nosec G101
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
|
|
|
|
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
|
|
|
|
b.UpdateRootDataDir(conf.DataDir)
|
|
|
|
|
|
|
|
require.NoError(t, b.OpenAccounts())
|
|
|
|
|
|
|
|
accounts, err := b.GetAccounts()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, accounts, 1)
|
|
|
|
require.Equal(t, username, accounts[0].Name)
|
|
|
|
require.Equal(t, keyUID, accounts[0].KeyUID)
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2024-06-26 11:14:27 +00:00
|
|
|
err := b.StartNodeWithAccount(accounts[0], passwd, conf, nil)
|
2022-05-04 14:46:49 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
require.NoError(t, b.Logout())
|
2023-05-18 11:22:20 +00:00
|
|
|
require.NotNil(t, b.statusNode.HTTPServer())
|
2022-05-04 14:46:49 +00:00
|
|
|
require.NoError(t, b.StopNode())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-05-21 02:34:43 +00:00
|
|
|
func TestLoginAndMigrationsStillWorkWithExistingDesktopUser(t *testing.T) {
|
2022-05-04 14:46:49 +00:00
|
|
|
utils.Init()
|
|
|
|
|
2023-05-12 18:13:21 +00:00
|
|
|
srcFolder := "../static/test-0.132.0-account/"
|
2022-05-04 14:46:49 +00:00
|
|
|
|
2023-04-26 20:39:51 +00:00
|
|
|
tmpdir := t.TempDir()
|
2022-05-04 14:46:49 +00:00
|
|
|
|
|
|
|
copyDir(srcFolder, tmpdir, t)
|
|
|
|
|
|
|
|
conf, err := params.NewNodeConfig(tmpdir, 1777)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-05-21 02:34:43 +00:00
|
|
|
loginDesktopUser(t, conf)
|
|
|
|
loginDesktopUser(t, conf) // Login twice to catch weird errors that only appear after logout
|
|
|
|
}
|
|
|
|
|
2023-08-10 11:41:04 +00:00
|
|
|
func TestChangeDatabasePassword(t *testing.T) {
|
2023-08-17 15:18:56 +00:00
|
|
|
oldPassword := "password"
|
|
|
|
newPassword := "newPassword"
|
|
|
|
|
2023-08-10 11:41:04 +00:00
|
|
|
backend := NewGethStatusBackend()
|
|
|
|
backend.UpdateRootDataDir(t.TempDir())
|
|
|
|
|
2023-08-17 15:18:56 +00:00
|
|
|
// Setup keystore to test decryption of it
|
|
|
|
keyStoreDir := t.TempDir()
|
|
|
|
require.NoError(t, backend.accountManager.InitKeystore(keyStoreDir))
|
|
|
|
|
|
|
|
_, accountInfo, _, err := backend.accountManager.CreateAccount(oldPassword)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-10 11:41:04 +00:00
|
|
|
account := multiaccounts.Account{
|
|
|
|
Name: "TestAccount",
|
|
|
|
Timestamp: 1,
|
|
|
|
KeyUID: "0x7c46c8f6f059ab72d524f2a6d356904db30bb0392636172ab3929a6bd2220f84",
|
|
|
|
KDFIterations: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize accounts DB
|
2023-08-17 15:18:56 +00:00
|
|
|
err = backend.OpenAccounts()
|
2023-08-10 11:41:04 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
err = backend.SaveAccount(account)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Created DBs with old password
|
|
|
|
err = backend.ensureDBsOpened(account, oldPassword)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Change password
|
|
|
|
err = backend.ChangeDatabasePassword(account.KeyUID, oldPassword, newPassword)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Test that DBs can be opened with new password
|
2023-08-22 14:36:51 +00:00
|
|
|
appDbPath, err := backend.getAppDBPath(account.KeyUID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
appDb, err := sqlite.OpenDB(appDbPath, newPassword, account.KDFIterations)
|
2023-08-10 11:41:04 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
appDb.Close()
|
|
|
|
|
2023-08-22 14:36:51 +00:00
|
|
|
walletDbPath, err := backend.getWalletDBPath(account.KeyUID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
walletDb, err := sqlite.OpenDB(walletDbPath, newPassword, account.KDFIterations)
|
2023-08-10 11:41:04 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
walletDb.Close()
|
2023-08-17 15:18:56 +00:00
|
|
|
|
|
|
|
// Test that keystore can be decrypted with the new password
|
|
|
|
acc, key, err := backend.accountManager.AddressToDecryptedAccount(accountInfo.WalletAddress, newPassword)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, acc)
|
|
|
|
require.NotNil(t, key)
|
|
|
|
require.Equal(t, acc.Address, key.Address)
|
2023-08-10 11:41:04 +00:00
|
|
|
}
|
2023-10-10 16:12:38 +00:00
|
|
|
|
|
|
|
func TestCreateWallet(t *testing.T) {
|
|
|
|
utils.Init()
|
2023-11-10 15:12:54 +00:00
|
|
|
password := "some-password2" // nolint: goconst
|
2023-10-10 16:12:38 +00:00
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
2024-06-05 00:00:51 +00:00
|
|
|
defer func() {
|
|
|
|
require.NoError(t, b.StopNode())
|
|
|
|
}()
|
|
|
|
|
2023-10-10 16:12:38 +00:00
|
|
|
createAccountRequest := &requests.CreateAccount{
|
2024-06-05 13:03:34 +00:00
|
|
|
DisplayName: "some-display-name",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: password,
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
2023-10-10 16:12:38 +00:00
|
|
|
}
|
|
|
|
c := make(chan interface{}, 10)
|
|
|
|
signal.SetMobileSignalHandler(func(data []byte) {
|
|
|
|
if strings.Contains(string(data), "node.login") {
|
|
|
|
c <- struct{}{}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
account, err := b.CreateAccountAndLogin(createAccountRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
statusNode := b.statusNode
|
|
|
|
require.NotNil(t, statusNode)
|
|
|
|
|
|
|
|
walletService := statusNode.WalletService()
|
|
|
|
require.NotNil(t, walletService)
|
|
|
|
walletAPI := walletservice.NewAPI(walletService)
|
|
|
|
|
|
|
|
paths := []string{"m/44'/60'/0'/0/1"}
|
|
|
|
|
|
|
|
db, err := accounts.NewDB(b.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
walletRootAddress, err := db.GetWalletRootAddress()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-06 23:34:08 +00:00
|
|
|
mnemonic, err := db.Mnemonic()
|
2023-10-10 16:12:38 +00:00
|
|
|
require.NoError(t, err)
|
2024-06-06 23:34:08 +00:00
|
|
|
require.NotEmpty(t, mnemonic)
|
2023-10-10 16:12:38 +00:00
|
|
|
|
|
|
|
derivedAddress, err := walletAPI.GetDerivedAddresses(context.Background(), password, walletRootAddress.String(), paths)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, derivedAddress, 1)
|
|
|
|
|
|
|
|
accountsService := statusNode.AccountService()
|
|
|
|
require.NotNil(t, accountsService)
|
|
|
|
accountsAPI := accountsService.AccountsAPI()
|
|
|
|
|
|
|
|
err = accountsAPI.AddAccount(context.Background(), password, &accounts.Account{
|
|
|
|
KeyUID: account.KeyUID,
|
|
|
|
Type: accounts.AccountTypeGenerated,
|
|
|
|
PublicKey: derivedAddress[0].PublicKey,
|
|
|
|
Emoji: "some",
|
|
|
|
ColorID: "so",
|
|
|
|
Name: "some name",
|
|
|
|
Path: derivedAddress[0].Path,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2023-11-10 15:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetFleet(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
password := "some-password2" // nolint: goconst
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
createAccountRequest := &requests.CreateAccount{
|
2024-06-05 13:03:34 +00:00
|
|
|
DisplayName: "some-display-name",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: password,
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
2023-11-10 15:12:54 +00:00
|
|
|
}
|
|
|
|
c := make(chan interface{}, 10)
|
|
|
|
signal.SetMobileSignalHandler(func(data []byte) {
|
|
|
|
if strings.Contains(string(data), "node.login") {
|
|
|
|
c <- struct{}{}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
newAccount, err := b.CreateAccountAndLogin(createAccountRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
statusNode := b.statusNode
|
|
|
|
require.NotNil(t, statusNode)
|
|
|
|
|
|
|
|
savedSettings, err := b.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, savedSettings.Fleet)
|
|
|
|
|
|
|
|
accountsDB, err := b.accountsDB()
|
|
|
|
require.NoError(t, err)
|
2024-07-29 21:19:48 +00:00
|
|
|
err = accountsDB.SaveSettingField(settings.Fleet, params.FleetStatusProd)
|
2023-11-10 15:12:54 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
savedSettings, err = b.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, savedSettings.Fleet)
|
2024-07-29 21:19:48 +00:00
|
|
|
require.Equal(t, params.FleetStatusProd, *savedSettings.Fleet)
|
2023-10-10 16:12:38 +00:00
|
|
|
|
2023-11-10 15:12:54 +00:00
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
|
|
|
|
loginAccountRequest := &requests.Login{
|
|
|
|
KeyUID: newAccount.KeyUID,
|
|
|
|
Password: password,
|
|
|
|
}
|
|
|
|
require.NoError(t, b.LoginAccount(loginAccountRequest))
|
|
|
|
select {
|
|
|
|
case <-c:
|
|
|
|
break
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
// Check is using the right fleet
|
2024-07-29 21:19:48 +00:00
|
|
|
require.Equal(t, b.config.ClusterConfig.WakuNodes, params.DefaultWakuNodes(params.FleetStatusProd))
|
2023-11-10 15:12:54 +00:00
|
|
|
|
|
|
|
require.NoError(t, b.Logout())
|
2023-10-10 16:12:38 +00:00
|
|
|
}
|
2024-02-02 13:55:46 +00:00
|
|
|
|
|
|
|
func TestWalletConfigOnLoginAccount(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
password := "some-password2" // nolint: goconst
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
poktToken := "grove-token" // nolint: goconst
|
|
|
|
infuraToken := "infura-token" // nolint: goconst
|
|
|
|
alchemyEthereumMainnetToken := "alchemy-ethereum-mainnet-token"
|
|
|
|
alchemyEthereumSepoliaToken := "alchemy-ethereum-sepolia-token"
|
|
|
|
alchemyArbitrumMainnetToken := "alchemy-arbitrum-mainnet-token"
|
|
|
|
alchemyArbitrumSepoliaToken := "alchemy-arbitrum-sepolia-token"
|
|
|
|
alchemyOptimismMainnetToken := "alchemy-optimism-mainnet-token"
|
|
|
|
alchemyOptimismSepoliaToken := "alchemy-optimism-sepolia-token"
|
|
|
|
raribleMainnetAPIKey := "rarible-mainnet-api-key" // nolint: gosec
|
|
|
|
raribleTestnetAPIKey := "rarible-testnet-api-key" // nolint: gosec
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
createAccountRequest := &requests.CreateAccount{
|
2024-06-05 13:03:34 +00:00
|
|
|
DisplayName: "some-display-name",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: password,
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
2024-02-02 13:55:46 +00:00
|
|
|
}
|
|
|
|
c := make(chan interface{}, 10)
|
|
|
|
signal.SetMobileSignalHandler(func(data []byte) {
|
|
|
|
if strings.Contains(string(data), "node.login") {
|
|
|
|
c <- struct{}{}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
newAccount, err := b.CreateAccountAndLogin(createAccountRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
statusNode := b.statusNode
|
|
|
|
require.NotNil(t, statusNode)
|
|
|
|
|
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
|
|
|
|
loginAccountRequest := &requests.Login{
|
|
|
|
KeyUID: newAccount.KeyUID,
|
|
|
|
Password: password,
|
|
|
|
WalletSecretsConfig: requests.WalletSecretsConfig{
|
|
|
|
PoktToken: poktToken,
|
|
|
|
InfuraToken: infuraToken,
|
|
|
|
AlchemyEthereumMainnetToken: alchemyEthereumMainnetToken,
|
|
|
|
AlchemyEthereumSepoliaToken: alchemyEthereumSepoliaToken,
|
|
|
|
AlchemyArbitrumMainnetToken: alchemyArbitrumMainnetToken,
|
|
|
|
AlchemyArbitrumSepoliaToken: alchemyArbitrumSepoliaToken,
|
|
|
|
AlchemyOptimismMainnetToken: alchemyOptimismMainnetToken,
|
|
|
|
AlchemyOptimismSepoliaToken: alchemyOptimismSepoliaToken,
|
|
|
|
RaribleMainnetAPIKey: raribleMainnetAPIKey,
|
|
|
|
RaribleTestnetAPIKey: raribleTestnetAPIKey,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, b.LoginAccount(loginAccountRequest))
|
|
|
|
select {
|
|
|
|
case <-c:
|
|
|
|
break
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, b.config.WalletConfig.InfuraAPIKey, infuraToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[mainnetChainID], alchemyEthereumMainnetToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[sepoliaChainID], alchemyEthereumSepoliaToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[arbitrumChainID], alchemyArbitrumMainnetToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[arbitrumSepoliaChainID], alchemyArbitrumSepoliaToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[optimismChainID], alchemyOptimismMainnetToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[optimismSepoliaChainID], alchemyOptimismSepoliaToken)
|
|
|
|
require.Equal(t, b.config.WalletConfig.RaribleMainnetAPIKey, raribleMainnetAPIKey)
|
|
|
|
require.Equal(t, b.config.WalletConfig.RaribleTestnetAPIKey, raribleTestnetAPIKey)
|
|
|
|
|
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
}
|
2024-03-26 11:38:16 +00:00
|
|
|
|
|
|
|
func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
b := NewGethStatusBackend()
|
|
|
|
|
|
|
|
// Creating an account with test networks enabled
|
|
|
|
createAccountRequest1 := &requests.CreateAccount{
|
2024-06-05 13:03:34 +00:00
|
|
|
DisplayName: "User-1",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: "password123",
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
|
|
|
TestNetworksEnabled: true,
|
2024-03-26 11:38:16 +00:00
|
|
|
}
|
|
|
|
_, err := b.CreateAccountAndLogin(createAccountRequest1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
statusNode := b.statusNode
|
|
|
|
require.NotNil(t, statusNode)
|
|
|
|
|
|
|
|
settings, err := b.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, settings.TestNetworksEnabled)
|
|
|
|
|
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
|
|
|
|
// Creating an account with test networks disabled
|
|
|
|
createAccountRequest2 := &requests.CreateAccount{
|
2024-06-05 13:03:34 +00:00
|
|
|
DisplayName: "User-2",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Password: "password",
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
LogFilePath: tmpdir + "/log",
|
2024-03-26 11:38:16 +00:00
|
|
|
}
|
|
|
|
_, err = b.CreateAccountAndLogin(createAccountRequest2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
statusNode = b.statusNode
|
|
|
|
require.NotNil(t, statusNode)
|
|
|
|
|
|
|
|
settings, err = b.GetSettings()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, settings.TestNetworksEnabled)
|
|
|
|
|
|
|
|
require.NoError(t, b.Logout())
|
|
|
|
}
|
2024-06-02 18:28:55 +00:00
|
|
|
|
|
|
|
func TestRestoreAccountAndLogin(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
backend := NewGethStatusBackend()
|
|
|
|
|
|
|
|
// Test case 1: Valid restore account request
|
|
|
|
restoreRequest := &requests.RestoreAccount{
|
|
|
|
Mnemonic: "test test test test test test test test test test test test",
|
|
|
|
FetchBackup: false,
|
|
|
|
CreateAccount: requests.CreateAccount{
|
2024-08-07 12:59:43 +00:00
|
|
|
DisplayName: "Account1",
|
|
|
|
DeviceName: "StatusIM",
|
|
|
|
Password: "password",
|
|
|
|
CustomizationColor: "0x000000",
|
|
|
|
RootDataDir: tmpdir,
|
2024-06-02 18:28:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
account, err := backend.RestoreAccountAndLogin(restoreRequest)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, account)
|
|
|
|
|
|
|
|
// Test case 2: Invalid restore account request
|
|
|
|
invalidRequest := &requests.RestoreAccount{}
|
|
|
|
_, err = backend.RestoreAccountAndLogin(invalidRequest)
|
|
|
|
require.Error(t, err)
|
2024-06-06 23:34:08 +00:00
|
|
|
|
|
|
|
db, err := accounts.NewDB(backend.appDB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
mnemonic, err := db.Mnemonic()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, mnemonic)
|
2024-06-02 18:28:55 +00:00
|
|
|
}
|
2024-06-05 13:03:34 +00:00
|
|
|
|
|
|
|
func TestCreateAccountPathsValidation(t *testing.T) {
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
validation := &requests.CreateAccountValidation{
|
|
|
|
AllowEmptyDisplayName: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
request := &requests.CreateAccount{
|
|
|
|
DisplayName: "User-1",
|
|
|
|
Password: "password123",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := request.Validate(validation)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
request.RootDataDir = ""
|
|
|
|
err = request.Validate(validation)
|
2024-08-07 12:59:43 +00:00
|
|
|
require.ErrorIs(t, err, requests.ErrCreateAccountInvalidRootDataDir)
|
2024-06-05 13:03:34 +00:00
|
|
|
}
|
2024-06-26 11:14:27 +00:00
|
|
|
|
|
|
|
func TestRestoreKeycardAccountAndLogin(t *testing.T) {
|
|
|
|
utils.Init()
|
|
|
|
tmpdir := t.TempDir()
|
|
|
|
|
|
|
|
exampleKeycardEvent := map[string]interface{}{
|
|
|
|
"error": "",
|
|
|
|
"instanceUID": "a84599394887b742eed9a99d3834a797",
|
|
|
|
"applicationInfo": map[string]interface{}{
|
|
|
|
"initialized": false,
|
|
|
|
"instanceUID": "",
|
|
|
|
"version": 0,
|
|
|
|
"availableSlots": 0,
|
|
|
|
"keyUID": "",
|
|
|
|
},
|
|
|
|
"seedPhraseIndexes": []interface{}{},
|
|
|
|
"freePairingSlots": 0,
|
|
|
|
"keyUid": "0x579324c53f347e18961c775a00ec13ed7d59a225b1859d5125ff36b450b8778d",
|
|
|
|
"pinRetries": 0,
|
|
|
|
"pukRetries": 0,
|
|
|
|
"cardMetadata": map[string]interface{}{
|
|
|
|
"name": "",
|
|
|
|
"walletAccounts": []interface{}{},
|
|
|
|
},
|
|
|
|
"generatedWalletAccount": map[string]interface{}{
|
|
|
|
"address": "",
|
|
|
|
"publicKey": "",
|
|
|
|
"privateKey": "",
|
|
|
|
},
|
|
|
|
"generatedWalletAccounts": []interface{}{},
|
|
|
|
"txSignature": map[string]interface{}{
|
|
|
|
"r": "",
|
|
|
|
"s": "",
|
|
|
|
"v": "",
|
|
|
|
},
|
|
|
|
"eip1581Key": map[string]interface{}{
|
|
|
|
"address": "0xA8d50f0B3bc581298446be8FBfF5c71684Ea6c01",
|
|
|
|
"publicKey": "0x040d7e6e3761ab3d17c220e484ede2f3fa02998b859d4d0e9d34216c6e41b03dc94996fdea23a9233092cee50a768e7428d5de7bd42e8e32c10d6b0e36b10f0e7a",
|
|
|
|
"privateKey": "",
|
|
|
|
},
|
|
|
|
"encryptionKey": map[string]interface{}{
|
|
|
|
"address": "0x1ec12f2b323ddDD076A1127cEc8FA0B592c46cD3",
|
|
|
|
"publicKey": "0x04c4b16f670b51702dc130673bf9c64ffd1f69383cef2127dfa05031b9b1359120f7342134af9a350465126a85e87cb003b7c4f93d2ba2ff98bb73277b119c7a87",
|
|
|
|
"privateKey": "68c830d5b327382a65e6c302594744ec0d28b01d1ea8124f49714f05c9625ddd"},
|
|
|
|
"masterKey": map[string]interface{}{
|
|
|
|
"address": "0xbf9dE86774051537b2192Ce9c8d2496f129bA24b",
|
|
|
|
"publicKey": "0x040d909a07ecca18bbfa7d53d10a86bd956f54b8b446eabd94940e642ae18421b516ec5b63677c4ce65e0e266b58bdb716d8266b25356154eb61713ecb23824075",
|
|
|
|
"privateKey": "",
|
|
|
|
},
|
|
|
|
"walletKey": map[string]interface{}{
|
|
|
|
"address": "0xB9E1998e1A8854887CA327D1aF5894B6CB0AC07D",
|
|
|
|
"publicKey": "0x04c16e7748f34e0ab2c9c13350d7872d928e942934dd8b8abd3fb12b8c742a5ee8cf0919731e800907068afec25f577bde3a9c534795e359ee48097e4e55f4aaca",
|
|
|
|
"privateKey": "",
|
|
|
|
},
|
|
|
|
"walletRootKey": map[string]interface{}{
|
|
|
|
"address": "0xFf59db9F2f97Db7104A906C390D33C342a1309C8",
|
|
|
|
"publicKey": "0x04c436532398e19ed14b4eb41545b82014435d60e7db4449a371fd80d0d5cd557f60d81f6c2b35ca5440aa60934c23b70489b0e7963e63ec66b51a7e52db711262",
|
|
|
|
"privateKey": "",
|
|
|
|
},
|
|
|
|
"whisperKey": map[string]interface{}{
|
|
|
|
"address": "0xBa122B9c0Ef560813b5D2C0961094aC36289f846",
|
|
|
|
"publicKey": "0x0441468c39b579259676350b9736b01cdadb740f67bfd022fa2b985123b1d66fc3191cfe73205e3d3d84148f0248f9a2978afeeda16d7c3db90bd2579f0de33459",
|
|
|
|
"privateKey": "5a42b4f15ff1a5da95d116442ce11a31e9020f562224bf60b1d8d3a99d90653d",
|
|
|
|
},
|
|
|
|
"masterKeyAddress": "",
|
|
|
|
}
|
|
|
|
|
|
|
|
exampleRequest := map[string]interface{}{
|
|
|
|
"mnemonic": "",
|
|
|
|
"fetchBackup": true,
|
|
|
|
"createAccountRequest": map[string]interface{}{
|
|
|
|
"rootDataDir": tmpdir,
|
|
|
|
"kdfIterations": 256000,
|
|
|
|
"deviceName": "",
|
|
|
|
"displayName": "",
|
|
|
|
"password": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
|
|
|
|
"imagePath": "",
|
|
|
|
"imageCropRectangle": map[string]interface{}{
|
|
|
|
"ax": 0, "ay": 0, "bx": 0, "by": 0},
|
|
|
|
"customizationColor": "primary",
|
|
|
|
"emoji": "",
|
|
|
|
"wakuV2Nameserver": nil,
|
|
|
|
"wakuV2LightClient": false,
|
|
|
|
"logLevel": "DEBUG",
|
|
|
|
"logFilePath": "",
|
|
|
|
"logEnabled": false,
|
|
|
|
"previewPrivacy": true,
|
|
|
|
"verifyTransactionURL": nil,
|
|
|
|
"verifyENSURL": nil,
|
|
|
|
"verifyENSContractAddress": nil,
|
|
|
|
"verifyTransactionChainID": nil,
|
|
|
|
"upstreamConfig": "",
|
|
|
|
"networkID": nil,
|
|
|
|
"walletSecretsConfig": map[string]interface{}{
|
|
|
|
"poktToken": "1234567890",
|
|
|
|
"infuraToken": "1234567890",
|
|
|
|
"infuraSecret": "",
|
|
|
|
"openseaApiKey": "",
|
|
|
|
"raribleMainnetApiKey": "",
|
|
|
|
"raribleTestnetApiKey": "",
|
|
|
|
"alchemyEthereumMainnetToken": "",
|
|
|
|
"alchemyEthereumGoerliToken": "",
|
|
|
|
"alchemyEthereumSepoliaToken": "",
|
|
|
|
"alchemyArbitrumMainnetToken": "",
|
|
|
|
"alchemyArbitrumGoerliToken": "",
|
|
|
|
"alchemyArbitrumSepoliaToken": "",
|
|
|
|
"alchemyOptimismMainnetToken": "",
|
|
|
|
"alchemyOptimismGoerliToken": "",
|
|
|
|
"alchemyOptimismSepoliaToken": "",
|
|
|
|
},
|
|
|
|
"torrentConfigEnabled": false,
|
|
|
|
"torrentConfigPort": 0,
|
|
|
|
"keycardInstanceUID": "a84599394887b742eed9a99d3834a797",
|
|
|
|
"keycardPairingDataFile": path.Join(tmpdir, DefaultKeycardPairingDataFile),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NotNil(t, exampleKeycardEvent)
|
|
|
|
require.NotNil(t, exampleRequest)
|
|
|
|
|
|
|
|
conf, err := params.NewNodeConfig(tmpdir, 1777)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
backend := NewGethStatusBackend()
|
|
|
|
|
|
|
|
require.NoError(t, backend.AccountManager().InitKeystore(conf.KeyStoreDir))
|
|
|
|
backend.UpdateRootDataDir(conf.DataDir)
|
|
|
|
|
|
|
|
require.NoError(t, backend.OpenAccounts())
|
|
|
|
|
|
|
|
keycardPairingDataFile := exampleRequest["createAccountRequest"].(map[string]interface{})["keycardPairingDataFile"].(string)
|
|
|
|
|
|
|
|
kp := wallet.NewKeycardPairings()
|
|
|
|
kp.SetKeycardPairingsFile(keycardPairingDataFile)
|
|
|
|
|
|
|
|
err = kp.SetPairingsJSONFileContent([]byte(`{"a84599394887b742eed9a99d3834a797":{"key":"785d52957b05482477728380d9b4bbb5dc9a8ed978ab4a4098e1a279c855d3c6","index":1}}`))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
request := &requests.RestoreAccount{
|
|
|
|
Keycard: &requests.KeycardData{
|
|
|
|
KeyUID: exampleKeycardEvent["keyUid"].(string),
|
|
|
|
Address: exampleKeycardEvent["masterKey"].(map[string]interface{})["address"].(string),
|
|
|
|
WhisperPrivateKey: exampleKeycardEvent["whisperKey"].(map[string]interface{})["privateKey"].(string),
|
|
|
|
WhisperPublicKey: exampleKeycardEvent["whisperKey"].(map[string]interface{})["publicKey"].(string),
|
|
|
|
WhisperAddress: exampleKeycardEvent["whisperKey"].(map[string]interface{})["address"].(string),
|
|
|
|
WalletPublicKey: exampleKeycardEvent["walletKey"].(map[string]interface{})["publicKey"].(string),
|
|
|
|
WalletAddress: exampleKeycardEvent["walletKey"].(map[string]interface{})["address"].(string),
|
|
|
|
WalletRootAddress: exampleKeycardEvent["walletRootKey"].(map[string]interface{})["address"].(string),
|
|
|
|
Eip1581Address: exampleKeycardEvent["eip1581Key"].(map[string]interface{})["address"].(string),
|
|
|
|
EncryptionPublicKey: exampleKeycardEvent["encryptionKey"].(map[string]interface{})["publicKey"].(string),
|
|
|
|
},
|
|
|
|
CreateAccount: requests.CreateAccount{
|
|
|
|
DisplayName: "User-1",
|
|
|
|
Password: "password123",
|
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
RootDataDir: tmpdir,
|
|
|
|
KeycardInstanceUID: exampleKeycardEvent["instanceUID"].(string),
|
|
|
|
KeycardPairingDataFile: &keycardPairingDataFile,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
acc, err := backend.RestoreKeycardAccountAndLogin(request)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, acc)
|
|
|
|
}
|