@@ -6,13 +6,15 @@ use crate::entities::{BlockRange, CardanoTransaction};
6
6
pub struct CardanoTransactionsBuilder {
7
7
max_transactions_per_block : usize ,
8
8
max_blocks_per_block_range : usize ,
9
+ max_transactions_per_immutable_file : usize ,
9
10
}
10
11
11
12
impl CardanoTransactionsBuilder {
12
13
pub fn new ( ) -> Self {
13
14
Self {
14
15
max_transactions_per_block : 1 ,
15
16
max_blocks_per_block_range : 1 ,
17
+ max_transactions_per_immutable_file : 1 ,
16
18
}
17
19
}
18
20
@@ -22,6 +24,12 @@ impl CardanoTransactionsBuilder {
22
24
self
23
25
}
24
26
27
+ /// Define how many transactions we generate for one immutable_file.
28
+ pub fn per_immutable_file ( mut self , transactions_per_immutable_file : usize ) -> Self {
29
+ self . max_transactions_per_immutable_file = transactions_per_immutable_file;
30
+ self
31
+ }
32
+
25
33
/// Define how many blocks we generate in each block_range.
26
34
/// If we set too many blocks for a block_range, this function panic.
27
35
pub fn blocks_per_block_range ( mut self , blocks_per_block_range : usize ) -> Self {
@@ -53,8 +61,11 @@ impl CardanoTransactionsBuilder {
53
61
let first_transaction_number = 100 ;
54
62
for tx_index in 0 ..transactions_count {
55
63
let block_number = self . block_number_from_transaction_index ( tx_index) ;
56
- transactions
57
- . push ( self . create_transaction ( tx_index + first_transaction_number, block_number) )
64
+ transactions. push ( self . create_transaction (
65
+ tx_index as u64 + first_transaction_number,
66
+ block_number,
67
+ tx_index as u64 / self . max_transactions_per_immutable_file as u64 ,
68
+ ) )
58
69
}
59
70
60
71
transactions
@@ -82,15 +93,16 @@ impl CardanoTransactionsBuilder {
82
93
/// Create a transaction with a given index and block number.
83
94
fn create_transaction (
84
95
& self ,
85
- transaction_index : usize ,
96
+ transaction_id : u64 ,
86
97
block_number : u64 ,
98
+ immutable_file_number : u64 ,
87
99
) -> CardanoTransaction {
88
100
CardanoTransaction :: new (
89
- format ! ( "tx-hash-{}-{}" , block_number, transaction_index ) ,
101
+ format ! ( "tx-hash-{}-{}" , block_number, transaction_id ) ,
90
102
block_number,
91
- transaction_index as u64 ,
103
+ transaction_id ,
92
104
format ! ( "block-hash-{block_number}" ) ,
93
- transaction_index as u64 ,
105
+ immutable_file_number ,
94
106
)
95
107
}
96
108
@@ -368,4 +380,18 @@ mod test {
368
380
fn should_panic_when_too_many_blocks_per_block_range ( ) {
369
381
CardanoTransactionsBuilder :: new ( ) . blocks_per_block_range ( BlockRange :: LENGTH as usize + 1 ) ;
370
382
}
383
+
384
+ #[ test]
385
+ fn build_transactions_with_many_transactions_per_immutable_file ( ) {
386
+ let transactions = CardanoTransactionsBuilder :: new ( )
387
+ . per_immutable_file ( 5 )
388
+ . build_transactions ( 18 ) ;
389
+
390
+ assert_eq ! ( transactions. len( ) , 18 ) ;
391
+
392
+ assert_eq ! (
393
+ 4 ,
394
+ count_distinct_values( & transactions, & |t| t. immutable_file_number)
395
+ ) ;
396
+ }
371
397
}
0 commit comments