@@ -91,9 +91,9 @@ impl MithrilSignedEntityService {
91
91
& self ,
92
92
signed_entity_type : SignedEntityType ,
93
93
certificate : & Certificate ,
94
- ) -> StdResult < Arc < dyn Artifact > > {
94
+ ) -> StdResult < Option < Arc < dyn Artifact > > > {
95
95
match signed_entity_type. clone ( ) {
96
- SignedEntityType :: MithrilStakeDistribution ( epoch) => Ok ( Arc :: new (
96
+ SignedEntityType :: MithrilStakeDistribution ( epoch) => Ok ( Some ( Arc :: new (
97
97
self . mithril_stake_distribution_artifact_builder
98
98
. compute_artifact ( epoch, certificate)
99
99
. await
@@ -102,8 +102,8 @@ impl MithrilSignedEntityService {
102
102
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
103
103
)
104
104
} ) ?,
105
- ) ) ,
106
- SignedEntityType :: CardanoImmutableFilesFull ( beacon) => Ok ( Arc :: new (
105
+ ) ) ) ,
106
+ SignedEntityType :: CardanoImmutableFilesFull ( beacon) => Ok ( Some ( Arc :: new (
107
107
self . cardano_immutable_files_full_artifact_builder
108
108
. compute_artifact ( beacon. clone ( ) , certificate)
109
109
. await
@@ -112,9 +112,9 @@ impl MithrilSignedEntityService {
112
112
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
113
113
)
114
114
} ) ?,
115
- ) ) ,
115
+ ) ) ) ,
116
116
SignedEntityType :: CardanoStakeDistribution ( _) => todo ! ( ) ,
117
- SignedEntityType :: CardanoTransactions ( _) => todo ! ( ) ,
117
+ SignedEntityType :: CardanoTransactions ( _) => Ok ( None ) ,
118
118
}
119
119
}
120
120
}
@@ -142,7 +142,8 @@ impl SignedEntityService for MithrilSignedEntityService {
142
142
{
143
143
Err ( error) if remaining_retries == 0 => break Err ( error) ,
144
144
Err ( _error) => ( ) ,
145
- Ok ( artifact) => break Ok ( artifact) ,
145
+ Ok ( Some ( artifact) ) => break Ok ( artifact) ,
146
+ Ok ( None ) => return Ok ( ( ) ) ,
146
147
} ;
147
148
} ?;
148
149
@@ -278,12 +279,22 @@ mod tests {
278
279
signers_with_stake,
279
280
& fake_data:: protocol_parameters ( ) ,
280
281
) ;
281
- let mithril_stake_distribution_clone = mithril_stake_distribution_expected. clone ( ) ;
282
282
283
- let mock_signed_entity_storer = MockSignedEntityStorer :: new ( ) ;
283
+ let mut mock_signed_entity_storer = MockSignedEntityStorer :: new ( ) ;
284
+ mock_signed_entity_storer
285
+ . expect_store_signed_entity ( )
286
+ . once ( )
287
+ . return_once ( |_| Ok ( ( ) ) ) ;
284
288
285
289
let mut mock_mithril_stake_distribution_artifact_builder =
286
290
MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ;
291
+ let mithril_stake_distribution_clone = mithril_stake_distribution_expected. clone ( ) ;
292
+ mock_mithril_stake_distribution_artifact_builder
293
+ . expect_compute_artifact ( )
294
+ . once ( )
295
+ . return_once ( move |_, _| Ok ( mithril_stake_distribution_clone) ) ;
296
+
297
+ let mithril_stake_distribution_clone = mithril_stake_distribution_expected. clone ( ) ;
287
298
mock_mithril_stake_distribution_artifact_builder
288
299
. expect_compute_artifact ( )
289
300
. once ( )
@@ -301,7 +312,7 @@ mod tests {
301
312
302
313
let signed_entity_type = SignedEntityType :: MithrilStakeDistribution ( Epoch ( 1 ) ) ;
303
314
let artifact = artifact_builder_service
304
- . compute_artifact ( signed_entity_type, & certificate)
315
+ . compute_artifact ( signed_entity_type. clone ( ) , & certificate)
305
316
. await
306
317
. unwrap ( ) ;
307
318
let mithril_stake_distribution_computed: MithrilStakeDistribution =
@@ -310,23 +321,39 @@ mod tests {
310
321
serde_json:: to_string( & mithril_stake_distribution_expected) . unwrap( ) ,
311
322
serde_json:: to_string( & mithril_stake_distribution_computed) . unwrap( )
312
323
) ;
324
+
325
+ artifact_builder_service
326
+ . create_artifact ( signed_entity_type, & certificate)
327
+ . await
328
+ . expect ( "Create artifact should not fail for MithrilStakeDistribution signed entity" ) ;
313
329
}
314
330
315
331
#[ tokio:: test]
316
332
async fn build_snapshot_artifact_when_given_cardano_immutable_files_full_entity_type ( ) {
317
333
let snapshot_expected = fake_data:: snapshots ( 1 ) . first ( ) . unwrap ( ) . to_owned ( ) ;
318
- let snapshot_expected_clone = snapshot_expected. clone ( ) ;
319
334
320
- let mock_signed_entity_storer = MockSignedEntityStorer :: new ( ) ;
335
+ let mut mock_signed_entity_storer = MockSignedEntityStorer :: new ( ) ;
336
+ mock_signed_entity_storer
337
+ . expect_store_signed_entity ( )
338
+ . once ( )
339
+ . return_once ( |_| Ok ( ( ) ) ) ;
321
340
322
341
let mock_mithril_stake_distribution_artifact_builder =
323
342
MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ;
324
343
325
344
let mut mock_cardano_immutable_files_full_artifact_builder =
326
345
MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ;
346
+
347
+ let snapshot_expected_clone = snapshot_expected. clone ( ) ;
327
348
mock_cardano_immutable_files_full_artifact_builder
328
349
. expect_compute_artifact ( )
329
- . once ( )
350
+ . times ( 1 )
351
+ . return_once ( move |_, _| Ok ( snapshot_expected_clone) ) ;
352
+
353
+ let snapshot_expected_clone = snapshot_expected. clone ( ) ;
354
+ mock_cardano_immutable_files_full_artifact_builder
355
+ . expect_compute_artifact ( )
356
+ . times ( 1 )
330
357
. return_once ( move |_, _| Ok ( snapshot_expected_clone) ) ;
331
358
332
359
let artifact_builder_service = MithrilSignedEntityService :: new (
@@ -338,7 +365,7 @@ mod tests {
338
365
339
366
let signed_entity_type = SignedEntityType :: CardanoImmutableFilesFull ( Beacon :: default ( ) ) ;
340
367
let artifact = artifact_builder_service
341
- . compute_artifact ( signed_entity_type, & certificate)
368
+ . compute_artifact ( signed_entity_type. clone ( ) , & certificate)
342
369
. await
343
370
. unwrap ( ) ;
344
371
let snapshot_computed: Snapshot =
@@ -347,5 +374,44 @@ mod tests {
347
374
serde_json:: to_string( & snapshot_expected) . unwrap( ) ,
348
375
serde_json:: to_string( & snapshot_computed) . unwrap( )
349
376
) ;
377
+
378
+ artifact_builder_service
379
+ . create_artifact ( signed_entity_type, & certificate)
380
+ . await
381
+ . expect ( "Create artifact should not fail for CardanoImmutableFilesFull signed entity" ) ;
382
+ }
383
+
384
+ #[ tokio:: test]
385
+ async fn build_artifact_for_cardano_transactions_store_nothing_in_db ( ) {
386
+ let mut mock_signed_entity_storer = MockSignedEntityStorer :: new ( ) ;
387
+ mock_signed_entity_storer
388
+ . expect_store_signed_entity ( )
389
+ . never ( ) ;
390
+
391
+ let mock_mithril_stake_distribution_artifact_builder =
392
+ MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ;
393
+ let mock_cardano_immutable_files_full_artifact_builder =
394
+ MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ;
395
+
396
+ let artifact_builder_service = MithrilSignedEntityService :: new (
397
+ Arc :: new ( mock_signed_entity_storer) ,
398
+ Arc :: new ( mock_mithril_stake_distribution_artifact_builder) ,
399
+ Arc :: new ( mock_cardano_immutable_files_full_artifact_builder) ,
400
+ ) ;
401
+
402
+ let certificate = fake_data:: certificate ( "hash" . to_string ( ) ) ;
403
+
404
+ let signed_entity_type = SignedEntityType :: CardanoTransactions ( Beacon :: default ( ) ) ;
405
+ let artifact = artifact_builder_service
406
+ . compute_artifact ( signed_entity_type. clone ( ) , & certificate)
407
+ . await
408
+ . unwrap ( ) ;
409
+
410
+ assert ! ( artifact. is_none( ) ) ;
411
+
412
+ artifact_builder_service
413
+ . create_artifact ( signed_entity_type, & certificate)
414
+ . await
415
+ . expect ( "Create artifact should not fail for CardanoTransactions signed entity" ) ;
350
416
}
351
417
}
0 commit comments