Skip to content

Commit

Permalink
test: verify artifact download by epoch and by hash in the E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Aug 8, 2024
1 parent cd378be commit c3519bc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
38 changes: 32 additions & 6 deletions mithril-test-lab/mithril-end-to-end/src/assertions/check.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -240,15 +240,15 @@ pub async fn assert_signer_is_signing_cardano_transactions(

pub async fn assert_node_producing_cardano_stake_distribution(
aggregator_endpoint: &str,
) -> StdResult<String> {
) -> StdResult<(String, Epoch)> {
let url = format!("{aggregator_endpoint}/artifact/cardano-stake-distributions");
info!("Waiting for the aggregator to produce a Cardano stake distribution");

match attempt!(45, Duration::from_millis(2000), {
match reqwest::get(url.clone()).await {
Ok(response) => match response.status() {
StatusCode::OK => match response.json::<CardanoStakeDistributionListMessage>().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}",)),
},
Expand All @@ -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!(
Expand Down Expand Up @@ -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(())
}
10 changes: 9 additions & 1 deletion 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 @@ -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?;
Expand All @@ -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?;
}
}

Expand Down
40 changes: 40 additions & 0 deletions mithril-test-lab/mithril-end-to-end/src/mithril/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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 {
Expand All @@ -120,6 +149,9 @@ impl ClientCommand {
ClientCommand::CardanoTransaction(cmd) => {
format!("ctx-{}", cmd.name())
}
ClientCommand::CardanoStakeDistribution(cmd) => {
format!("csd-{}", cmd.name())
}
}
}

Expand All @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions mithril-test-lab/mithril-end-to-end/src/mithril/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c3519bc

Please sign in to comment.