@@ -153,11 +153,10 @@ impl ProverService for MithrilProverService {
153153
154154#[ cfg( test) ]
155155mod tests {
156- use std:: cmp:: max;
157-
158156 use anyhow:: anyhow;
159157 use mithril_common:: crypto_helper:: { MKMap , MKMapNode , MKTreeNode } ;
160158 use mithril_common:: entities:: { CardanoTransaction , ImmutableFileNumber } ;
159+ use mithril_common:: test_utils:: CardanoTransactionsBuilder ;
161160 use mockall:: mock;
162161 use mockall:: predicate:: eq;
163162
@@ -183,43 +182,6 @@ mod tests {
183182 mod test_data {
184183 use super :: * ;
185184
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-
223185 pub fn filter_transactions_for_indices (
224186 indices : & [ usize ] ,
225187 transactions : & [ CardanoTransaction ] ,
@@ -232,7 +194,7 @@ mod tests {
232194 . collect ( )
233195 }
234196
235- pub fn compute_transaction_hashes_from_transactions (
197+ pub fn map_to_transaction_hashes (
236198 transactions : & [ CardanoTransaction ] ,
237199 ) -> Vec < TransactionHash > {
238200 transactions
@@ -241,7 +203,7 @@ mod tests {
241203 . collect ( )
242204 }
243205
244- pub fn compute_block_ranges_map_from_transactions (
206+ pub fn transactions_group_by_block_range (
245207 transactions : & [ CardanoTransaction ] ,
246208 ) -> BTreeMap < BlockRange , Vec < CardanoTransaction > > {
247209 let mut block_ranges_map = BTreeMap :: new ( ) ;
@@ -309,11 +271,10 @@ mod tests {
309271 transactions_to_prove : & [ CardanoTransaction ] ,
310272 transactions : & [ CardanoTransaction ] ,
311273 ) -> 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) ;
315276 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) ;
317278 let block_ranges_to_prove = block_ranges_map_to_prove
318279 . keys ( )
319280 . cloned ( )
@@ -355,10 +316,10 @@ mod tests {
355316 async fn compute_proof_for_one_set_of_three_known_transactions ( ) {
356317 let total_block_ranges = 5 ;
357318 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 ) ;
362323 let transactions_to_prove =
363324 test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
364325 let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
@@ -408,10 +369,10 @@ mod tests {
408369 async fn cant_compute_proof_for_unknown_transaction ( ) {
409370 let total_block_ranges = 5 ;
410371 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 ) ;
415376 let transactions_to_prove = test_data:: filter_transactions_for_indices ( & [ ] , & transactions) ;
416377 let mut test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
417378 test_data. transaction_hashes_to_prove = vec ! [ "tx-unknown-123" . to_string( ) ] ;
@@ -456,10 +417,10 @@ mod tests {
456417 async fn compute_proof_for_one_set_of_three_known_transactions_and_two_unknowns ( ) {
457418 let total_block_ranges = 5 ;
458419 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 ) ;
463424 let transactions_to_prove =
464425 test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
465426 let transaction_hashes_unknown =
@@ -517,10 +478,10 @@ mod tests {
517478 async fn cant_compute_proof_if_transaction_retriever_fails ( ) {
518479 let total_block_ranges = 5 ;
519480 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 ) ;
524485 let transactions_to_prove =
525486 test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
526487 let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
@@ -547,10 +508,10 @@ mod tests {
547508 async fn cant_compute_proof_if_block_range_root_retriever_fails ( ) {
548509 let total_block_ranges = 5 ;
549510 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 ) ;
554515 let transactions_to_prove =
555516 test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
556517 let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
0 commit comments