@@ -201,17 +201,20 @@ impl CardanoTransactionParser {
201
201
202
202
#[ async_trait]
203
203
impl TransactionParser for CardanoTransactionParser {
204
- // Todo: update implem to parse from the lower bound
205
204
async fn parse (
206
205
& self ,
207
206
dirpath : & Path ,
208
- _from_immutable : Option < ImmutableFileNumber > ,
207
+ from_immutable : Option < ImmutableFileNumber > ,
209
208
until_immutable : ImmutableFileNumber ,
210
209
) -> StdResult < Vec < CardanoTransaction > > {
211
210
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
+ } ;
212
215
let immutable_chunks = ImmutableFile :: list_completed_in_dir ( dirpath) ?
213
216
. 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" ) )
215
218
. collect :: < Vec < _ > > ( ) ;
216
219
let mut transactions: Vec < CardanoTransaction > = vec ! [ ] ;
217
220
@@ -295,7 +298,22 @@ mod tests {
295
298
296
299
#[ tokio:: test]
297
300
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) ;
299
317
}
300
318
301
319
#[ tokio:: test]
0 commit comments