1
- use std:: cmp:: max;
2
-
3
1
use crate :: entities:: { BlockRange , CardanoTransaction } ;
4
2
5
3
/// Builder to easily build transactions with consistent values.
@@ -10,7 +8,14 @@ pub struct CardanoTransactionsBuilder {
10
8
first_immutable_file : u64 ,
11
9
}
12
10
11
+ impl Default for CardanoTransactionsBuilder {
12
+ fn default ( ) -> Self {
13
+ Self :: new ( )
14
+ }
15
+ }
16
+
13
17
impl CardanoTransactionsBuilder {
18
+ /// [CardanoTransactionsBuilder] constructor.
14
19
pub fn new ( ) -> Self {
15
20
Self {
16
21
max_transactions_per_block : 1 ,
@@ -51,13 +56,6 @@ impl CardanoTransactionsBuilder {
51
56
self
52
57
}
53
58
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
-
61
59
/// Default build that build only one transaction.
62
60
pub fn build ( self ) -> Vec < CardanoTransaction > {
63
61
self . build_transactions ( 1 )
@@ -116,42 +114,6 @@ impl CardanoTransactionsBuilder {
116
114
immutable_file_number,
117
115
)
118
116
}
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
- }
155
117
}
156
118
157
119
#[ cfg( test) ]
@@ -160,13 +122,6 @@ mod test {
160
122
161
123
use super :: * ;
162
124
163
- #[ test]
164
- fn return_one_transaction_by_default ( ) {
165
- let transactions = CardanoTransactionsBuilder :: new ( ) . build ( ) ;
166
-
167
- assert_eq ! ( transactions. len( ) , 1 ) ;
168
- }
169
-
170
125
fn count_distinct_values < T , R > ( list : & [ T ] , extract_value : & dyn Fn ( & T ) -> R ) -> usize
171
126
where
172
127
R : Eq + std:: hash:: Hash ,
@@ -188,25 +143,15 @@ mod test {
188
143
grouped_by_block
189
144
}
190
145
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
+ }
203
149
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 ( ) ;
208
153
209
- CardanoTransactionsBuilder :: print_transactions ( & transactions) ;
154
+ assert_eq ! ( transactions. len ( ) , 1 ) ;
210
155
}
211
156
212
157
#[ test]
@@ -278,28 +223,12 @@ mod test {
278
223
assert_eq ! ( vec![ 2 , 5 , 5 ] , txs_per_block) ;
279
224
}
280
225
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
-
293
226
#[ test]
294
227
fn generate_one_block_range_return_one_transaction_by_default ( ) {
295
228
let txs = CardanoTransactionsBuilder :: new ( ) . build_block_ranges ( 1 ) ;
296
229
assert_eq ! ( txs. len( ) , 1 ) ;
297
230
}
298
231
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
-
303
232
#[ test]
304
233
fn build_block_ranges_return_the_number_of_block_ranges_requested ( ) {
305
234
let block_ranges = 3 ;
0 commit comments