Skip to content

Commit 8f9a650

Browse files
committed
fix: produce artifact for 'CardanoTransactions' in signed entity service
1 parent cd80429 commit 8f9a650

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

mithril-aggregator/src/services/signed_entity.rs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ impl MithrilSignedEntityService {
9797
&self,
9898
signed_entity_type: SignedEntityType,
9999
certificate: &Certificate,
100-
) -> StdResult<Option<Arc<dyn Artifact>>> {
100+
) -> StdResult<Arc<dyn Artifact>> {
101101
match signed_entity_type.clone() {
102-
SignedEntityType::MithrilStakeDistribution(epoch) => Ok(Some(Arc::new(
102+
SignedEntityType::MithrilStakeDistribution(epoch) => Ok(Arc::new(
103103
self.mithril_stake_distribution_artifact_builder
104104
.compute_artifact(epoch, certificate)
105105
.await
@@ -108,8 +108,8 @@ impl MithrilSignedEntityService {
108108
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
109109
)
110110
})?,
111-
))),
112-
SignedEntityType::CardanoImmutableFilesFull(beacon) => Ok(Some(Arc::new(
111+
)),
112+
SignedEntityType::CardanoImmutableFilesFull(beacon) => Ok(Arc::new(
113113
self.cardano_immutable_files_full_artifact_builder
114114
.compute_artifact(beacon.clone(), certificate)
115115
.await
@@ -118,9 +118,9 @@ impl MithrilSignedEntityService {
118118
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
119119
)
120120
})?,
121-
))),
121+
)),
122122
SignedEntityType::CardanoStakeDistribution(_) => todo!(),
123-
SignedEntityType::CardanoTransactions(beacon) => Ok(Some(Arc::new(
123+
SignedEntityType::CardanoTransactions(beacon) => Ok(Arc::new(
124124
self.cardano_transactions_artifact_builder
125125
.compute_artifact(beacon.clone(), certificate)
126126
.await
@@ -129,7 +129,7 @@ impl MithrilSignedEntityService {
129129
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
130130
)
131131
})?,
132-
))),
132+
)),
133133
}
134134
}
135135
}
@@ -157,8 +157,7 @@ impl SignedEntityService for MithrilSignedEntityService {
157157
{
158158
Err(error) if remaining_retries == 0 => break Err(error),
159159
Err(_error) => (),
160-
Ok(Some(artifact)) => break Ok(artifact),
161-
Ok(None) => return Ok(()),
160+
Ok(artifact) => break Ok(artifact),
162161
};
163162
}?;
164163

@@ -277,7 +276,10 @@ impl SignedEntityService for MithrilSignedEntityService {
277276

278277
#[cfg(test)]
279278
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+
};
281283

282284
use super::*;
283285

@@ -358,9 +360,10 @@ mod tests {
358360

359361
let mock_mithril_stake_distribution_artifact_builder =
360362
MockArtifactBuilder::<Epoch, MithrilStakeDistribution>::new();
361-
362363
let mut mock_cardano_immutable_files_full_artifact_builder =
363364
MockArtifactBuilder::<Beacon, Snapshot>::new();
365+
let mock_cardano_transactions_artifact_builder =
366+
MockArtifactBuilder::<Beacon, CardanoTransactionsCommitment>::new();
364367

365368
let snapshot_expected_clone = snapshot_expected.clone();
366369
mock_cardano_immutable_files_full_artifact_builder
@@ -373,8 +376,6 @@ mod tests {
373376
.expect_compute_artifact()
374377
.times(1)
375378
.return_once(move |_, _| Ok(snapshot_expected_clone));
376-
let mock_cardano_transactions_artifact_builder =
377-
MockArtifactBuilder::<Beacon, CardanoTransactionsCommitment>::new();
378379

379380
let artifact_builder_service = MithrilSignedEntityService::new(
380381
Arc::new(mock_signed_entity_storer),
@@ -404,22 +405,31 @@ mod tests {
404405

405406
#[tokio::test]
406407
async fn build_artifact_for_cardano_transactions_store_nothing_in_db() {
408+
let expected = CardanoTransactionsCommitment::new("merkle_root".to_string());
407409
let mut mock_signed_entity_storer = MockSignedEntityStorer::new();
408410
mock_signed_entity_storer
409411
.expect_store_signed_entity()
410-
.never();
412+
.return_once(|_| Ok(()));
411413

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 =
417415
MockArtifactBuilder::<Beacon, CardanoTransactionsCommitment>::new();
418416

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+
419429
let artifact_builder_service = MithrilSignedEntityService::new(
420430
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()),
423433
Arc::new(mock_cardano_transactions_artifact_builder),
424434
);
425435

@@ -430,8 +440,13 @@ mod tests {
430440
.compute_artifact(signed_entity_type.clone(), &certificate)
431441
.await
432442
.unwrap();
443+
let commitment_computed: CardanoTransactionsCommitment =
444+
serde_json::from_str(&serde_json::to_string(&artifact).unwrap()).unwrap();
433445

434-
assert!(artifact.is_none());
446+
assert_eq!(
447+
serde_json::to_string(&expected).unwrap(),
448+
serde_json::to_string(&commitment_computed).unwrap()
449+
);
435450

436451
artifact_builder_service
437452
.create_artifact(signed_entity_type, &certificate)

0 commit comments

Comments
 (0)