@@ -11,9 +11,9 @@ use tokio::task::JoinHandle;
11
11
12
12
use mithril_common:: {
13
13
entities:: {
14
- BlockNumber , CardanoDbBeacon , CardanoStakeDistribution , CardanoTransactionsSnapshot ,
15
- Certificate , Epoch , MithrilStakeDistribution , SignedEntity , SignedEntityType ,
16
- SignedEntityTypeDiscriminants , Snapshot ,
14
+ BlockNumber , CardanoDatabase , CardanoDbBeacon , CardanoStakeDistribution ,
15
+ CardanoTransactionsSnapshot , Certificate , Epoch , MithrilStakeDistribution , SignedEntity ,
16
+ SignedEntityType , SignedEntityTypeDiscriminants , Snapshot ,
17
17
} ,
18
18
logging:: LoggerExtensions ,
19
19
signable_builder:: Artifact ,
@@ -89,6 +89,7 @@ pub struct MithrilSignedEntityService {
89
89
signed_entity_type_lock : Arc < SignedEntityTypeLock > ,
90
90
cardano_stake_distribution_artifact_builder :
91
91
Arc < dyn ArtifactBuilder < Epoch , CardanoStakeDistribution > > ,
92
+ cardano_database_artifact_builder : Arc < dyn ArtifactBuilder < CardanoDbBeacon , CardanoDatabase > > ,
92
93
metrics_service : Arc < MetricsService > ,
93
94
logger : Logger ,
94
95
}
@@ -103,6 +104,7 @@ pub struct SignedEntityServiceArtifactsDependencies {
103
104
Arc < dyn ArtifactBuilder < BlockNumber , CardanoTransactionsSnapshot > > ,
104
105
cardano_stake_distribution_artifact_builder :
105
106
Arc < dyn ArtifactBuilder < Epoch , CardanoStakeDistribution > > ,
107
+ cardano_database_artifact_builder : Arc < dyn ArtifactBuilder < CardanoDbBeacon , CardanoDatabase > > ,
106
108
}
107
109
108
110
impl SignedEntityServiceArtifactsDependencies {
@@ -120,12 +122,16 @@ impl SignedEntityServiceArtifactsDependencies {
120
122
cardano_stake_distribution_artifact_builder : Arc <
121
123
dyn ArtifactBuilder < Epoch , CardanoStakeDistribution > ,
122
124
> ,
125
+ cardano_database_artifact_builder : Arc <
126
+ dyn ArtifactBuilder < CardanoDbBeacon , CardanoDatabase > ,
127
+ > ,
123
128
) -> Self {
124
129
Self {
125
130
mithril_stake_distribution_artifact_builder,
126
131
cardano_immutable_files_full_artifact_builder,
127
132
cardano_transactions_artifact_builder,
128
133
cardano_stake_distribution_artifact_builder,
134
+ cardano_database_artifact_builder,
129
135
}
130
136
}
131
137
}
@@ -149,6 +155,7 @@ impl MithrilSignedEntityService {
149
155
. cardano_transactions_artifact_builder ,
150
156
cardano_stake_distribution_artifact_builder : dependencies
151
157
. cardano_stake_distribution_artifact_builder ,
158
+ cardano_database_artifact_builder : dependencies. cardano_database_artifact_builder ,
152
159
signed_entity_type_lock,
153
160
metrics_service,
154
161
logger : logger. new_with_component_name :: < Self > ( ) ,
@@ -247,11 +254,16 @@ impl MithrilSignedEntityService {
247
254
)
248
255
} ) ?,
249
256
) ) ,
250
- SignedEntityType :: CardanoDatabase ( _) => {
251
- Err ( anyhow:: anyhow!(
252
- "Signable builder service can not compute artifact for Cardano database because it is not yet implemented."
253
- ) )
254
- }
257
+ SignedEntityType :: CardanoDatabase ( beacon) => Ok ( Arc :: new (
258
+ self . cardano_database_artifact_builder
259
+ . compute_artifact ( beacon, certificate)
260
+ . await
261
+ . with_context ( || {
262
+ format ! (
263
+ "Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
264
+ )
265
+ } ) ?
266
+ ) ) ,
255
267
}
256
268
}
257
269
@@ -510,6 +522,8 @@ mod tests {
510
522
MockArtifactBuilder < BlockNumber , CardanoTransactionsSnapshot > ,
511
523
mock_cardano_stake_distribution_artifact_builder :
512
524
MockArtifactBuilder < Epoch , CardanoStakeDistribution > ,
525
+ mock_cardano_database_artifact_builder :
526
+ MockArtifactBuilder < CardanoDbBeacon , CardanoDatabase > ,
513
527
}
514
528
515
529
impl MockDependencyInjector {
@@ -532,6 +546,10 @@ mod tests {
532
546
Epoch ,
533
547
CardanoStakeDistribution ,
534
548
> :: new ( ) ,
549
+ mock_cardano_database_artifact_builder : MockArtifactBuilder :: <
550
+ CardanoDbBeacon ,
551
+ CardanoDatabase ,
552
+ > :: new ( ) ,
535
553
}
536
554
}
537
555
@@ -541,6 +559,7 @@ mod tests {
541
559
Arc :: new ( self . mock_cardano_immutable_files_full_artifact_builder ) ,
542
560
Arc :: new ( self . mock_cardano_transactions_artifact_builder ) ,
543
561
Arc :: new ( self . mock_cardano_stake_distribution_artifact_builder ) ,
562
+ Arc :: new ( self . mock_cardano_database_artifact_builder ) ,
544
563
) ;
545
564
MithrilSignedEntityService :: new (
546
565
Arc :: new ( self . mock_signed_entity_storer ) ,
@@ -597,6 +616,7 @@ mod tests {
597
616
Arc :: new ( cardano_immutable_files_full_long_artifact_builder) ,
598
617
Arc :: new ( self . mock_cardano_transactions_artifact_builder ) ,
599
618
Arc :: new ( self . mock_cardano_stake_distribution_artifact_builder ) ,
619
+ Arc :: new ( self . mock_cardano_database_artifact_builder ) ,
600
620
) ;
601
621
MithrilSignedEntityService :: new (
602
622
Arc :: new ( self . mock_signed_entity_storer ) ,
@@ -822,17 +842,48 @@ mod tests {
822
842
}
823
843
824
844
#[ tokio:: test]
825
- async fn build_cardano_database_artifact_when_given_cardano_database_entity_type_return_error ( )
826
- {
827
- let mock_container = MockDependencyInjector :: new ( ) ;
845
+ async fn build_cardano_database_artifact_when_given_cardano_database_entity_type ( ) {
846
+ let mut mock_container = MockDependencyInjector :: new ( ) ;
847
+
848
+ let cardano_database_expected = fake_data:: cardano_database_entities ( 1 )
849
+ . first ( )
850
+ . unwrap ( )
851
+ . to_owned ( ) ;
852
+
853
+ mock_container
854
+ . mock_cardano_database_artifact_builder
855
+ . expect_compute_artifact ( )
856
+ . times ( 1 )
857
+ . returning ( |_, _| {
858
+ Ok ( fake_data:: cardano_database_entities ( 1 )
859
+ . first ( )
860
+ . unwrap ( )
861
+ . to_owned ( ) )
862
+ } ) ;
863
+
828
864
let artifact_builder_service = mock_container. build_artifact_builder_service ( ) ;
865
+
829
866
let certificate = fake_data:: certificate ( "hash" . to_string ( ) ) ;
830
867
let signed_entity_type = SignedEntityType :: CardanoDatabase ( CardanoDbBeacon :: default ( ) ) ;
831
-
832
- artifact_builder_service
868
+ let artifact = artifact_builder_service
833
869
. compute_artifact ( signed_entity_type. clone ( ) , & certificate)
834
870
. await
835
- . expect_err ( "Should return error because CardanoDatabase is not implemented yet." ) ;
871
+ . unwrap ( ) ;
872
+
873
+ assert_expected ( & cardano_database_expected, & artifact) ;
874
+ }
875
+
876
+ #[ tokio:: test]
877
+ async fn should_store_the_artifact_when_creating_artifact_for_a_cardano_database ( ) {
878
+ generic_test_that_the_artifact_is_stored (
879
+ SignedEntityType :: CardanoDatabase ( CardanoDbBeacon :: default ( ) ) ,
880
+ fake_data:: cardano_database_entities ( 1 )
881
+ . first ( )
882
+ . unwrap ( )
883
+ . to_owned ( ) ,
884
+ & |mock_injector| & mut mock_injector. mock_cardano_database_artifact_builder ,
885
+ )
886
+ . await ;
836
887
}
837
888
838
889
async fn generic_test_that_the_artifact_is_stored <
0 commit comments