@@ -7,6 +7,7 @@ pub struct CardanoTransactionsBuilder {
77 max_transactions_per_block : usize ,
88 max_blocks_per_block_range : usize ,
99 max_transactions_per_immutable_file : usize ,
10+ first_immutable_file : u64 ,
1011}
1112
1213impl CardanoTransactionsBuilder {
@@ -15,6 +16,7 @@ impl CardanoTransactionsBuilder {
1516 max_transactions_per_block : 1 ,
1617 max_blocks_per_block_range : 1 ,
1718 max_transactions_per_immutable_file : 1 ,
19+ first_immutable_file : 1 ,
1820 }
1921 }
2022
@@ -30,6 +32,12 @@ impl CardanoTransactionsBuilder {
3032 self
3133 }
3234
35+ /// Define the first immutable file number.
36+ pub fn first_immutable_file ( mut self , first_immutable_file : u64 ) -> Self {
37+ self . first_immutable_file = first_immutable_file;
38+ self
39+ }
40+
3341 /// Define how many blocks we generate in each block_range.
3442 /// If we set too many blocks for a block_range, this function panic.
3543 pub fn blocks_per_block_range ( mut self , blocks_per_block_range : usize ) -> Self {
@@ -61,10 +69,13 @@ impl CardanoTransactionsBuilder {
6169 let first_transaction_number = 100 ;
6270 for tx_index in 0 ..transactions_count {
6371 let block_number = self . block_number_from_transaction_index ( tx_index) ;
72+ let immutable_file_number = tx_index as u64
73+ / self . max_transactions_per_immutable_file as u64
74+ + self . first_immutable_file ;
6475 transactions. push ( self . create_transaction (
6576 tx_index as u64 + first_transaction_number,
6677 block_number,
67- tx_index as u64 / self . max_transactions_per_immutable_file as u64 ,
78+ immutable_file_number ,
6879 ) )
6980 }
7081
@@ -394,4 +405,32 @@ mod test {
394405 count_distinct_values( & transactions, & |t| t. immutable_file_number)
395406 ) ;
396407 }
408+
409+ #[ test]
410+ fn build_transactions_with_same_number_of_transactions_per_immutable_file ( ) {
411+ let transactions = CardanoTransactionsBuilder :: new ( )
412+ . per_immutable_file ( 5 )
413+ . build_transactions ( 20 ) ;
414+
415+ assert_eq ! ( transactions. len( ) , 20 ) ;
416+
417+ let grouped_by_immutable_file = group_by ( & transactions, & |t| t. immutable_file_number ) ;
418+ assert_eq ! ( 4 , grouped_by_immutable_file. len( ) ) ;
419+
420+ for transaction_for_immutable_file in grouped_by_immutable_file. values ( ) {
421+ assert_eq ! ( 5 , transaction_for_immutable_file. len( ) ) ;
422+ }
423+ }
424+
425+ #[ test]
426+ fn build_transactions_with_immutable_file_starting_at_a_specific_number ( ) {
427+ let transactions = CardanoTransactionsBuilder :: new ( )
428+ . first_immutable_file ( 5 )
429+ . build_transactions ( 3 ) ;
430+
431+ assert_eq ! (
432+ vec![ 5 , 6 , 7 ] ,
433+ extract_by( & transactions, & |t| t. immutable_file_number)
434+ ) ;
435+ }
397436}
0 commit comments