Skip to content

Commit a07aaec

Browse files
committed
chore_: fix test
1 parent 54eecad commit a07aaec

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

kvstore/database_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,27 @@ type DbInitializer struct {
1414
}
1515

1616
func (a DbInitializer) Initialize(path, password string, kdfIterationsNumber int) (*sql.DB, error) {
17-
return sqlite.OpenDB(path, password, kdfIterationsNumber)
17+
db, err := sqlite.OpenDB(path, password, kdfIterationsNumber)
18+
if err != nil {
19+
return nil, err
20+
}
21+
22+
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS kv_store (
23+
key TEXT PRIMARY KEY,
24+
value BLOB
25+
);`)
26+
27+
if err != nil {
28+
return nil, err
29+
}
30+
31+
return db, nil
1832
}
1933

2034
func setupTestDB(t *testing.T) (*Database, func()) {
21-
db, cleanup, err := helpers.SetupTestSQLDB(DbInitializer{}, "kvstore-tests")
35+
db, err := helpers.SetupTestMemorySQLDB(DbInitializer{})
2236
require.NoError(t, err)
23-
return NewDB(db), func() { require.NoError(t, cleanup()) }
37+
return NewDB(db), func() { require.NoError(t, db.Close()) }
2438
}
2539

2640
func TestSetGetDelete(t *testing.T) {

protocol/messenger_base_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88

99
"go.uber.org/zap"
1010

11+
"github.com/status-im/status-go/appdatabase"
1112
"github.com/status-im/status-go/eth-node/crypto"
1213
"github.com/status-im/status-go/multiaccounts/settings"
1314
"github.com/status-im/status-go/params"
1415
"github.com/status-im/status-go/protocol/tt"
16+
"github.com/status-im/status-go/t/helpers"
1517
"github.com/status-im/status-go/wakuv2"
1618

1719
wakutypes "github.com/status-im/status-go/waku/types"
@@ -85,11 +87,15 @@ func newMessengerWithKey(shh wakutypes.Waku, privateKey *ecdsa.PrivateKey, logge
8587
}
8688

8789
func newTestWakuNode(logger *zap.Logger) (wakutypes.Waku, error) {
90+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
91+
if err != nil {
92+
return nil, err
93+
}
8894
return wakuv2.New(
8995
nil,
9096
&wakuv2.DefaultConfig,
9197
logger,
92-
nil,
98+
db,
9399
nil,
94100
func([]byte, peer.AddrInfo, error) {},
95101
nil,

server/pairing/sync_device_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/stretchr/testify/suite"
2121

2222
"github.com/status-im/status-go/api"
23+
"github.com/status-im/status-go/appdatabase"
2324
"github.com/status-im/status-go/common/dbsetup"
2425
"github.com/status-im/status-go/eth-node/crypto"
2526
"github.com/status-im/status-go/eth-node/types"
@@ -33,6 +34,7 @@ import (
3334
"github.com/status-im/status-go/protocol/tt"
3435
accservice "github.com/status-im/status-go/services/accounts"
3536
"github.com/status-im/status-go/services/browsers"
37+
"github.com/status-im/status-go/t/helpers"
3638
"github.com/status-im/status-go/wakuv2"
3739
)
3840

@@ -85,8 +87,10 @@ func (s *SyncDeviceSuite) SetupTest() {
8587
DefaultShardPubsubTopic: wakuv2.DefaultShardPubsubTopic(),
8688
EnableStoreConfirmationForMessagesSent: false,
8789
}
88-
var err error
89-
s.pxBootNode, err = wakuv2.New(nil, exchangeNodeConfig, s.logger.Named("pxServerNode"), nil, nil, nil, nil)
90+
91+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
92+
s.Require().NoError(err)
93+
s.pxBootNode, err = wakuv2.New(nil, exchangeNodeConfig, s.logger.Named("pxServerNode"), db, nil, nil, nil)
9094
s.Require().NoError(err)
9195
s.Require().NoError(s.pxBootNode.Start())
9296

wakuv2/waku_test.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ func TestDiscoveryV5(t *testing.T) {
6666
setDefaultConfig(config, false)
6767
config.DiscV5BootstrapNodes = []string{testStoreENRBootstrap}
6868
config.DiscoveryLimit = 20
69-
w, err := New(nil, config, nil, nil, nil, nil, nil)
69+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
70+
require.NoError(t, err)
71+
w, err := New(nil, config, nil, db, nil, nil, nil)
7072
require.NoError(t, err)
7173

7274
require.NoError(t, w.Start())
@@ -92,7 +94,9 @@ func TestRestartDiscoveryV5(t *testing.T) {
9294
config.DiscoveryLimit = 20
9395
config.UDPPort = 10002
9496
config.ClusterID = 16
95-
w, err := New(nil, config, nil, nil, nil, nil, nil)
97+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
98+
require.NoError(t, err)
99+
w, err := New(nil, config, nil, db, nil, nil, nil)
96100
require.NoError(t, err)
97101

98102
require.NoError(t, w.Start())
@@ -135,8 +139,10 @@ func TestRelayPeers(t *testing.T) {
135139
config := &Config{
136140
EnableMissingMessageVerification: true,
137141
}
142+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
143+
require.NoError(t, err)
138144
setDefaultConfig(config, false)
139-
w, err := New(nil, config, nil, nil, nil, nil, nil)
145+
w, err := New(nil, config, nil, db, nil, nil, nil)
140146
require.NoError(t, err)
141147
require.NoError(t, w.Start())
142148
_, err = w.RelayPeersByTopic(config.DefaultShardPubsubTopic)
@@ -146,7 +152,7 @@ func TestRelayPeers(t *testing.T) {
146152
config = &Config{}
147153
config.ClusterID = 16
148154
config.LightClient = true
149-
w, err = New(nil, config, nil, nil, nil, nil, nil)
155+
w, err = New(nil, config, nil, db, nil, nil, nil)
150156
require.NoError(t, err)
151157
require.NoError(t, w.Start())
152158
_, err = w.RelayPeersByTopic(config.DefaultShardPubsubTopic)
@@ -194,7 +200,9 @@ func TestBasicWakuV2(t *testing.T) {
194200
config.DiscV5BootstrapNodes = []string{enrTreeAddress}
195201
config.DiscoveryLimit = 20
196202
config.WakuNodes = []string{enrTreeAddress}
197-
w, err := New(nil, config, nil, nil, nil, nil, nil)
203+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
204+
require.NoError(t, err)
205+
w, err := New(nil, config, nil, db, nil, nil, nil)
198206
require.NoError(t, err)
199207
require.NoError(t, w.Start())
200208

@@ -334,7 +342,9 @@ func TestPeerExchange(t *testing.T) {
334342
config.EnableDiscV5 = true
335343
config.EnablePeerExchangeServer = true
336344
config.EnablePeerExchangeClient = false
337-
pxServerNode, err := New(nil, config, logger.Named("pxServerNode"), nil, nil, nil, nil)
345+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
346+
require.NoError(t, err)
347+
pxServerNode, err := New(nil, config, logger.Named("pxServerNode"), db, nil, nil, nil)
338348
require.NoError(t, err)
339349
require.NoError(t, pxServerNode.Start())
340350

@@ -347,7 +357,7 @@ func TestPeerExchange(t *testing.T) {
347357
config.EnablePeerExchangeServer = false
348358
config.EnablePeerExchangeClient = false
349359
config.DiscV5BootstrapNodes = []string{pxServerNode.node.ENR().String()}
350-
discV5Node, err := New(nil, config, logger.Named("discV5Node"), nil, nil, nil, nil)
360+
discV5Node, err := New(nil, config, logger.Named("discV5Node"), db, nil, nil, nil)
351361
require.NoError(t, err)
352362
require.NoError(t, discV5Node.Start())
353363

@@ -366,7 +376,7 @@ func TestPeerExchange(t *testing.T) {
366376
config.Resolver = resolver
367377

368378
config.WakuNodes = []string{url}
369-
lightNode, err := New(nil, config, logger.Named("lightNode"), nil, nil, nil, nil)
379+
lightNode, err := New(nil, config, logger.Named("lightNode"), db, nil, nil, nil)
370380
require.NoError(t, err)
371381
require.NoError(t, lightNode.Start())
372382

@@ -636,7 +646,9 @@ func waitForEnvelope(t *testing.T, contentTopic string, envCh chan common.Envelo
636646
}
637647

638648
func TestOnlineChecker(t *testing.T) {
639-
w, err := New(nil, nil, nil, nil, nil, nil, nil)
649+
db, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
650+
require.NoError(t, err)
651+
w, err := New(nil, nil, nil, db, nil, nil, nil)
640652
require.NoError(t, w.Start())
641653

642654
require.NoError(t, err)
@@ -662,7 +674,7 @@ func TestOnlineChecker(t *testing.T) {
662674
config := &Config{}
663675
config.ClusterID = 16
664676
config.LightClient = true
665-
lightNode, err := New(nil, config, nil, nil, nil, nil, nil)
677+
lightNode, err := New(nil, config, nil, db, nil, nil, nil)
666678
require.NoError(t, err)
667679

668680
err = lightNode.Start()

0 commit comments

Comments
 (0)