@@ -3,7 +3,7 @@ use async_trait::async_trait;
3
3
use std:: sync:: Arc ;
4
4
5
5
use mithril_common:: {
6
- entities:: { Certificate , Epoch , SignedEntityType } ,
6
+ entities:: { Beacon , Certificate , Epoch , SignedEntityType , Snapshot } ,
7
7
signable_builder:: Artifact ,
8
8
StdResult ,
9
9
} ;
@@ -31,6 +31,7 @@ pub trait ArtifactBuilderService: Send + Sync {
31
31
pub struct MithrilArtifactBuilderService {
32
32
mithril_stake_distribution_artifact_builder :
33
33
Arc < dyn ArtifactBuilder < Epoch , MithrilStakeDistribution > > ,
34
+ cardano_immutable_files_full_artifact_builder : Arc < dyn ArtifactBuilder < Beacon , Snapshot > > ,
34
35
}
35
36
36
37
impl MithrilArtifactBuilderService {
@@ -40,9 +41,11 @@ impl MithrilArtifactBuilderService {
40
41
mithril_stake_distribution_artifact_builder : Arc <
41
42
dyn ArtifactBuilder < Epoch , MithrilStakeDistribution > ,
42
43
> ,
44
+ cardano_immutable_files_full_artifact_builder : Arc < dyn ArtifactBuilder < Beacon , Snapshot > > ,
43
45
) -> Self {
44
46
Self {
45
47
mithril_stake_distribution_artifact_builder,
48
+ cardano_immutable_files_full_artifact_builder,
46
49
}
47
50
}
48
51
}
@@ -55,16 +58,19 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService {
55
58
signed_entity_type : SignedEntityType ,
56
59
certificate : & Certificate ,
57
60
) -> StdResult < Arc < dyn Artifact > > {
58
- let artifact = match signed_entity_type {
59
- SignedEntityType :: MithrilStakeDistribution ( e ) => Arc :: new (
61
+ match signed_entity_type {
62
+ SignedEntityType :: MithrilStakeDistribution ( epoch ) => Ok ( Arc :: new (
60
63
self . mithril_stake_distribution_artifact_builder
61
- . compute_artifact ( e , certificate)
64
+ . compute_artifact ( epoch , certificate)
62
65
. await ?,
63
- ) ,
66
+ ) ) ,
67
+ SignedEntityType :: CardanoImmutableFilesFull ( beacon) => Ok ( Arc :: new (
68
+ self . cardano_immutable_files_full_artifact_builder
69
+ . compute_artifact ( beacon, certificate)
70
+ . await ?,
71
+ ) ) ,
64
72
_ => todo ! ( ) ,
65
- } ;
66
-
67
- Ok ( artifact)
73
+ }
68
74
}
69
75
}
70
76
@@ -77,7 +83,8 @@ mod tests {
77
83
use crate :: artifact_builder:: MockArtifactBuilder ;
78
84
79
85
#[ tokio:: test]
80
- async fn test_artifact_builder_service_mithril_stake_distribution ( ) {
86
+ async fn build_mithril_stake_distribution_artifact_when_given_mithril_stake_distribution_entity_type (
87
+ ) {
81
88
let signers_with_stake = fake_data:: signers_with_stakes ( 5 ) ;
82
89
let mithril_stake_distribution_expected = MithrilStakeDistribution :: new ( signers_with_stake) ;
83
90
let mithril_stake_distribution_clone = mithril_stake_distribution_expected. clone ( ) ;
@@ -88,9 +95,13 @@ mod tests {
88
95
. once ( )
89
96
. return_once ( move |_, _| Ok ( mithril_stake_distribution_clone) ) ;
90
97
91
- let artifact_builder_service = MithrilArtifactBuilderService :: new ( Arc :: new (
92
- mock_mithril_stake_distribution_artifact_builder,
93
- ) ) ;
98
+ let mock_cardano_immutable_files_full_artifact_builder =
99
+ MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ;
100
+
101
+ let artifact_builder_service = MithrilArtifactBuilderService :: new (
102
+ Arc :: new ( mock_mithril_stake_distribution_artifact_builder) ,
103
+ Arc :: new ( mock_cardano_immutable_files_full_artifact_builder) ,
104
+ ) ;
94
105
let certificate = Certificate :: default ( ) ;
95
106
96
107
let signed_entity_type = SignedEntityType :: MithrilStakeDistribution ( Epoch ( 1 ) ) ;
@@ -105,4 +116,37 @@ mod tests {
105
116
serde_json:: to_string( & mithril_stake_distribution_computed) . unwrap( )
106
117
) ;
107
118
}
119
+
120
+ #[ tokio:: test]
121
+ async fn build_snapshot_artifact_when_given_cardano_immutable_files_full_entity_type ( ) {
122
+ let snapshot_expected = fake_data:: snapshots ( 1 ) . first ( ) . unwrap ( ) . to_owned ( ) ;
123
+ let snapshot_expected_clone = snapshot_expected. clone ( ) ;
124
+ let mock_mithril_stake_distribution_artifact_builder =
125
+ MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ;
126
+
127
+ let mut mock_cardano_immutable_files_full_artifact_builder =
128
+ MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ;
129
+ mock_cardano_immutable_files_full_artifact_builder
130
+ . expect_compute_artifact ( )
131
+ . once ( )
132
+ . return_once ( move |_, _| Ok ( snapshot_expected_clone) ) ;
133
+
134
+ let artifact_builder_service = MithrilArtifactBuilderService :: new (
135
+ Arc :: new ( mock_mithril_stake_distribution_artifact_builder) ,
136
+ Arc :: new ( mock_cardano_immutable_files_full_artifact_builder) ,
137
+ ) ;
138
+ let certificate = Certificate :: default ( ) ;
139
+
140
+ let signed_entity_type = SignedEntityType :: CardanoImmutableFilesFull ( Beacon :: default ( ) ) ;
141
+ let artifact = artifact_builder_service
142
+ . compute_artifact ( signed_entity_type, & certificate)
143
+ . await
144
+ . unwrap ( ) ;
145
+ let snapshot_computed: Snapshot =
146
+ serde_json:: from_str ( & serde_json:: to_string ( & artifact) . unwrap ( ) ) . unwrap ( ) ;
147
+ assert_eq ! (
148
+ serde_json:: to_string( & snapshot_expected) . unwrap( ) ,
149
+ serde_json:: to_string( & snapshot_computed) . unwrap( )
150
+ ) ;
151
+ }
108
152
}
0 commit comments