Skip to content

Commit 396ed9e

Browse files
committed
Handle lower bound in Transactions parser
1 parent bf7d1dd commit 396ed9e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

mithril-common/src/cardano_transaction_parser.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,20 @@ impl CardanoTransactionParser {
201201

202202
#[async_trait]
203203
impl TransactionParser for CardanoTransactionParser {
204-
// Todo: update implem to parse from the lower bound
205204
async fn parse(
206205
&self,
207206
dirpath: &Path,
208-
_from_immutable: Option<ImmutableFileNumber>,
207+
from_immutable: Option<ImmutableFileNumber>,
209208
until_immutable: ImmutableFileNumber,
210209
) -> StdResult<Vec<CardanoTransaction>> {
211210
let up_to_file_number = until_immutable;
211+
let is_in_bounds = |number: ImmutableFileNumber| match from_immutable {
212+
Some(from) => from <= number && number <= up_to_file_number,
213+
None => number <= up_to_file_number,
214+
};
212215
let immutable_chunks = ImmutableFile::list_completed_in_dir(dirpath)?
213216
.into_iter()
214-
.filter(|f| f.number <= up_to_file_number && f.filename.contains("chunk"))
217+
.filter(|f| is_in_bounds(f.number) && f.filename.contains("chunk"))
215218
.collect::<Vec<_>>();
216219
let mut transactions: Vec<CardanoTransaction> = vec![];
217220

@@ -295,7 +298,22 @@ mod tests {
295298

296299
#[tokio::test]
297300
async fn test_parse_from_lower_bound_until_upper_bound() {
298-
todo!()
301+
// We known the number of transactions in those prebuilt immutables
302+
let immutable_files = [("00002", 3)];
303+
let db_path = Path::new("../mithril-test-lab/test_data/immutable/");
304+
assert!(get_number_of_immutable_chunk_in_dir(db_path) >= 3);
305+
306+
let until_immutable_file = 2;
307+
let tx_count: usize = immutable_files.iter().map(|(_, count)| *count).sum();
308+
let cardano_transaction_parser =
309+
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()), false);
310+
311+
let transactions = cardano_transaction_parser
312+
.parse(db_path, Some(2), until_immutable_file)
313+
.await
314+
.unwrap();
315+
316+
assert_eq!(transactions.len(), tx_count);
299317
}
300318

301319
#[tokio::test]

0 commit comments

Comments
 (0)