@@ -11,7 +11,7 @@ use anyhow::{anyhow, Context};
11
11
use async_trait:: async_trait;
12
12
use pallas_hardano:: storage:: immutable:: chunk:: { read_blocks, Reader } ;
13
13
use pallas_traverse:: MultiEraBlock ;
14
- use slog:: { error, Logger } ;
14
+ use slog:: { error, warn , Logger } ;
15
15
use std:: path:: Path ;
16
16
use tokio:: sync:: RwLock ;
17
17
@@ -131,6 +131,12 @@ pub struct CardanoTransactionParser {
131
131
impl CardanoTransactionParser {
132
132
/// Factory
133
133
pub fn new ( logger : Logger , allow_unparsable_block : bool ) -> Self {
134
+ if allow_unparsable_block {
135
+ warn ! (
136
+ logger,
137
+ "The 'allow_unparsable_block' option is activated. This option should only be used on test networks." )
138
+ }
139
+
134
140
Self {
135
141
logger,
136
142
allow_unparsable_block,
@@ -372,4 +378,36 @@ mod tests {
372
378
373
379
assert_eq ! ( transactions. len( ) , tx_count) ;
374
380
}
381
+
382
+ #[ tokio:: test]
383
+ async fn test_instantiate_parser_with_allow_unparsable_block_should_log_warning ( ) {
384
+ let temp_dir = TempDir :: create (
385
+ "cardano_transaction_parser" ,
386
+ "test_instantiate_parser_with_allow_unparsable_block_should_log_warning" ,
387
+ ) ;
388
+ let filepath = temp_dir. join ( "test.log" ) ;
389
+ // We create a block to drop the logger and force a flush before we read the log file.
390
+ {
391
+ let _ = CardanoTransactionParser :: new ( create_file_logger ( & filepath) , true ) ;
392
+ }
393
+
394
+ let log_file = std:: fs:: read_to_string ( & filepath) . unwrap ( ) ;
395
+ assert ! ( log_file. contains( "The 'allow_unparsable_block' option is activated. This option should only be used on test networks." ) ) ;
396
+ }
397
+
398
+ #[ tokio:: test]
399
+ async fn test_instantiate_parser_without_allow_unparsable_block_should_not_log_warning ( ) {
400
+ let temp_dir = TempDir :: create (
401
+ "cardano_transaction_parser" ,
402
+ "test_instantiate_parser_without_allow_unparsable_block_should_not_log_warning" ,
403
+ ) ;
404
+ let filepath = temp_dir. join ( "test.log" ) ;
405
+ // We create a block to drop the logger and force a flush before we read the log file.
406
+ {
407
+ let _ = CardanoTransactionParser :: new ( create_file_logger ( & filepath) , false ) ;
408
+ }
409
+
410
+ let log_file = std:: fs:: read_to_string ( & filepath) . unwrap ( ) ;
411
+ assert ! ( !log_file. contains( "The 'allow_unparsable_block' option is activated. This option should only be used on test networks." ) ) ;
412
+ }
375
413
}
0 commit comments