@@ -153,11 +153,10 @@ impl ProverService for MithrilProverService {
153
153
154
154
#[ cfg( test) ]
155
155
mod tests {
156
- use std:: cmp:: max;
157
-
158
156
use anyhow:: anyhow;
159
157
use mithril_common:: crypto_helper:: { MKMap , MKMapNode , MKTreeNode } ;
160
158
use mithril_common:: entities:: { CardanoTransaction , ImmutableFileNumber } ;
159
+ use mithril_common:: test_utils:: CardanoTransactionsBuilder ;
161
160
use mockall:: mock;
162
161
use mockall:: predicate:: eq;
163
162
@@ -183,43 +182,6 @@ mod tests {
183
182
mod test_data {
184
183
use super :: * ;
185
184
186
- // Generate transactions for 'total_block_ranges' consecutive block ranges,
187
- // with 'total_transactions_per_block_range' transactions per block range
188
- pub fn generate_transactions (
189
- total_block_ranges : usize ,
190
- total_transactions_per_block_range : usize ,
191
- ) -> Vec < CardanoTransaction > {
192
- let block_range_length = BlockRange :: LENGTH as usize ;
193
- let max_transaction_per_block_number =
194
- max ( 1 , total_transactions_per_block_range / block_range_length) ;
195
- let mut transactions = vec ! [ ] ;
196
-
197
- for i in 0 ..total_block_ranges {
198
- let block_range = BlockRange :: from_block_number ( ( i * block_range_length) as u64 ) ;
199
- for j in 0 ..total_transactions_per_block_range {
200
- let transaction_index = i * total_transactions_per_block_range + j;
201
- let block_number =
202
- block_range. start + ( j / max_transaction_per_block_number) as u64 ;
203
- let slot_number = 100 * block_number;
204
- let immutable_file_number = block_number / 5 ;
205
- let tx_hash = format ! (
206
- "tx-br-{}..{}-{}-idx-{}" ,
207
- block_range. start, block_range. end, j, transaction_index
208
- ) ;
209
- let block_hash = format ! ( "block_hash-{block_number}" ) ;
210
- transactions. push ( CardanoTransaction :: new (
211
- & tx_hash,
212
- block_number,
213
- slot_number,
214
- block_hash,
215
- immutable_file_number,
216
- ) ) ;
217
- }
218
- }
219
-
220
- transactions
221
- }
222
-
223
185
pub fn filter_transactions_for_indices (
224
186
indices : & [ usize ] ,
225
187
transactions : & [ CardanoTransaction ] ,
@@ -232,7 +194,7 @@ mod tests {
232
194
. collect ( )
233
195
}
234
196
235
- pub fn compute_transaction_hashes_from_transactions (
197
+ pub fn map_to_transaction_hashes (
236
198
transactions : & [ CardanoTransaction ] ,
237
199
) -> Vec < TransactionHash > {
238
200
transactions
@@ -241,7 +203,7 @@ mod tests {
241
203
. collect ( )
242
204
}
243
205
244
- pub fn compute_block_ranges_map_from_transactions (
206
+ pub fn transactions_group_by_block_range (
245
207
transactions : & [ CardanoTransaction ] ,
246
208
) -> BTreeMap < BlockRange , Vec < CardanoTransaction > > {
247
209
let mut block_ranges_map = BTreeMap :: new ( ) ;
@@ -309,11 +271,10 @@ mod tests {
309
271
transactions_to_prove : & [ CardanoTransaction ] ,
310
272
transactions : & [ CardanoTransaction ] ,
311
273
) -> TestData {
312
- let transaction_hashes_to_prove =
313
- compute_transaction_hashes_from_transactions ( transactions_to_prove) ;
314
- let block_ranges_map = compute_block_ranges_map_from_transactions ( transactions) ;
274
+ let transaction_hashes_to_prove = map_to_transaction_hashes ( transactions_to_prove) ;
275
+ let block_ranges_map = transactions_group_by_block_range ( transactions) ;
315
276
let block_ranges_map_to_prove =
316
- compute_block_ranges_map_from_transactions ( transactions_to_prove) ;
277
+ transactions_group_by_block_range ( transactions_to_prove) ;
317
278
let block_ranges_to_prove = block_ranges_map_to_prove
318
279
. keys ( )
319
280
. cloned ( )
@@ -355,10 +316,10 @@ mod tests {
355
316
async fn compute_proof_for_one_set_of_three_known_transactions ( ) {
356
317
let total_block_ranges = 5 ;
357
318
let total_transactions_per_block_range = 3 ;
358
- let transactions = test_data :: generate_transactions (
359
- total_block_ranges ,
360
- total_transactions_per_block_range,
361
- ) ;
319
+ let transactions = CardanoTransactionsBuilder :: new ( )
320
+ . max_transactions_per_block ( 1 )
321
+ . blocks_per_block_range ( total_transactions_per_block_range)
322
+ . build_block_ranges ( total_block_ranges ) ;
362
323
let transactions_to_prove =
363
324
test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
364
325
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
@@ -408,10 +369,10 @@ mod tests {
408
369
async fn cant_compute_proof_for_unknown_transaction ( ) {
409
370
let total_block_ranges = 5 ;
410
371
let total_transactions_per_block_range = 3 ;
411
- let transactions = test_data :: generate_transactions (
412
- total_block_ranges ,
413
- total_transactions_per_block_range,
414
- ) ;
372
+ let transactions = CardanoTransactionsBuilder :: new ( )
373
+ . max_transactions_per_block ( 1 )
374
+ . blocks_per_block_range ( total_transactions_per_block_range)
375
+ . build_block_ranges ( total_block_ranges ) ;
415
376
let transactions_to_prove = test_data:: filter_transactions_for_indices ( & [ ] , & transactions) ;
416
377
let mut test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
417
378
test_data. transaction_hashes_to_prove = vec ! [ "tx-unknown-123" . to_string( ) ] ;
@@ -456,10 +417,10 @@ mod tests {
456
417
async fn compute_proof_for_one_set_of_three_known_transactions_and_two_unknowns ( ) {
457
418
let total_block_ranges = 5 ;
458
419
let total_transactions_per_block_range = 3 ;
459
- let transactions = test_data :: generate_transactions (
460
- total_block_ranges ,
461
- total_transactions_per_block_range,
462
- ) ;
420
+ let transactions = CardanoTransactionsBuilder :: new ( )
421
+ . max_transactions_per_block ( 1 )
422
+ . blocks_per_block_range ( total_transactions_per_block_range)
423
+ . build_block_ranges ( total_block_ranges ) ;
463
424
let transactions_to_prove =
464
425
test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
465
426
let transaction_hashes_unknown =
@@ -517,10 +478,10 @@ mod tests {
517
478
async fn cant_compute_proof_if_transaction_retriever_fails ( ) {
518
479
let total_block_ranges = 5 ;
519
480
let total_transactions_per_block_range = 3 ;
520
- let transactions = test_data :: generate_transactions (
521
- total_block_ranges ,
522
- total_transactions_per_block_range,
523
- ) ;
481
+ let transactions = CardanoTransactionsBuilder :: new ( )
482
+ . max_transactions_per_block ( 1 )
483
+ . blocks_per_block_range ( total_transactions_per_block_range)
484
+ . build_block_ranges ( total_block_ranges ) ;
524
485
let transactions_to_prove =
525
486
test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
526
487
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
@@ -547,10 +508,10 @@ mod tests {
547
508
async fn cant_compute_proof_if_block_range_root_retriever_fails ( ) {
548
509
let total_block_ranges = 5 ;
549
510
let total_transactions_per_block_range = 3 ;
550
- let transactions = test_data :: generate_transactions (
551
- total_block_ranges ,
552
- total_transactions_per_block_range,
553
- ) ;
511
+ let transactions = CardanoTransactionsBuilder :: new ( )
512
+ . max_transactions_per_block ( 1 )
513
+ . blocks_per_block_range ( total_transactions_per_block_range)
514
+ . build_block_ranges ( total_block_ranges ) ;
554
515
let transactions_to_prove =
555
516
test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
556
517
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
0 commit comments