Skip to content

Commit

Permalink
Merge pull request #2237 from input-output-hk/jpraynaud/2211-integrat…
Browse files Browse the repository at this point in the history
…ion-test-cardano-database

Feat(tests): integration testing for `CardanoDatabase` certification
  • Loading branch information
jpraynaud authored Jan 22, 2025
2 parents 2aadbc6 + 889fc8f commit 5c76c76
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.6.15"
version = "0.6.16"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod handlers {
metrics_service: Arc<MetricsService>,
) -> Result<impl warp::Reply, Infallible> {
metrics_service
.get_artifact_detail_cardano_db_total_served_since_startup()
.get_artifact_detail_cardano_database_total_served_since_startup()
.increment();

match http_message_service
Expand Down Expand Up @@ -269,7 +269,7 @@ mod tests {
let dependency_manager = Arc::new(initialize_dependencies().await);
let initial_counter_value = dependency_manager
.metrics_service
.get_artifact_detail_cardano_db_total_served_since_startup()
.get_artifact_detail_cardano_database_total_served_since_startup()
.get();

request()
Expand All @@ -284,7 +284,7 @@ mod tests {
initial_counter_value + 1,
dependency_manager
.metrics_service
.get_artifact_detail_cardano_db_total_served_since_startup()
.get_artifact_detail_cardano_database_total_served_since_startup()
.get()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod handlers {
metrics_service: Arc<MetricsService>,
) -> Result<impl warp::Reply, Infallible> {
metrics_service
.get_artifact_detail_cardano_db_total_served_since_startup()
.get_artifact_detail_cardano_immutable_files_full_total_served_since_startup()
.increment();

match http_message_service
Expand Down Expand Up @@ -303,7 +303,7 @@ mod tests {
let dependency_manager = Arc::new(initialize_dependencies().await);
let initial_counter_value = dependency_manager
.metrics_service
.get_artifact_detail_cardano_db_total_served_since_startup()
.get_artifact_detail_cardano_immutable_files_full_total_served_since_startup()
.get();

request()
Expand All @@ -318,7 +318,7 @@ mod tests {
initial_counter_value + 1,
dependency_manager
.metrics_service
.get_artifact_detail_cardano_db_total_served_since_startup()
.get_artifact_detail_cardano_immutable_files_full_total_served_since_startup()
.get()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod handlers {
metrics_service: Arc<MetricsService>,
) -> Result<impl warp::Reply, Infallible> {
metrics_service
.get_cardano_db_total_restoration_since_startup()
.get_cardano_immutable_files_full_total_restoration_since_startup()
.increment();

let headers: Vec<(&str, &str)> = Vec::new();
Expand Down Expand Up @@ -134,7 +134,7 @@ mod tests {
let dependency_manager = Arc::new(initialize_dependencies().await);
let initial_counter_value = dependency_manager
.metrics_service
.get_cardano_db_total_restoration_since_startup()
.get_cardano_immutable_files_full_total_restoration_since_startup()
.get();

request()
Expand All @@ -150,7 +150,7 @@ mod tests {
initial_counter_value + 1,
dependency_manager
.metrics_service
.get_cardano_db_total_restoration_since_startup()
.get_cardano_immutable_files_full_total_restoration_since_startup()
.get()
);
}
Expand Down
24 changes: 14 additions & 10 deletions mithril-aggregator/src/metrics/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ build_metrics_service!(
"mithril_aggregator_certificate_detail_total_served_since_startup",
"Number of certificate details served since startup on a Mithril aggregator node"
),
artifact_detail_cardano_db_total_served_since_startup:MetricCounter(
artifact_detail_cardano_immutable_files_full_total_served_since_startup:MetricCounter(
"mithril_aggregator_artifact_detail_cardano_db_total_served_since_startup",
"Number of Cardano db artifact details served since startup on a Mithril aggregator node"
"Number of Cardano immutable files full artifact details served since startup on a Mithril aggregator node"
),
cardano_db_total_restoration_since_startup:MetricCounter(
cardano_immutable_files_full_total_restoration_since_startup:MetricCounter(
"mithril_aggregator_cardano_db_total_restoration_since_startup",
"Number of Cardano db restorations since startup on a Mithril aggregator node"
"Number of Cardano immutable files full restorations since startup on a Mithril aggregator node"
),
artifact_detail_cardano_database_total_served_since_startup:MetricCounter(
"mithril_aggregator_artifact_detail_cardano_database_total_served_since_startup",
"Number of Cardano database artifact details served since startup on a Mithril aggregator node"
),
artifact_detail_mithril_stake_distribution_total_served_since_startup:MetricCounter(
"mithril_aggregator_artifact_detail_mithril_stake_distribution_total_served_since_startup",
Expand Down Expand Up @@ -50,9 +54,13 @@ build_metrics_service!(
"mithril_aggregator_certificate_total_produced_since_startup",
"Number of certificates produced since startup on a Mithril aggregator node"
),
artifact_cardano_db_total_produced_since_startup:MetricCounter(
artifact_cardano_immutable_files_full_total_produced_since_startup:MetricCounter(
"mithril_aggregator_artifact_cardano_db_total_produced_since_startup",
"Number of Cardano db artifacts produced since startup on a Mithril aggregator node"
"Number of Cardano immutable files full artifacts produced since startup on a Mithril aggregator node"
),
artifact_cardano_database_total_produced_since_startup:MetricCounter(
"mithril_aggregator_artifact_cardano_database_total_produced_since_startup",
"Number of Cardano database artifacts produced since startup on a Mithril aggregator node"
),
artifact_mithril_stake_distribution_total_produced_since_startup:MetricCounter(
"mithril_aggregator_artifact_mithril_stake_distribution_total_produced_since_startup",
Expand All @@ -66,10 +74,6 @@ build_metrics_service!(
"mithril_aggregator_artifact_cardano_transaction_total_produced_since_startup",
"Number of Cardano transaction artifacts produced since startup on a Mithril aggregator node"
),
artifact_cardano_database_total_produced_since_startup:MetricCounter(
"mithril_aggregator_artifact_cardano_database_total_produced_since_startup",
"Number of Cardano database artifacts produced since startup on a Mithril aggregator node"
),
runtime_cycle_success_since_startup:MetricCounter(
"mithril_aggregator_runtime_cycle_success_since_startup",
"Number of successful runtime cycles since startup on a Mithril aggregator"
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/services/signed_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl MithrilSignedEntityService {
metrics.get_artifact_mithril_stake_distribution_total_produced_since_startup()
}
SignedEntityType::CardanoImmutableFilesFull(_) => {
metrics.get_artifact_cardano_db_total_produced_since_startup()
metrics.get_artifact_cardano_immutable_files_full_total_produced_since_startup()
}
SignedEntityType::CardanoStakeDistribution(_) => {
metrics.get_artifact_cardano_stake_distribution_total_produced_since_startup()
Expand Down Expand Up @@ -712,7 +712,7 @@ mod tests {
.get_artifact_mithril_stake_distribution_total_produced_since_startup()
.get(),
SignedEntityType::CardanoImmutableFilesFull(_) => metrics_service
.get_artifact_cardano_db_total_produced_since_startup()
.get_artifact_cardano_immutable_files_full_total_produced_since_startup()
.get(),
SignedEntityType::CardanoStakeDistribution(_) => metrics_service
.get_artifact_cardano_stake_distribution_total_produced_since_startup()
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/tests/certificate_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async fn certificate_chain() {
tester.metrics_verifier,
ExpectedMetrics::new()
.certificate_total(7)
.artifact_cardano_db_total(3)
.artifact_cardano_immutable_files_full_total(3)
.artifact_mithril_stake_distribution_total(4)
);
}
40 changes: 37 additions & 3 deletions mithril-aggregator/tests/create_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ async fn create_certificate() {
};
let configuration = Configuration {
protocol_parameters: protocol_parameters.clone(),
signed_entity_types: Some(SignedEntityTypeDiscriminants::CardanoTransactions.to_string()),
signed_entity_types: Some(
[
SignedEntityTypeDiscriminants::CardanoTransactions.to_string(),
SignedEntityTypeDiscriminants::CardanoDatabase.to_string(),
]
.join(","),
),
data_stores_directory: get_test_dir("create_certificate"),
cardano_transactions_signing_config: CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(0),
Expand Down Expand Up @@ -124,6 +130,33 @@ async fn create_certificate() {
)
);

comment!("The state machine should get back to signing to sign CardanoDatabase with the previously created immutable file");
cycle!(tester, "signing");
let signers_for_cardano_database = &fixture.signers_fixture()[1..=6];
tester
.send_single_signatures(
SignedEntityTypeDiscriminants::CardanoDatabase,
signers_for_cardano_database,
)
.await
.unwrap();

comment!("The state machine should issue a certificate for the CardanoDatabase");
cycle!(tester, "ready");
assert_last_certificate_eq!(
tester,
ExpectedCertificate::new(
Epoch(1),
&signers_for_cardano_database
.iter()
.map(|s| s.signer_with_stake.clone().into())
.collect::<Vec<_>>(),
fixture.compute_and_encode_avk(),
SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(1, 3)),
ExpectedCertificate::genesis_identifier(Epoch(1)),
)
);

comment!(
"Increase cardano chain block number to 185,
the state machine should be signing CardanoTransactions for block 179"
Expand Down Expand Up @@ -203,8 +236,9 @@ async fn create_certificate() {
assert_metrics_eq!(
tester.metrics_verifier,
ExpectedMetrics::new()
.certificate_total(4)
.artifact_cardano_db_total(1)
.certificate_total(5)
.artifact_cardano_immutable_files_full_total(1)
.artifact_cardano_database_total(1)
.artifact_mithril_stake_distribution_total(1)
.artifact_cardano_transaction_total(2)
);
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/tests/open_message_expiration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ async fn open_message_expiration() {
tester.metrics_verifier,
ExpectedMetrics::new()
.certificate_total(1)
.artifact_cardano_db_total(1)
.artifact_cardano_immutable_files_full_total(1)
);
}
2 changes: 1 addition & 1 deletion mithril-aggregator/tests/open_message_newer_exists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ async fn open_message_newer_exists() {
ExpectedMetrics::new()
.certificate_total(2)
.artifact_mithril_stake_distribution_total(1)
.artifact_cardano_db_total(1)
.artifact_cardano_immutable_files_full_total(1)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,13 @@ impl AggregatorObserver {
.await?
.first()
.map(|s| &s.signed_entity_type)),
// TODO: This case will be implemented once the signable and artifact builders are available.
SignedEntityType::CardanoDatabase(_) => Ok(false),
SignedEntityType::CardanoDatabase(_) => Ok(Some(signed_entity_type_expected)
== self
.signed_entity_service
.get_last_signed_cardano_database_snapshots(1)
.await?
.first()
.map(|s| &s.signed_entity_type)),
}
}
}
33 changes: 27 additions & 6 deletions mithril-aggregator/tests/test_extensions/metrics_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::sync::Arc;

pub struct ExpectedMetrics {
certificate_total: Option<u32>,
artifact_cardano_db_total: Option<u32>,
artifact_cardano_immutable_files_full_total: Option<u32>,
artifact_cardano_database_total: Option<u32>,
artifact_mithril_stake_distribution_total: Option<u32>,
artifact_cardano_stake_distribution_total: Option<u32>,
artifact_cardano_transaction_total: Option<u32>,
Expand All @@ -16,7 +17,8 @@ impl ExpectedMetrics {
pub fn new() -> Self {
Self {
certificate_total: None,
artifact_cardano_db_total: None,
artifact_cardano_immutable_files_full_total: None,
artifact_cardano_database_total: None,
artifact_mithril_stake_distribution_total: None,
artifact_cardano_stake_distribution_total: None,
artifact_cardano_transaction_total: None,
Expand All @@ -27,36 +29,49 @@ impl ExpectedMetrics {

pub fn certificate_total(mut self, value: u32) -> Self {
self.certificate_total = Some(value);

self
}

pub fn artifact_cardano_immutable_files_full_total(mut self, value: u32) -> Self {
self.artifact_cardano_immutable_files_full_total = Some(value);

self
}

pub fn artifact_cardano_db_total(mut self, value: u32) -> Self {
self.artifact_cardano_db_total = Some(value);
pub fn artifact_cardano_database_total(mut self, value: u32) -> Self {
self.artifact_cardano_database_total = Some(value);

self
}

pub fn artifact_mithril_stake_distribution_total(mut self, value: u32) -> Self {
self.artifact_mithril_stake_distribution_total = Some(value);

self
}

pub fn artifact_cardano_stake_distribution_total(mut self, value: u32) -> Self {
self.artifact_cardano_stake_distribution_total = Some(value);

self
}

pub fn artifact_cardano_transaction_total(mut self, value: u32) -> Self {
self.artifact_cardano_transaction_total = Some(value);

self
}

pub fn runtime_cycle_success(mut self, value: u32) -> Self {
self.runtime_cycle_success = Some(value);

self
}

pub fn runtime_cycle_total(mut self, value: u32) -> Self {
self.runtime_cycle_total = Some(value);

self
}
}
Expand Down Expand Up @@ -93,9 +108,15 @@ impl MetricsVerifier {
);

verify_metric!(
expected_metrics.artifact_cardano_db_total,
expected_metrics.artifact_cardano_immutable_files_full_total,
self.metrics_service
.get_artifact_cardano_immutable_files_full_total_produced_since_startup()
);

verify_metric!(
expected_metrics.artifact_cardano_database_total,
self.metrics_service
.get_artifact_cardano_db_total_produced_since_startup()
.get_artifact_cardano_database_total_produced_since_startup()
);

verify_metric!(
Expand Down

0 comments on commit 5c76c76

Please sign in to comment.