Skip to content

Commit

Permalink
feat: check immutable digest route produces non empty map in e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Jan 7, 2025
1 parent 06a0dbc commit 8616fdb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
56 changes: 51 additions & 5 deletions mithril-test-lab/mithril-end-to-end/src/assertions/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use anyhow::{anyhow, Context};
use mithril_common::{
entities::{Epoch, TransactionHash},
messages::{
CardanoDatabaseSnapshotListMessage, CardanoDatabaseSnapshotMessage,
CardanoStakeDistributionListMessage, CardanoStakeDistributionMessage,
CardanoTransactionSnapshotListMessage, CardanoTransactionSnapshotMessage,
CertificateMessage, MithrilStakeDistributionListMessage, MithrilStakeDistributionMessage,
SnapshotMessage,
CardanoDatabaseDigestListMessage, CardanoDatabaseSnapshotListMessage,
CardanoDatabaseSnapshotMessage, CardanoStakeDistributionListMessage,
CardanoStakeDistributionMessage, CardanoTransactionSnapshotListMessage,
CardanoTransactionSnapshotMessage, CertificateMessage, MithrilStakeDistributionListMessage,
MithrilStakeDistributionMessage, SnapshotMessage,
},
StdResult,
};
Expand Down Expand Up @@ -277,6 +277,52 @@ pub async fn assert_signer_is_signing_cardano_database_snapshot(
}
}

pub async fn assert_node_producing_cardano_database_digests_map(
aggregator_endpoint: &str,
) -> StdResult<Vec<(String, String)>> {
let url = format!("{aggregator_endpoint}/artifact/cardano-database/digests");
info!("Waiting for the aggregator to produce a Cardano database digests map");

async fn fetch_cardano_database_digests_map(
url: String,
) -> StdResult<Option<Vec<(String, String)>>> {
match reqwest::get(url.clone()).await {
Ok(response) => match response.status() {
StatusCode::OK => match response
.json::<CardanoDatabaseDigestListMessage>()
.await
.as_deref()
{
Ok(&[]) => Ok(None),
Ok(cardano_database_digests_map) => Ok(Some(
cardano_database_digests_map
.iter()
.map(|item| (item.immutable_file_name.clone(), item.digest.clone()))
.collect(),
)),
Err(err) => Err(anyhow!("Invalid Cardano database digests map body : {err}",)),
},
s => Err(anyhow!("Unexpected status code from Aggregator: {s}")),
},
Err(err) => Err(anyhow!(err).context(format!("Request to `{url}` failed"))),
}
}

// todo: reduce the number of attempts if we can reduce the delay between two immutables
match attempt!(45, Duration::from_millis(2000), {
fetch_cardano_database_digests_map(url.clone()).await
}) {
AttemptResult::Ok(cardano_database_digests_map) => {
info!("Aggregator produced a Cardano database digests map"; "total_digests" => &cardano_database_digests_map.len());
Ok(cardano_database_digests_map)
}
AttemptResult::Err(error) => Err(error),
AttemptResult::Timeout() => Err(anyhow!(
"Timeout exhausted assert_node_producing_cardano_database_digests_map, no response from `{url}`"
)),
}
}

pub async fn assert_node_producing_cardano_transactions(
aggregator_endpoint: &str,
) -> StdResult<String> {
Expand Down
3 changes: 3 additions & 0 deletions mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ impl<'a> Spec<'a> {
)
.await?;

assertions::assert_node_producing_cardano_database_digests_map(&aggregator_endpoint)
.await?;

// TODO: uncomment when the client can verify Cardano database snapshots
//let mut client = self.infrastructure.build_client()?;
//assertions::assert_client_can_verify_cardano_database_snapshot(&mut client, &digest).await?;
Expand Down

0 comments on commit 8616fdb

Please sign in to comment.