Skip to content

Commit d774c71

Browse files
committed
feat: skip artifact production for 'CardanoTransactions' signed entity type
1 parent ac59749 commit d774c71

File tree

1 file changed

+80
-14
lines changed

1 file changed

+80
-14
lines changed

mithril-aggregator/src/services/signed_entity.rs

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ impl MithrilSignedEntityService {
9191
&self,
9292
signed_entity_type: SignedEntityType,
9393
certificate: &Certificate,
94-
) -> StdResult<Arc<dyn Artifact>> {
94+
) -> StdResult<Option<Arc<dyn Artifact>>> {
9595
match signed_entity_type.clone() {
96-
SignedEntityType::MithrilStakeDistribution(epoch) => Ok(Arc::new(
96+
SignedEntityType::MithrilStakeDistribution(epoch) => Ok(Some(Arc::new(
9797
self.mithril_stake_distribution_artifact_builder
9898
.compute_artifact(epoch, certificate)
9999
.await
@@ -102,8 +102,8 @@ impl MithrilSignedEntityService {
102102
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
103103
)
104104
})?,
105-
)),
106-
SignedEntityType::CardanoImmutableFilesFull(beacon) => Ok(Arc::new(
105+
))),
106+
SignedEntityType::CardanoImmutableFilesFull(beacon) => Ok(Some(Arc::new(
107107
self.cardano_immutable_files_full_artifact_builder
108108
.compute_artifact(beacon.clone(), certificate)
109109
.await
@@ -112,9 +112,9 @@ impl MithrilSignedEntityService {
112112
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
113113
)
114114
})?,
115-
)),
115+
))),
116116
SignedEntityType::CardanoStakeDistribution(_) => todo!(),
117-
SignedEntityType::CardanoTransactions(_) => todo!(),
117+
SignedEntityType::CardanoTransactions(_) => Ok(None),
118118
}
119119
}
120120
}
@@ -142,7 +142,8 @@ impl SignedEntityService for MithrilSignedEntityService {
142142
{
143143
Err(error) if remaining_retries == 0 => break Err(error),
144144
Err(_error) => (),
145-
Ok(artifact) => break Ok(artifact),
145+
Ok(Some(artifact)) => break Ok(artifact),
146+
Ok(None) => return Ok(()),
146147
};
147148
}?;
148149

@@ -278,12 +279,22 @@ mod tests {
278279
signers_with_stake,
279280
&fake_data::protocol_parameters(),
280281
);
281-
let mithril_stake_distribution_clone = mithril_stake_distribution_expected.clone();
282282

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(()));
284288

285289
let mut mock_mithril_stake_distribution_artifact_builder =
286290
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();
287298
mock_mithril_stake_distribution_artifact_builder
288299
.expect_compute_artifact()
289300
.once()
@@ -301,7 +312,7 @@ mod tests {
301312

302313
let signed_entity_type = SignedEntityType::MithrilStakeDistribution(Epoch(1));
303314
let artifact = artifact_builder_service
304-
.compute_artifact(signed_entity_type, &certificate)
315+
.compute_artifact(signed_entity_type.clone(), &certificate)
305316
.await
306317
.unwrap();
307318
let mithril_stake_distribution_computed: MithrilStakeDistribution =
@@ -310,23 +321,39 @@ mod tests {
310321
serde_json::to_string(&mithril_stake_distribution_expected).unwrap(),
311322
serde_json::to_string(&mithril_stake_distribution_computed).unwrap()
312323
);
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");
313329
}
314330

315331
#[tokio::test]
316332
async fn build_snapshot_artifact_when_given_cardano_immutable_files_full_entity_type() {
317333
let snapshot_expected = fake_data::snapshots(1).first().unwrap().to_owned();
318-
let snapshot_expected_clone = snapshot_expected.clone();
319334

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(()));
321340

322341
let mock_mithril_stake_distribution_artifact_builder =
323342
MockArtifactBuilder::<Epoch, MithrilStakeDistribution>::new();
324343

325344
let mut mock_cardano_immutable_files_full_artifact_builder =
326345
MockArtifactBuilder::<Beacon, Snapshot>::new();
346+
347+
let snapshot_expected_clone = snapshot_expected.clone();
327348
mock_cardano_immutable_files_full_artifact_builder
328349
.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)
330357
.return_once(move |_, _| Ok(snapshot_expected_clone));
331358

332359
let artifact_builder_service = MithrilSignedEntityService::new(
@@ -338,7 +365,7 @@ mod tests {
338365

339366
let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(Beacon::default());
340367
let artifact = artifact_builder_service
341-
.compute_artifact(signed_entity_type, &certificate)
368+
.compute_artifact(signed_entity_type.clone(), &certificate)
342369
.await
343370
.unwrap();
344371
let snapshot_computed: Snapshot =
@@ -347,5 +374,44 @@ mod tests {
347374
serde_json::to_string(&snapshot_expected).unwrap(),
348375
serde_json::to_string(&snapshot_computed).unwrap()
349376
);
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");
350416
}
351417
}

0 commit comments

Comments
 (0)