@@ -19,15 +19,91 @@ import (
1919 "github.com/status-im/status-go/t/helpers"
2020)
2121
22- func setupTestDB (t * testing.T ) ( * sql.DB , func ()) {
22+ func setupTestDB (t * testing.T ) * sql.DB {
2323 db , cleanup , err := helpers .SetupTestSQLDB (DbInitializer {}, "settings-tests-" )
2424 require .NoError (t , err )
25- return db , func () { require .NoError (t , cleanup ()) }
25+
26+ t .Cleanup (func () { require .NoError (t , cleanup ()) })
27+ return db
28+ }
29+
30+ func randomNodeConfig () * params.NodeConfig {
31+ return & params.NodeConfig {
32+ NetworkID : uint64 (int64 (randomInt (math .MaxInt64 ))),
33+ DataDir : randomString (),
34+ NodeKey : randomString (),
35+ APIModules : randomString (),
36+ WalletConfig : params.WalletConfig {Enabled : randomBool ()},
37+ BrowsersConfig : params.BrowsersConfig {Enabled : randomBool ()},
38+ PermissionsConfig : params.PermissionsConfig {Enabled : randomBool ()},
39+ ConnectorConfig : params.ConnectorConfig {Enabled : randomBool ()},
40+ HTTPEnabled : randomBool (),
41+ HTTPHost : randomString (),
42+ HTTPPort : randomInt (math .MaxInt64 ),
43+ HTTPVirtualHosts : randomStringSlice (),
44+ HTTPCors : randomStringSlice (),
45+ WSEnabled : false , // NOTE: leaving ws field idle since we are moving away from the storing the whole config
46+ WSHost : "" ,
47+ WSPort : 0 ,
48+ IPCEnabled : randomBool (),
49+ IPCFile : randomString (),
50+ LogEnabled : randomBool (),
51+ LogDir : randomString (),
52+ LogFile : randomString (),
53+ LogLevel : randomString (),
54+ LogMaxBackups : randomInt (math .MaxInt64 ),
55+ LogMaxSize : randomInt (math .MaxInt64 ),
56+ LogCompressRotated : randomBool (),
57+ LogToStderr : randomBool (),
58+ ClusterConfig : params.ClusterConfig {
59+ Enabled : randomBool (),
60+ Fleet : randomString (),
61+ StaticNodes : randomStringSlice (),
62+ BootNodes : randomStringSlice (),
63+ },
64+ ShhextConfig : params.ShhextConfig {
65+ PFSEnabled : randomBool (),
66+ InstallationID : randomString (),
67+ MailServerConfirmations : randomBool (),
68+ EnableConnectionManager : randomBool (),
69+ EnableLastUsedMonitor : randomBool (),
70+ ConnectionTarget : randomInt (math .MaxInt64 ),
71+ RequestsDelay : time .Duration (randomInt (math .MaxInt64 )),
72+ MaxServerFailures : randomInt (math .MaxInt64 ),
73+ MaxMessageDeliveryAttempts : randomInt (math .MaxInt64 ),
74+ WhisperCacheDir : randomString (),
75+ DisableGenericDiscoveryTopic : randomBool (),
76+ SendV1Messages : randomBool (),
77+ DataSyncEnabled : randomBool (),
78+ VerifyTransactionURL : randomString (),
79+ VerifyENSURL : randomString (),
80+ VerifyENSContractAddress : randomString (),
81+ VerifyTransactionChainID : int64 (randomInt (math .MaxInt64 )),
82+ AnonMetricsSendID : randomString (),
83+ AnonMetricsServerEnabled : randomBool (),
84+ AnonMetricsServerPostgresURI : randomString (),
85+ BandwidthStatsEnabled : randomBool (),
86+ },
87+ WakuV2Config : params.WakuV2Config {
88+ Enabled : randomBool (),
89+ Host : randomString (),
90+ Port : randomInt (math .MaxInt64 ),
91+ LightClient : randomBool (),
92+ FullNode : randomBool (),
93+ DiscoveryLimit : randomInt (math .MaxInt64 ),
94+ DataDir : randomString (),
95+ MaxMessageSize : uint32 (randomInt (math .MaxInt64 )),
96+ EnableConfirmations : randomBool (),
97+ CustomNodes : randomCustomNodes (),
98+ EnableDiscV5 : randomBool (),
99+ UDPPort : randomInt (math .MaxInt64 ),
100+ AutoUpdate : randomBool (),
101+ },
102+ }
26103}
27104
28105func TestGetNodeConfig (t * testing.T ) {
29- db , stop := setupTestDB (t )
30- defer stop ()
106+ db := setupTestDB (t )
31107
32108 nodeConfig := randomNodeConfig ()
33109 require .NoError (t , nodecfg .SaveNodeConfig (db , nodeConfig ))
@@ -38,22 +114,19 @@ func TestGetNodeConfig(t *testing.T) {
38114}
39115
40116func TestSaveNodeConfig (t * testing.T ) {
41- db , stop := setupTestDB (t )
42- defer stop ()
43-
44- newNodeConfig := randomNodeConfig ()
117+ db := setupTestDB (t )
45118
46- require .NoError (t , nodecfg .SaveNodeConfig (db , newNodeConfig ))
119+ nodeConfig := randomNodeConfig ()
120+ require .NoError (t , nodecfg .SaveNodeConfig (db , nodeConfig ))
47121
48122 dbNodeConfig , err := nodecfg .GetNodeConfigFromDB (db )
49123 require .NoError (t , err )
50- require .Equal (t , * newNodeConfig , * dbNodeConfig )
124+ require .Equal (t , * nodeConfig , * dbNodeConfig )
51125}
52126
53127func TestMigrateNodeConfig (t * testing.T ) {
54128 // Migration will be run in setupTestDB. If there's an error, that function will fail
55- db , stop := setupTestDB (t )
56- defer stop ()
129+ db := setupTestDB (t )
57130
58131 // node_config column should be empty
59132 var result string
@@ -114,86 +187,9 @@ func randomCustomNodes() map[string]string {
114187 return result
115188}
116189
117- func randomNodeConfig () * params.NodeConfig {
118- return & params.NodeConfig {
119- NetworkID : uint64 (int64 (randomInt (math .MaxInt64 ))),
120- DataDir : randomString (),
121- NodeKey : randomString (),
122- APIModules : randomString (),
123- WalletConfig : params.WalletConfig {Enabled : randomBool ()},
124- BrowsersConfig : params.BrowsersConfig {Enabled : randomBool ()},
125- PermissionsConfig : params.PermissionsConfig {Enabled : randomBool ()},
126- MailserversConfig : params.MailserversConfig {Enabled : randomBool ()},
127- ConnectorConfig : params.ConnectorConfig {Enabled : randomBool ()},
128- HTTPEnabled : randomBool (),
129- HTTPHost : randomString (),
130- HTTPPort : randomInt (math .MaxInt64 ),
131- HTTPVirtualHosts : randomStringSlice (),
132- HTTPCors : randomStringSlice (),
133- WSEnabled : false , // NOTE: leaving ws field idle since we are moving away from the storing the whole config
134- WSHost : "" ,
135- WSPort : 0 ,
136- IPCEnabled : randomBool (),
137- IPCFile : randomString (),
138- LogEnabled : randomBool (),
139- LogDir : randomString (),
140- LogFile : randomString (),
141- LogLevel : randomString (),
142- LogMaxBackups : randomInt (math .MaxInt64 ),
143- LogMaxSize : randomInt (math .MaxInt64 ),
144- LogCompressRotated : randomBool (),
145- LogToStderr : randomBool (),
146- ClusterConfig : params.ClusterConfig {
147- Enabled : randomBool (),
148- Fleet : randomString (),
149- StaticNodes : randomStringSlice (),
150- BootNodes : randomStringSlice (),
151- },
152- ShhextConfig : params.ShhextConfig {
153- PFSEnabled : randomBool (),
154- InstallationID : randomString (),
155- MailServerConfirmations : randomBool (),
156- EnableConnectionManager : randomBool (),
157- EnableLastUsedMonitor : randomBool (),
158- ConnectionTarget : randomInt (math .MaxInt64 ),
159- RequestsDelay : time .Duration (randomInt (math .MaxInt64 )),
160- MaxServerFailures : randomInt (math .MaxInt64 ),
161- MaxMessageDeliveryAttempts : randomInt (math .MaxInt64 ),
162- WhisperCacheDir : randomString (),
163- DisableGenericDiscoveryTopic : randomBool (),
164- SendV1Messages : randomBool (),
165- DataSyncEnabled : randomBool (),
166- VerifyTransactionURL : randomString (),
167- VerifyENSURL : randomString (),
168- VerifyENSContractAddress : randomString (),
169- VerifyTransactionChainID : int64 (randomInt (math .MaxInt64 )),
170- AnonMetricsSendID : randomString (),
171- AnonMetricsServerEnabled : randomBool (),
172- AnonMetricsServerPostgresURI : randomString (),
173- BandwidthStatsEnabled : randomBool (),
174- },
175- WakuV2Config : params.WakuV2Config {
176- Enabled : randomBool (),
177- Host : randomString (),
178- Port : randomInt (math .MaxInt64 ),
179- LightClient : randomBool (),
180- FullNode : randomBool (),
181- DiscoveryLimit : randomInt (math .MaxInt64 ),
182- DataDir : randomString (),
183- MaxMessageSize : uint32 (randomInt (math .MaxInt64 )),
184- EnableConfirmations : randomBool (),
185- CustomNodes : randomCustomNodes (),
186- EnableDiscV5 : randomBool (),
187- UDPPort : randomInt (math .MaxInt64 ),
188- AutoUpdate : randomBool (),
189- },
190- }
191- }
192-
193190func TestConfigValidate (t * testing.T ) {
194191 // GIVEN
195- db , stop := setupTestDB (t )
196- defer stop ()
192+ db := setupTestDB (t )
197193
198194 tmpdir := t .TempDir ()
199195 nodeConfig , err := params .NewNodeConfig (tmpdir , 1777 )
@@ -212,8 +208,7 @@ func TestConfigValidate(t *testing.T) {
212208
213209func TestRepairLoadedTorrentConfig (t * testing.T ) {
214210 // GIVEN
215- db , stop := setupTestDB (t )
216- defer stop ()
211+ db := setupTestDB (t )
217212
218213 tmpdir := t .TempDir ()
219214 nodeConfig , err := params .NewNodeConfig (tmpdir , 1777 )
0 commit comments