1- use std:: cmp:: max;
2-
31use crate :: entities:: { BlockRange , CardanoTransaction } ;
42
53/// Builder to easily build transactions with consistent values.
@@ -10,7 +8,14 @@ pub struct CardanoTransactionsBuilder {
108 first_immutable_file : u64 ,
119}
1210
11+ impl Default for CardanoTransactionsBuilder {
12+ fn default ( ) -> Self {
13+ Self :: new ( )
14+ }
15+ }
16+
1317impl CardanoTransactionsBuilder {
18+ /// [CardanoTransactionsBuilder] constructor.
1419 pub fn new ( ) -> Self {
1520 Self {
1621 max_transactions_per_block : 1 ,
@@ -51,13 +56,6 @@ impl CardanoTransactionsBuilder {
5156 self
5257 }
5358
54- /// TODO Do we keep this function ? If yes, ido we keep it public ?
55- fn print_transactions ( txs : & Vec < CardanoTransaction > ) {
56- for tx in txs {
57- println ! ( "{:?}" , tx) ;
58- }
59- }
60-
6159 /// Default build that build only one transaction.
6260 pub fn build ( self ) -> Vec < CardanoTransaction > {
6361 self . build_transactions ( 1 )
@@ -116,42 +114,6 @@ impl CardanoTransactionsBuilder {
116114 immutable_file_number,
117115 )
118116 }
119-
120- // TODO to remove when builder is finished
121- pub fn generate_transactions_with_block_ranges (
122- total_block_ranges : usize ,
123- total_transactions_per_block_range : usize ,
124- ) -> Vec < CardanoTransaction > {
125- let block_range_length = BlockRange :: LENGTH as usize ;
126- let max_transaction_per_block_number =
127- max ( 1 , total_transactions_per_block_range / block_range_length) ;
128- let mut transactions = vec ! [ ] ;
129-
130- for i in 0 ..total_block_ranges {
131- let block_range = BlockRange :: from_block_number ( ( i * block_range_length) as u64 ) ;
132- for j in 0 ..total_transactions_per_block_range {
133- let transaction_index = i * total_transactions_per_block_range + j;
134- let block_number =
135- block_range. start + ( j / max_transaction_per_block_number) as u64 ;
136- let slot_number = 100 * block_number;
137- let immutable_file_number = block_number / 5 ;
138- let tx_hash = format ! (
139- "tx-br-{}..{}-{}-idx-{}" ,
140- block_range. start, block_range. end, j, transaction_index
141- ) ;
142- let block_hash = format ! ( "block_hash-{block_number}" ) ;
143- transactions. push ( CardanoTransaction :: new (
144- & tx_hash,
145- block_number,
146- slot_number,
147- block_hash,
148- immutable_file_number,
149- ) ) ;
150- }
151- }
152-
153- transactions
154- }
155117}
156118
157119#[ cfg( test) ]
@@ -160,13 +122,6 @@ mod test {
160122
161123 use super :: * ;
162124
163- #[ test]
164- fn return_one_transaction_by_default ( ) {
165- let transactions = CardanoTransactionsBuilder :: new ( ) . build ( ) ;
166-
167- assert_eq ! ( transactions. len( ) , 1 ) ;
168- }
169-
170125 fn count_distinct_values < T , R > ( list : & [ T ] , extract_value : & dyn Fn ( & T ) -> R ) -> usize
171126 where
172127 R : Eq + std:: hash:: Hash ,
@@ -188,25 +143,15 @@ mod test {
188143 grouped_by_block
189144 }
190145
191- #[ test]
192- fn generate_transactions_with_block_ranges_test ( ) {
193- let total_block_ranges = 3 ;
194- let total_transactions_per_block_range = 10 ;
195- let transactions = CardanoTransactionsBuilder :: generate_transactions_with_block_ranges (
196- total_block_ranges,
197- total_transactions_per_block_range,
198- ) ;
199-
200- CardanoTransactionsBuilder :: print_transactions ( & transactions) ;
201-
202- println ! ( "-------------------" ) ;
146+ fn extract_by < T , R > ( list : & [ T ] , extract_value : & dyn Fn ( & T ) -> R ) -> Vec < R > {
147+ list. iter ( ) . map ( extract_value) . collect ( )
148+ }
203149
204- let transactions = CardanoTransactionsBuilder :: new ( )
205- . per_block ( 1 )
206- . blocks_per_block_range ( total_transactions_per_block_range)
207- . build_block_ranges ( total_block_ranges) ;
150+ #[ test]
151+ fn return_one_transaction_by_default ( ) {
152+ let transactions = CardanoTransactionsBuilder :: new ( ) . build ( ) ;
208153
209- CardanoTransactionsBuilder :: print_transactions ( & transactions) ;
154+ assert_eq ! ( transactions. len ( ) , 1 ) ;
210155 }
211156
212157 #[ test]
@@ -278,28 +223,12 @@ mod test {
278223 assert_eq ! ( vec![ 2 , 5 , 5 ] , txs_per_block) ;
279224 }
280225
281- // TODO to remove when builder is finished #[test]
282- fn test_generate_transactions_with_block_ranges ( ) {
283- let total_block_ranges = 3 ;
284- let total_transactions_per_block_range = 10 ;
285- let transactions = CardanoTransactionsBuilder :: generate_transactions_with_block_ranges (
286- total_block_ranges,
287- total_transactions_per_block_range,
288- ) ;
289-
290- CardanoTransactionsBuilder :: print_transactions ( & transactions) ;
291- }
292-
293226 #[ test]
294227 fn generate_one_block_range_return_one_transaction_by_default ( ) {
295228 let txs = CardanoTransactionsBuilder :: new ( ) . build_block_ranges ( 1 ) ;
296229 assert_eq ! ( txs. len( ) , 1 ) ;
297230 }
298231
299- fn extract_by < T , R > ( list : & [ T ] , extract_value : & dyn Fn ( & T ) -> R ) -> Vec < R > {
300- list. iter ( ) . map ( extract_value) . collect ( )
301- }
302-
303232 #[ test]
304233 fn build_block_ranges_return_the_number_of_block_ranges_requested ( ) {
305234 let block_ranges = 3 ;
0 commit comments