From 8616fdb28c6267c6d229ebff5629b4f7cadd45d9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 7 Jan 2025 18:24:26 +0100 Subject: [PATCH] feat: check immutable digest route produces non empty map in e2e test --- .../src/assertions/check.rs | 56 +++++++++++++++++-- .../mithril-end-to-end/src/end_to_end_spec.rs | 3 + 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/mithril-test-lab/mithril-end-to-end/src/assertions/check.rs b/mithril-test-lab/mithril-end-to-end/src/assertions/check.rs index b62f8425dd..260b4ded5f 100644 --- a/mithril-test-lab/mithril-end-to-end/src/assertions/check.rs +++ b/mithril-test-lab/mithril-end-to-end/src/assertions/check.rs @@ -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, }; @@ -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> { + 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>> { + match reqwest::get(url.clone()).await { + Ok(response) => match response.status() { + StatusCode::OK => match response + .json::() + .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 { diff --git a/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs b/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs index dbdb2e6cb5..57aae960f7 100644 --- a/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs +++ b/mithril-test-lab/mithril-end-to-end/src/end_to_end_spec.rs @@ -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?;