@@ -97,9 +97,9 @@ impl MithrilSignedEntityService {
97
97
& self ,
98
98
signed_entity_type : SignedEntityType ,
99
99
certificate : & Certificate ,
100
- ) -> StdResult < Option < Arc < dyn Artifact > > > {
100
+ ) -> StdResult < Arc < dyn Artifact > > {
101
101
match signed_entity_type. clone ( ) {
102
- SignedEntityType :: MithrilStakeDistribution ( epoch) => Ok ( Some ( Arc :: new (
102
+ SignedEntityType :: MithrilStakeDistribution ( epoch) => Ok ( Arc :: new (
103
103
self . mithril_stake_distribution_artifact_builder
104
104
. compute_artifact ( epoch, certificate)
105
105
. await
@@ -108,8 +108,8 @@ impl MithrilSignedEntityService {
108
108
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
109
109
)
110
110
} ) ?,
111
- ) ) ) ,
112
- SignedEntityType :: CardanoImmutableFilesFull ( beacon) => Ok ( Some ( Arc :: new (
111
+ ) ) ,
112
+ SignedEntityType :: CardanoImmutableFilesFull ( beacon) => Ok ( Arc :: new (
113
113
self . cardano_immutable_files_full_artifact_builder
114
114
. compute_artifact ( beacon. clone ( ) , certificate)
115
115
. await
@@ -118,9 +118,9 @@ impl MithrilSignedEntityService {
118
118
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
119
119
)
120
120
} ) ?,
121
- ) ) ) ,
121
+ ) ) ,
122
122
SignedEntityType :: CardanoStakeDistribution ( _) => todo ! ( ) ,
123
- SignedEntityType :: CardanoTransactions ( beacon) => Ok ( Some ( Arc :: new (
123
+ SignedEntityType :: CardanoTransactions ( beacon) => Ok ( Arc :: new (
124
124
self . cardano_transactions_artifact_builder
125
125
. compute_artifact ( beacon. clone ( ) , certificate)
126
126
. await
@@ -129,7 +129,7 @@ impl MithrilSignedEntityService {
129
129
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
130
130
)
131
131
} ) ?,
132
- ) ) ) ,
132
+ ) ) ,
133
133
}
134
134
}
135
135
}
@@ -157,8 +157,7 @@ impl SignedEntityService for MithrilSignedEntityService {
157
157
{
158
158
Err ( error) if remaining_retries == 0 => break Err ( error) ,
159
159
Err ( _error) => ( ) ,
160
- Ok ( Some ( artifact) ) => break Ok ( artifact) ,
161
- Ok ( None ) => return Ok ( ( ) ) ,
160
+ Ok ( artifact) => break Ok ( artifact) ,
162
161
} ;
163
162
} ?;
164
163
@@ -277,7 +276,10 @@ impl SignedEntityService for MithrilSignedEntityService {
277
276
278
277
#[ cfg( test) ]
279
278
mod tests {
280
- use mithril_common:: { entities:: Epoch , test_utils:: fake_data} ;
279
+ use mithril_common:: {
280
+ entities:: { CardanoTransactionsCommitment , Epoch } ,
281
+ test_utils:: fake_data,
282
+ } ;
281
283
282
284
use super :: * ;
283
285
@@ -358,9 +360,10 @@ mod tests {
358
360
359
361
let mock_mithril_stake_distribution_artifact_builder =
360
362
MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ;
361
-
362
363
let mut mock_cardano_immutable_files_full_artifact_builder =
363
364
MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ;
365
+ let mock_cardano_transactions_artifact_builder =
366
+ MockArtifactBuilder :: < Beacon , CardanoTransactionsCommitment > :: new ( ) ;
364
367
365
368
let snapshot_expected_clone = snapshot_expected. clone ( ) ;
366
369
mock_cardano_immutable_files_full_artifact_builder
@@ -373,8 +376,6 @@ mod tests {
373
376
. expect_compute_artifact ( )
374
377
. times ( 1 )
375
378
. return_once ( move |_, _| Ok ( snapshot_expected_clone) ) ;
376
- let mock_cardano_transactions_artifact_builder =
377
- MockArtifactBuilder :: < Beacon , CardanoTransactionsCommitment > :: new ( ) ;
378
379
379
380
let artifact_builder_service = MithrilSignedEntityService :: new (
380
381
Arc :: new ( mock_signed_entity_storer) ,
@@ -404,22 +405,31 @@ mod tests {
404
405
405
406
#[ tokio:: test]
406
407
async fn build_artifact_for_cardano_transactions_store_nothing_in_db ( ) {
408
+ let expected = CardanoTransactionsCommitment :: new ( "merkle_root" . to_string ( ) ) ;
407
409
let mut mock_signed_entity_storer = MockSignedEntityStorer :: new ( ) ;
408
410
mock_signed_entity_storer
409
411
. expect_store_signed_entity ( )
410
- . never ( ) ;
412
+ . return_once ( |_| Ok ( ( ) ) ) ;
411
413
412
- let mock_mithril_stake_distribution_artifact_builder =
413
- MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ;
414
- let mock_cardano_immutable_files_full_artifact_builder =
415
- MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ;
416
- let mock_cardano_transactions_artifact_builder =
414
+ let mut mock_cardano_transactions_artifact_builder =
417
415
MockArtifactBuilder :: < Beacon , CardanoTransactionsCommitment > :: new ( ) ;
418
416
417
+ let commitment_expected_clone = expected. clone ( ) ;
418
+ mock_cardano_transactions_artifact_builder
419
+ . expect_compute_artifact ( )
420
+ . times ( 1 )
421
+ . return_once ( move |_, _| Ok ( commitment_expected_clone) ) ;
422
+
423
+ let commitment_expected_clone = expected. clone ( ) ;
424
+ mock_cardano_transactions_artifact_builder
425
+ . expect_compute_artifact ( )
426
+ . times ( 1 )
427
+ . return_once ( move |_, _| Ok ( commitment_expected_clone) ) ;
428
+
419
429
let artifact_builder_service = MithrilSignedEntityService :: new (
420
430
Arc :: new ( mock_signed_entity_storer) ,
421
- Arc :: new ( mock_mithril_stake_distribution_artifact_builder ) ,
422
- Arc :: new ( mock_cardano_immutable_files_full_artifact_builder ) ,
431
+ Arc :: new ( MockArtifactBuilder :: < Epoch , MithrilStakeDistribution > :: new ( ) ) ,
432
+ Arc :: new ( MockArtifactBuilder :: < Beacon , Snapshot > :: new ( ) ) ,
423
433
Arc :: new ( mock_cardano_transactions_artifact_builder) ,
424
434
) ;
425
435
@@ -430,8 +440,13 @@ mod tests {
430
440
. compute_artifact ( signed_entity_type. clone ( ) , & certificate)
431
441
. await
432
442
. unwrap ( ) ;
443
+ let commitment_computed: CardanoTransactionsCommitment =
444
+ serde_json:: from_str ( & serde_json:: to_string ( & artifact) . unwrap ( ) ) . unwrap ( ) ;
433
445
434
- assert ! ( artifact. is_none( ) ) ;
446
+ assert_eq ! (
447
+ serde_json:: to_string( & expected) . unwrap( ) ,
448
+ serde_json:: to_string( & commitment_computed) . unwrap( )
449
+ ) ;
435
450
436
451
artifact_builder_service
437
452
. create_artifact ( signed_entity_type, & certificate)
0 commit comments