From c3519bc5c2907a815ecb26d4aa12284f3c94af65 Mon Sep 17 00:00:00 2001 From: Damien Lachaume <135982616+dlachaume@users.noreply.github.com> Date: Thu, 8 Aug 2024 10:47:56 +0200 Subject: [PATCH] test: verify artifact download by epoch and by hash in the E2E test --- .../src/assertions/check.rs | 38 +++++++++++++++--- .../mithril-end-to-end/src/end_to_end_spec.rs | 10 ++++- .../mithril-end-to-end/src/mithril/client.rs | 40 +++++++++++++++++++ .../mithril-end-to-end/src/mithril/mod.rs | 4 +- 4 files changed, 83 insertions(+), 9 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 9c9f2b2c5cd..07280c3ae4b 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 @@ -1,6 +1,6 @@ use crate::{ - attempt, utils::AttemptResult, CardanoDbCommand, CardanoTransactionCommand, Client, - ClientCommand, MithrilStakeDistributionCommand, + attempt, utils::AttemptResult, CardanoDbCommand, CardanoStakeDistributionCommand, + CardanoTransactionCommand, Client, ClientCommand, MithrilStakeDistributionCommand, }; use anyhow::{anyhow, Context}; use mithril_common::{ @@ -240,7 +240,7 @@ pub async fn assert_signer_is_signing_cardano_transactions( pub async fn assert_node_producing_cardano_stake_distribution( aggregator_endpoint: &str, -) -> StdResult { +) -> StdResult<(String, Epoch)> { let url = format!("{aggregator_endpoint}/artifact/cardano-stake-distributions"); info!("Waiting for the aggregator to produce a Cardano stake distribution"); @@ -248,7 +248,7 @@ pub async fn assert_node_producing_cardano_stake_distribution( match reqwest::get(url.clone()).await { Ok(response) => match response.status() { StatusCode::OK => match response.json::().await.as_deref() { - Ok([stake_distribution, ..]) => Ok(Some(stake_distribution.hash.clone())), + Ok([stake_distribution, ..]) => Ok(Some((stake_distribution.hash.clone(), stake_distribution.epoch))), Ok(&[]) => Ok(None), Err(err) => Err(anyhow!("Invalid Cardano stake distribution body : {err}",)), }, @@ -257,9 +257,9 @@ pub async fn assert_node_producing_cardano_stake_distribution( Err(err) => Err(anyhow!(err).context(format!("Request to `{url}` failed"))), } }) { - AttemptResult::Ok(hash) => { + AttemptResult::Ok((hash, epoch)) => { info!("Aggregator produced a Cardano stake distribution"; "hash" => &hash); - Ok(hash) + Ok((hash, epoch)) } AttemptResult::Err(error) => Err(error), AttemptResult::Timeout() => Err(anyhow!( @@ -426,3 +426,29 @@ pub async fn assert_client_can_verify_transactions( )) } } + +pub async fn assert_client_can_verify_cardano_stake_distribution( + client: &mut Client, + hash: &str, + epoch: Epoch, +) -> StdResult<()> { + client + .run(ClientCommand::CardanoStakeDistribution( + CardanoStakeDistributionCommand::Download { + unique_identifier: epoch.to_string(), + }, + )) + .await?; + info!("Client downloaded the Cardano stake distribution by epoch"; "epoch" => epoch.to_string()); + + client + .run(ClientCommand::CardanoStakeDistribution( + CardanoStakeDistributionCommand::Download { + unique_identifier: epoch.to_string(), + }, + )) + .await?; + info!("Client downloaded the Cardano stake distribution by hash"; "hash" => hash.to_string()); + + Ok(()) +} 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 81c52ea0481..4fac42eb0f8 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 @@ -145,7 +145,7 @@ impl<'a> Spec<'a> { // Verify that Cardano stake distribution artifacts are produced and signed correctly if self.infrastructure.is_signing_cardano_stake_distribution() { { - let hash = assertions::assert_node_producing_cardano_stake_distribution( + let (hash, epoch) = assertions::assert_node_producing_cardano_stake_distribution( &aggregator_endpoint, ) .await?; @@ -162,6 +162,14 @@ impl<'a> Spec<'a> { self.infrastructure.signers().len(), ) .await?; + + let mut client = self.infrastructure.build_client()?; + assertions::assert_client_can_verify_cardano_stake_distribution( + &mut client, + &hash, + epoch, + ) + .await?; } } diff --git a/mithril-test-lab/mithril-end-to-end/src/mithril/client.rs b/mithril-test-lab/mithril-end-to-end/src/mithril/client.rs index 6328c3c8c48..21d7987dbb7 100644 --- a/mithril-test-lab/mithril-end-to-end/src/mithril/client.rs +++ b/mithril-test-lab/mithril-end-to-end/src/mithril/client.rs @@ -103,11 +103,40 @@ impl CardanoTransactionCommand { } } +#[derive(Debug)] +pub enum CardanoStakeDistributionCommand { + List, + Download { unique_identifier: String }, +} + +impl CardanoStakeDistributionCommand { + fn name(&self) -> String { + match self { + CardanoStakeDistributionCommand::List => "list".to_string(), + CardanoStakeDistributionCommand::Download { unique_identifier } => { + format!("download-{unique_identifier}") + } + } + } + + fn cli_arg(&self) -> Vec { + match self { + CardanoStakeDistributionCommand::List => { + vec!["list".to_string()] + } + CardanoStakeDistributionCommand::Download { unique_identifier } => { + vec!["download".to_string(), unique_identifier.clone()] + } + } + } +} + #[derive(Debug)] pub enum ClientCommand { CardanoDb(CardanoDbCommand), MithrilStakeDistribution(MithrilStakeDistributionCommand), CardanoTransaction(CardanoTransactionCommand), + CardanoStakeDistribution(CardanoStakeDistributionCommand), } impl ClientCommand { @@ -120,6 +149,9 @@ impl ClientCommand { ClientCommand::CardanoTransaction(cmd) => { format!("ctx-{}", cmd.name()) } + ClientCommand::CardanoStakeDistribution(cmd) => { + format!("csd-{}", cmd.name()) + } } } @@ -138,6 +170,14 @@ impl ClientCommand { cmd.cli_arg(), ] .concat(), + ClientCommand::CardanoStakeDistribution(cmd) => [ + vec![ + "--unstable".to_string(), + "cardano-stake-distribution".to_string(), + ], + cmd.cli_arg(), + ] + .concat(), }; args.push("--json".to_string()); diff --git a/mithril-test-lab/mithril-end-to-end/src/mithril/mod.rs b/mithril-test-lab/mithril-end-to-end/src/mithril/mod.rs index 0169f949a8d..73f36024817 100644 --- a/mithril-test-lab/mithril-end-to-end/src/mithril/mod.rs +++ b/mithril-test-lab/mithril-end-to-end/src/mithril/mod.rs @@ -8,8 +8,8 @@ mod signer; pub use aggregator::{Aggregator, AggregatorConfig}; pub use client::{ - CardanoDbCommand, CardanoTransactionCommand, Client, ClientCommand, - MithrilStakeDistributionCommand, + CardanoDbCommand, CardanoStakeDistributionCommand, CardanoTransactionCommand, Client, + ClientCommand, MithrilStakeDistributionCommand, }; pub use infrastructure::{MithrilInfrastructure, MithrilInfrastructureConfig}; pub use relay_aggregator::RelayAggregator;