Skip to content

Commit 192c803

Browse files
committed
feat: add warning message when allow_unparsable_block is activated
1 parent a23ffad commit 192c803

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

mithril-common/src/cardano_transaction_parser.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use anyhow::{anyhow, Context};
1111
use async_trait::async_trait;
1212
use pallas_hardano::storage::immutable::chunk::{read_blocks, Reader};
1313
use pallas_traverse::MultiEraBlock;
14-
use slog::{error, Logger};
14+
use slog::{error, warn, Logger};
1515
use std::path::Path;
1616
use tokio::sync::RwLock;
1717

@@ -131,6 +131,12 @@ pub struct CardanoTransactionParser {
131131
impl CardanoTransactionParser {
132132
/// Factory
133133
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+
134140
Self {
135141
logger,
136142
allow_unparsable_block,
@@ -372,4 +378,36 @@ mod tests {
372378

373379
assert_eq!(transactions.len(), tx_count);
374380
}
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+
}
375413
}

0 commit comments

Comments
 (0)