@@ -19,6 +19,7 @@ import (
19
19
20
20
"github.com/stretchr/testify/assert"
21
21
"github.com/stretchr/testify/require"
22
+ "go.uber.org/zap"
22
23
23
24
gethcrypto "github.com/ethereum/go-ethereum/crypto"
24
25
@@ -90,12 +91,23 @@ func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
90
91
}, nil
91
92
}
92
93
94
+ func newGethStatusBackend () (* GethStatusBackend , error ) {
95
+ logger , err := zap .NewDevelopment ()
96
+ if err != nil {
97
+ return nil , err
98
+ }
99
+ return NewGethStatusBackend (logger ), nil
100
+ }
101
+
93
102
func setupGethStatusBackend () (* GethStatusBackend , func () error , func () error , func () error , error ) {
94
103
db , stop1 , err := setupTestDB ()
95
104
if err != nil {
96
105
return nil , nil , nil , nil , err
97
106
}
98
- backend := NewGethStatusBackend ()
107
+ backend , err := newGethStatusBackend ()
108
+ if err != nil {
109
+ return nil , nil , nil , nil , err
110
+ }
99
111
backend .StatusNode ().SetAppDB (db )
100
112
101
113
ma , stop2 , err := setupTestMultiDB ()
@@ -292,7 +304,9 @@ func TestBackendGettersConcurrently(t *testing.T) {
292
304
293
305
func TestBackendConnectionChangesConcurrently (t * testing.T ) {
294
306
connections := [... ]string {connection .Wifi , connection .Cellular , connection .Unknown }
295
- backend := NewGethStatusBackend ()
307
+ backend , err := newGethStatusBackend ()
308
+ require .NoError (t , err )
309
+
296
310
count := 3
297
311
298
312
var wg sync.WaitGroup
@@ -310,7 +324,9 @@ func TestBackendConnectionChangesConcurrently(t *testing.T) {
310
324
}
311
325
312
326
func TestBackendConnectionChangesToOffline (t * testing.T ) {
313
- b := NewGethStatusBackend ()
327
+ b , err := newGethStatusBackend ()
328
+ require .NoError (t , err )
329
+
314
330
b .ConnectionChange (connection .None , false )
315
331
assert .True (t , b .connectionState .Offline )
316
332
@@ -386,7 +402,8 @@ func TestBackendCallRPCConcurrently(t *testing.T) {
386
402
}
387
403
388
404
func TestAppStateChange (t * testing.T ) {
389
- backend := NewGethStatusBackend ()
405
+ backend , err := newGethStatusBackend ()
406
+ require .NoError (t , err )
390
407
391
408
var testCases = []struct {
392
409
name string
@@ -460,7 +477,8 @@ func TestBlockedRPCMethods(t *testing.T) {
460
477
}
461
478
462
479
func TestCallRPCWithStoppedNode (t * testing.T ) {
463
- backend := NewGethStatusBackend ()
480
+ backend , err := newGethStatusBackend ()
481
+ require .NoError (t , err )
464
482
465
483
resp , err := backend .CallRPC (
466
484
`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}` ,
@@ -699,7 +717,9 @@ func TestBackendGetVerifiedAccount(t *testing.T) {
699
717
func TestRuntimeLogLevelIsNotWrittenToDatabase (t * testing.T ) {
700
718
utils .Init ()
701
719
702
- b := NewGethStatusBackend ()
720
+ b , err := newGethStatusBackend ()
721
+ require .NoError (t , err )
722
+
703
723
chatKey , err := gethcrypto .GenerateKey ()
704
724
require .NoError (t , err )
705
725
walletKey , err := gethcrypto .GenerateKey ()
@@ -767,7 +787,9 @@ func TestRuntimeLogLevelIsNotWrittenToDatabase(t *testing.T) {
767
787
func TestLoginWithKey (t * testing.T ) {
768
788
utils .Init ()
769
789
770
- b := NewGethStatusBackend ()
790
+ b , err := newGethStatusBackend ()
791
+ require .NoError (t , err )
792
+
771
793
chatKey , err := gethcrypto .GenerateKey ()
772
794
require .NoError (t , err )
773
795
walletKey , err := gethcrypto .GenerateKey ()
@@ -825,7 +847,9 @@ func TestLoginAccount(t *testing.T) {
825
847
tmpdir := t .TempDir ()
826
848
nameserver := "8.8.8.8"
827
849
828
- b := NewGethStatusBackend ()
850
+ b , err := newGethStatusBackend ()
851
+ require .NoError (t , err )
852
+
829
853
createAccountRequest := & requests.CreateAccount {
830
854
DisplayName : "some-display-name" ,
831
855
CustomizationColor : "#ffffff" ,
@@ -882,7 +906,9 @@ func TestLoginAccount(t *testing.T) {
882
906
func TestVerifyDatabasePassword (t * testing.T ) {
883
907
utils .Init ()
884
908
885
- b := NewGethStatusBackend ()
909
+ b , err := newGethStatusBackend ()
910
+ require .NoError (t , err )
911
+
886
912
chatKey , err := gethcrypto .GenerateKey ()
887
913
require .NoError (t , err )
888
914
walletKey , err := gethcrypto .GenerateKey ()
@@ -920,15 +946,16 @@ func TestVerifyDatabasePassword(t *testing.T) {
920
946
}
921
947
922
948
func TestDeleteMultiaccount (t * testing.T ) {
923
- backend := NewGethStatusBackend ()
949
+ backend , err := newGethStatusBackend ()
950
+ require .NoError (t , err )
924
951
925
952
rootDataDir := t .TempDir ()
926
953
927
954
keyStoreDir := filepath .Join (rootDataDir , "keystore" )
928
955
929
956
backend .rootDataDir = rootDataDir
930
957
931
- err : = backend .AccountManager ().InitKeystore (keyStoreDir )
958
+ err = backend .AccountManager ().InitKeystore (keyStoreDir )
932
959
require .NoError (t , err )
933
960
934
961
backend .AccountManager ()
@@ -1279,7 +1306,8 @@ func loginDesktopUser(t *testing.T, conf *params.NodeConfig) {
1279
1306
username := "TestUser"
1280
1307
passwd := "0xC888C9CE9E098D5864D3DED6EBCC140A12142263BACE3A23A36F9905F12BD64A" // #nosec G101
1281
1308
1282
- b := NewGethStatusBackend ()
1309
+ b , err := newGethStatusBackend ()
1310
+ require .NoError (t , err )
1283
1311
1284
1312
require .NoError (t , b .AccountManager ().InitKeystore (conf .KeyStoreDir ))
1285
1313
b .UpdateRootDataDir (conf .DataDir )
@@ -1328,7 +1356,8 @@ func TestChangeDatabasePassword(t *testing.T) {
1328
1356
oldPassword := "password"
1329
1357
newPassword := "newPassword"
1330
1358
1331
- backend := NewGethStatusBackend ()
1359
+ backend , err := newGethStatusBackend ()
1360
+ require .NoError (t , err )
1332
1361
backend .UpdateRootDataDir (t .TempDir ())
1333
1362
1334
1363
// Setup keystore to test decryption of it
@@ -1385,7 +1414,8 @@ func TestCreateWallet(t *testing.T) {
1385
1414
password := "some-password2" // nolint: goconst
1386
1415
tmpdir := t .TempDir ()
1387
1416
1388
- b := NewGethStatusBackend ()
1417
+ b , err := newGethStatusBackend ()
1418
+ require .NoError (t , err )
1389
1419
defer func () {
1390
1420
require .NoError (t , b .StopNode ())
1391
1421
}()
@@ -1450,7 +1480,8 @@ func TestSetFleet(t *testing.T) {
1450
1480
password := "some-password2" // nolint: goconst
1451
1481
tmpdir := t .TempDir ()
1452
1482
1453
- b := NewGethStatusBackend ()
1483
+ b , err := newGethStatusBackend ()
1484
+ require .NoError (t , err )
1454
1485
createAccountRequest := & requests.CreateAccount {
1455
1486
DisplayName : "some-display-name" ,
1456
1487
CustomizationColor : "#ffffff" ,
@@ -1519,7 +1550,8 @@ func TestWalletConfigOnLoginAccount(t *testing.T) {
1519
1550
raribleMainnetAPIKey := "rarible-mainnet-api-key" // nolint: gosec
1520
1551
raribleTestnetAPIKey := "rarible-testnet-api-key" // nolint: gosec
1521
1552
1522
- b := NewGethStatusBackend ()
1553
+ b , err := newGethStatusBackend ()
1554
+ require .NoError (t , err )
1523
1555
createAccountRequest := & requests.CreateAccount {
1524
1556
DisplayName : "some-display-name" ,
1525
1557
CustomizationColor : "#ffffff" ,
@@ -1584,7 +1616,8 @@ func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) {
1584
1616
utils .Init ()
1585
1617
tmpdir := t .TempDir ()
1586
1618
1587
- b := NewGethStatusBackend ()
1619
+ b , err := newGethStatusBackend ()
1620
+ require .NoError (t , err )
1588
1621
1589
1622
// Creating an account with test networks enabled
1590
1623
createAccountRequest1 := & requests.CreateAccount {
@@ -1595,7 +1628,7 @@ func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) {
1595
1628
LogFilePath : tmpdir + "/log" ,
1596
1629
TestNetworksEnabled : true ,
1597
1630
}
1598
- _ , err : = b .CreateAccountAndLogin (createAccountRequest1 )
1631
+ _ , err = b .CreateAccountAndLogin (createAccountRequest1 )
1599
1632
require .NoError (t , err )
1600
1633
statusNode := b .statusNode
1601
1634
require .NotNil (t , statusNode )
@@ -1630,7 +1663,8 @@ func TestRestoreAccountAndLogin(t *testing.T) {
1630
1663
utils .Init ()
1631
1664
tmpdir := t .TempDir ()
1632
1665
1633
- backend := NewGethStatusBackend ()
1666
+ backend , err := newGethStatusBackend ()
1667
+ require .NoError (t , err )
1634
1668
1635
1669
// Test case 1: Valid restore account request
1636
1670
restoreRequest := & requests.RestoreAccount {
@@ -1665,7 +1699,8 @@ func TestRestoreAccountAndLoginWithoutDisplayName(t *testing.T) {
1665
1699
utils .Init ()
1666
1700
tmpdir := t .TempDir ()
1667
1701
1668
- backend := NewGethStatusBackend ()
1702
+ backend , err := newGethStatusBackend ()
1703
+ require .NoError (t , err )
1669
1704
1670
1705
// Test case: Valid restore account request without DisplayName
1671
1706
restoreRequest := & requests.RestoreAccount {
@@ -1828,7 +1863,8 @@ func TestRestoreKeycardAccountAndLogin(t *testing.T) {
1828
1863
conf , err := params .NewNodeConfig (tmpdir , 1777 )
1829
1864
require .NoError (t , err )
1830
1865
1831
- backend := NewGethStatusBackend ()
1866
+ backend , err := newGethStatusBackend ()
1867
+ require .NoError (t , err )
1832
1868
1833
1869
require .NoError (t , backend .AccountManager ().InitKeystore (conf .KeyStoreDir ))
1834
1870
backend .UpdateRootDataDir (conf .DataDir )
0 commit comments