8
8
#![ cfg( any( test, cln_test, vss_test) ) ]
9
9
#![ allow( dead_code) ]
10
10
11
- use ldk_node:: config:: { Config , EsploraSyncConfig } ;
11
+ use ldk_node:: config:: {
12
+ Config , EsploraSyncConfig , DEFAULT_LOG_FILENAME , DEFAULT_LOG_LEVEL , DEFAULT_STORAGE_DIR_PATH ,
13
+ } ;
12
14
use ldk_node:: io:: sqlite_store:: SqliteStore ;
13
- use ldk_node:: logger:: LogLevel ;
15
+ use ldk_node:: logger:: { LogLevel , LogWriter } ;
14
16
use ldk_node:: payment:: { PaymentDirection , PaymentKind , PaymentStatus } ;
15
17
use ldk_node:: {
16
18
Builder , CustomTlvRecord , Event , LightningBalance , Node , NodeError , PendingSweepBalance ,
@@ -215,7 +217,7 @@ pub(crate) fn random_node_alias() -> Option<NodeAlias> {
215
217
Some ( NodeAlias ( bytes) )
216
218
}
217
219
218
- pub ( crate ) fn random_config ( anchor_channels : bool ) -> Config {
220
+ pub ( crate ) fn random_config ( anchor_channels : bool ) -> TestConfig {
219
221
let mut config = Config :: default ( ) ;
220
222
221
223
if !anchor_channels {
@@ -237,7 +239,7 @@ pub(crate) fn random_config(anchor_channels: bool) -> Config {
237
239
println ! ( "Setting random LDK node alias: {:?}" , alias) ;
238
240
config. node_alias = alias;
239
241
240
- config
242
+ TestConfig { node_config : config, log_writer : TestLogWriter :: default ( ) }
241
243
}
242
244
243
245
#[ cfg( feature = "uniffi" ) ]
@@ -251,6 +253,34 @@ pub(crate) enum TestChainSource<'a> {
251
253
BitcoindRpc ( & ' a BitcoinD ) ,
252
254
}
253
255
256
+ #[ derive( Clone ) ]
257
+ pub ( crate ) enum TestLogWriter {
258
+ FileWriter { file_path : String , max_log_level : LogLevel } ,
259
+ LogFacade { max_log_level : LogLevel } ,
260
+ Custom ( Arc < dyn LogWriter > ) ,
261
+ }
262
+
263
+ impl Default for TestLogWriter {
264
+ fn default ( ) -> Self {
265
+ TestLogWriter :: FileWriter {
266
+ file_path : format ! ( "{}/{}" , DEFAULT_STORAGE_DIR_PATH , DEFAULT_LOG_FILENAME ) ,
267
+ max_log_level : DEFAULT_LOG_LEVEL ,
268
+ }
269
+ }
270
+ }
271
+
272
+ #[ derive( Clone ) ]
273
+ pub ( crate ) struct TestConfig {
274
+ pub node_config : Config ,
275
+ pub log_writer : TestLogWriter ,
276
+ }
277
+
278
+ impl Default for TestConfig {
279
+ fn default ( ) -> Self {
280
+ Self { node_config : Config :: default ( ) , log_writer : TestLogWriter :: default ( ) }
281
+ }
282
+ }
283
+
254
284
macro_rules! setup_builder {
255
285
( $builder: ident, $config: expr) => {
256
286
#[ cfg( feature = "uniffi" ) ]
@@ -273,10 +303,11 @@ pub(crate) fn setup_two_nodes(
273
303
println ! ( "\n == Node B ==" ) ;
274
304
let mut config_b = random_config ( anchor_channels) ;
275
305
if allow_0conf {
276
- config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
306
+ config_b. node_config . trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
277
307
}
278
308
if anchor_channels && anchors_trusted_no_reserve {
279
309
config_b
310
+ . node_config
280
311
. anchor_channels_config
281
312
. as_mut ( )
282
313
. unwrap ( )
@@ -288,9 +319,9 @@ pub(crate) fn setup_two_nodes(
288
319
}
289
320
290
321
pub ( crate ) fn setup_node (
291
- chain_source : & TestChainSource , config : Config , seed_bytes : Option < Vec < u8 > > ,
322
+ chain_source : & TestChainSource , config : TestConfig , seed_bytes : Option < Vec < u8 > > ,
292
323
) -> TestNode {
293
- setup_builder ! ( builder, config) ;
324
+ setup_builder ! ( builder, config. node_config ) ;
294
325
match chain_source {
295
326
TestChainSource :: Esplora ( electrsd) => {
296
327
let esplora_url = format ! ( "http://{}" , electrsd. esplora_url. as_ref( ) . unwrap( ) ) ;
@@ -309,14 +340,23 @@ pub(crate) fn setup_node(
309
340
} ,
310
341
}
311
342
312
- let log_file_path = format ! ( "{}/{}" , config. storage_dir_path, "ldk_node.log" ) ;
313
- builder. set_filesystem_logger ( Some ( log_file_path) , Some ( LogLevel :: Gossip ) ) ;
343
+ match & config. log_writer {
344
+ TestLogWriter :: FileWriter { file_path, max_log_level } => {
345
+ builder. set_filesystem_logger ( Some ( file_path. clone ( ) ) , Some ( * max_log_level) ) ;
346
+ } ,
347
+ TestLogWriter :: LogFacade { max_log_level } => {
348
+ builder. set_log_facade_logger ( Some ( * max_log_level) ) ;
349
+ } ,
350
+ TestLogWriter :: Custom ( custom_log_writer) => {
351
+ builder. set_custom_logger ( Arc :: clone ( custom_log_writer) ) ;
352
+ } ,
353
+ }
314
354
315
355
if let Some ( seed) = seed_bytes {
316
356
builder. set_entropy_seed_bytes ( seed) . unwrap ( ) ;
317
357
}
318
358
319
- let test_sync_store = Arc :: new ( TestSyncStore :: new ( config. storage_dir_path . into ( ) ) ) ;
359
+ let test_sync_store = Arc :: new ( TestSyncStore :: new ( config. node_config . storage_dir_path . into ( ) ) ) ;
320
360
let node = builder. build_with_store ( test_sync_store) . unwrap ( ) ;
321
361
node. start ( ) . unwrap ( ) ;
322
362
assert ! ( node. status( ) . is_running) ;
0 commit comments