@@ -388,6 +388,45 @@ mod tests {
388
388
Arc :: new ( self . mock_cardano_transactions_artifact_builder ) ,
389
389
)
390
390
}
391
+
392
+ fn mock_artifact_processing <
393
+ T : Artifact + Clone + Serialize + ' static ,
394
+ U : signable_builder:: Beacon ,
395
+ > (
396
+ & mut self ,
397
+ artifact : T ,
398
+ mock_that_provide_artifact : & dyn Fn (
399
+ & mut MockDependencyInjector ,
400
+ ) -> & mut MockArtifactBuilder < U , T > ,
401
+ ) {
402
+ {
403
+ let artifact_cloned = artifact. clone ( ) ;
404
+ mock_that_provide_artifact ( self )
405
+ . expect_compute_artifact ( )
406
+ . times ( 1 )
407
+ . return_once ( |_, _| Ok ( artifact_cloned) ) ;
408
+ }
409
+ {
410
+ let artifact_clone: Arc < dyn Artifact > = Arc :: new ( artifact. clone ( ) ) ;
411
+ let artifact_json = serde_json:: to_string ( & artifact_clone) . unwrap ( ) ;
412
+ self . mock_signed_entity_storer
413
+ . expect_store_signed_entity ( )
414
+ . withf ( move |signed_entity| signed_entity. artifact == artifact_json)
415
+ . return_once ( |_| Ok ( ( ) ) ) ;
416
+ }
417
+ }
418
+
419
+ fn mock_immutable_files_processing ( & mut self , artifact : Snapshot ) {
420
+ self . mock_artifact_processing ( artifact, & |mock_injector| {
421
+ & mut mock_injector. mock_cardano_immutable_files_full_artifact_builder
422
+ } ) ;
423
+ }
424
+
425
+ fn mock_stake_distribution_processing ( & mut self , artifact : MithrilStakeDistribution ) {
426
+ self . mock_artifact_processing ( artifact, & |mock_injector| {
427
+ & mut mock_injector. mock_mithril_stake_distribution_artifact_builder
428
+ } ) ;
429
+ }
391
430
}
392
431
393
432
#[ tokio:: test]
@@ -546,43 +585,16 @@ mod tests {
546
585
// TODO: Verify the relevance of this test
547
586
#[ tokio:: test]
548
587
async fn create_artifact_for_two_signed_entity_types_in_sequence ( ) {
549
- let mut mock_container = MockDependencyInjector :: new ( ) ;
550
- {
551
- let snapshot = fake_data:: snapshots ( 1 ) . first ( ) . unwrap ( ) . to_owned ( ) ;
552
- let artifact_snapshot: Arc < dyn Artifact > = Arc :: new ( snapshot. clone ( ) ) ;
553
- let artifact = serde_json:: to_string ( & artifact_snapshot) . unwrap ( ) ;
554
- mock_container
555
- . mock_cardano_immutable_files_full_artifact_builder
556
- . expect_compute_artifact ( )
557
- . times ( 1 )
558
- . return_once ( |_, _| Ok ( snapshot) ) ;
559
-
560
- mock_container
561
- . mock_signed_entity_storer
562
- . expect_store_signed_entity ( )
563
- . withf ( move |signed_entity| signed_entity. artifact == artifact)
564
- . times ( 1 )
565
- . return_once ( |_| Ok ( ( ) ) ) ;
566
- }
567
- {
568
- let msd = create_stake_distribution ( Epoch ( 1 ) , 5 ) ;
569
- let artifact_msd: Arc < dyn Artifact > = Arc :: new ( msd. clone ( ) ) ;
570
- let artifact = serde_json:: to_string ( & artifact_msd) . unwrap ( ) ;
571
- mock_container
572
- . mock_mithril_stake_distribution_artifact_builder
573
- . expect_compute_artifact ( )
574
- . times ( 1 )
575
- . return_once ( |_, _| Ok ( msd) ) ;
576
-
588
+ let artifact_builder_service = {
589
+ let mut mock_container = MockDependencyInjector :: new ( ) ;
590
+ mock_container. mock_immutable_files_processing (
591
+ fake_data:: snapshots ( 1 ) . first ( ) . unwrap ( ) . to_owned ( ) ,
592
+ ) ;
577
593
mock_container
578
- . mock_signed_entity_storer
579
- . expect_store_signed_entity ( )
580
- . withf ( move |signed_entity| signed_entity. artifact == artifact)
581
- . times ( 1 )
582
- . return_once ( |_| Ok ( ( ) ) ) ;
583
- }
584
- let artifact_builder_service = mock_container. build_artifact_builder_service ( ) ;
594
+ . mock_stake_distribution_processing ( create_stake_distribution ( Epoch ( 1 ) , 5 ) ) ;
585
595
596
+ mock_container. build_artifact_builder_service ( )
597
+ } ;
586
598
let certificate = fake_data:: certificate ( "hash" . to_string ( ) ) ;
587
599
588
600
let signed_entity_type_immutable =
@@ -601,11 +613,9 @@ mod tests {
601
613
602
614
#[ tokio:: test]
603
615
async fn create_artifact_for_two_signed_entity_types_in_sequence_not_blocking ( ) {
604
- let mut mock_container = MockDependencyInjector :: new ( ) ;
605
- {
616
+ let artifact_builder_service = {
617
+ let mut mock_container = MockDependencyInjector :: new ( ) ;
606
618
let snapshot = fake_data:: snapshots ( 1 ) . first ( ) . unwrap ( ) . to_owned ( ) ;
607
- let artifact_snapshot: Arc < dyn Artifact > = Arc :: new ( snapshot. clone ( ) ) ;
608
- let artifact = serde_json:: to_string ( & artifact_snapshot) . unwrap ( ) ;
609
619
mock_container
610
620
. mock_cardano_immutable_files_full_artifact_builder
611
621
. expect_compute_artifact ( )
@@ -615,32 +625,11 @@ mod tests {
615
625
Ok ( snapshot)
616
626
} ) ;
617
627
618
- mock_container
619
- . mock_signed_entity_storer
620
- . expect_store_signed_entity ( )
621
- . withf ( move |signed_entity| signed_entity. artifact == artifact)
622
- . never ( )
623
- . return_once ( |_| Ok ( ( ) ) ) ;
624
- }
625
- {
626
628
let msd = create_stake_distribution ( Epoch ( 1 ) , 5 ) ;
627
- let artifact_msd: Arc < dyn Artifact > = Arc :: new ( msd. clone ( ) ) ;
628
- let artifact = serde_json:: to_string ( & artifact_msd) . unwrap ( ) ;
629
- mock_container
630
- . mock_mithril_stake_distribution_artifact_builder
631
- . expect_compute_artifact ( )
632
- . times ( 1 )
633
- . return_once ( |_, _| Ok ( msd) ) ;
634
-
635
- mock_container
636
- . mock_signed_entity_storer
637
- . expect_store_signed_entity ( )
638
- . withf ( move |signed_entity| signed_entity. artifact == artifact)
639
- . times ( 1 )
640
- . return_once ( |_| Ok ( ( ) ) ) ;
641
- }
642
- let artifact_builder_service = Arc :: new ( mock_container. build_artifact_builder_service ( ) ) ;
629
+ mock_container. mock_stake_distribution_processing ( msd) ;
643
630
631
+ Arc :: new ( mock_container. build_artifact_builder_service ( ) )
632
+ } ;
644
633
let certificate = fake_data:: certificate ( "hash" . to_string ( ) ) ;
645
634
646
635
let signed_entity_type_immutable =
@@ -652,7 +641,7 @@ mod tests {
652
641
let second_task_that_finish_first = artifact_builder_service
653
642
. create_artifact_return_join_handle ( signed_entity_type_msd, & certificate) ;
654
643
655
- let _ = second_task_that_finish_first. await ;
644
+ let _ = second_task_that_finish_first. await . unwrap ( ) ;
656
645
assert ! ( !first_task_that_never_finished. is_finished( ) ) ;
657
646
}
658
647
}
0 commit comments