@@ -7,6 +7,7 @@ pub struct CardanoTransactionsBuilder {
7
7
max_transactions_per_block : usize ,
8
8
max_blocks_per_block_range : usize ,
9
9
max_transactions_per_immutable_file : usize ,
10
+ first_immutable_file : u64 ,
10
11
}
11
12
12
13
impl CardanoTransactionsBuilder {
@@ -15,6 +16,7 @@ impl CardanoTransactionsBuilder {
15
16
max_transactions_per_block : 1 ,
16
17
max_blocks_per_block_range : 1 ,
17
18
max_transactions_per_immutable_file : 1 ,
19
+ first_immutable_file : 1 ,
18
20
}
19
21
}
20
22
@@ -30,6 +32,12 @@ impl CardanoTransactionsBuilder {
30
32
self
31
33
}
32
34
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
+
33
41
/// Define how many blocks we generate in each block_range.
34
42
/// If we set too many blocks for a block_range, this function panic.
35
43
pub fn blocks_per_block_range ( mut self , blocks_per_block_range : usize ) -> Self {
@@ -61,10 +69,13 @@ impl CardanoTransactionsBuilder {
61
69
let first_transaction_number = 100 ;
62
70
for tx_index in 0 ..transactions_count {
63
71
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 ;
64
75
transactions. push ( self . create_transaction (
65
76
tx_index as u64 + first_transaction_number,
66
77
block_number,
67
- tx_index as u64 / self . max_transactions_per_immutable_file as u64 ,
78
+ immutable_file_number ,
68
79
) )
69
80
}
70
81
@@ -394,4 +405,32 @@ mod test {
394
405
count_distinct_values( & transactions, & |t| t. immutable_file_number)
395
406
) ;
396
407
}
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
+ }
397
436
}
0 commit comments