diff --git a/Cargo.lock b/Cargo.lock index 0b4e386bae5..6107dee327b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3918,7 +3918,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.7.74" +version = "0.7.75" dependencies = [ "anyhow", "async-trait", @@ -3999,7 +3999,7 @@ dependencies = [ [[package]] name = "mithril-api-spec" -version = "0.1.1" +version = "0.1.2" dependencies = [ "jsonschema", "mithril-common", @@ -4021,7 +4021,7 @@ dependencies = [ [[package]] name = "mithril-cardano-node-chain" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "async-trait", @@ -4080,7 +4080,7 @@ dependencies = [ [[package]] name = "mithril-client" -version = "0.12.22" +version = "0.12.23" dependencies = [ "anyhow", "async-recursion", @@ -4118,7 +4118,7 @@ dependencies = [ [[package]] name = "mithril-client-cli" -version = "0.12.22" +version = "0.12.23" dependencies = [ "anyhow", "async-trait", @@ -4170,7 +4170,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.6.9" +version = "0.6.10" dependencies = [ "anyhow", "async-trait", @@ -4212,7 +4212,7 @@ dependencies = [ [[package]] name = "mithril-dmq" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "async-trait", @@ -4271,7 +4271,7 @@ dependencies = [ [[package]] name = "mithril-era" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "async-trait", @@ -4320,7 +4320,7 @@ dependencies = [ [[package]] name = "mithril-relay" -version = "0.1.47" +version = "0.1.48" dependencies = [ "anyhow", "clap", @@ -4364,7 +4364,7 @@ dependencies = [ [[package]] name = "mithril-signed-entity-preloader" -version = "0.0.7" +version = "0.0.8" dependencies = [ "anyhow", "async-trait", @@ -4380,7 +4380,7 @@ dependencies = [ [[package]] name = "mithril-signer" -version = "0.2.260" +version = "0.2.261" dependencies = [ "anyhow", "async-trait", diff --git a/DEV-ADR.md b/DEV-ADR.md index 455bf0b9526..ccbd48d9eb9 100644 --- a/DEV-ADR.md +++ b/DEV-ADR.md @@ -23,6 +23,34 @@ To complete To complete --> +### 3. Guidelines for Dummy Test Doubles + +**Date:** 2025-07-22 +**Status:** Accepted + +#### Context + +The use of `dummy()` functions for creating test doubles is widespread across the codebase. However, inconsistencies +in their placement and visibility have led to maintenance challenges and reduced code clarity. + +#### Decision + +A `Dummy` trait will be introduced, functioning similarly to Rust's `Default` trait. + +The following guidelines will be adopted for implementing the `Dummy` trait: + +1. Most implementations should reside in a `test::double::dummies` module within the crate where the type is defined. +2. For types with non-public fields, the `Dummy` trait should be implemented directly below the type's definition. + +#### Consequences + +- Enhanced consistency in code organization. +- Improved discoverability of test doubles. +- Clearer distinction between production and test code. +- Simplified maintenance of test implementations. + +--- + ## 2. Remove Artifacts serialization support when compiling to WebAssembly date: 2025-02-26 diff --git a/internal/cardano-node/mithril-cardano-node-chain/Cargo.toml b/internal/cardano-node/mithril-cardano-node-chain/Cargo.toml index 9511916d7ea..2f1ea563933 100644 --- a/internal/cardano-node/mithril-cardano-node-chain/Cargo.toml +++ b/internal/cardano-node/mithril-cardano-node-chain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-cardano-node-chain" -version = "0.1.4" +version = "0.1.5" authors.workspace = true documentation.workspace = true edition.workspace = true diff --git a/internal/cardano-node/mithril-cardano-node-chain/src/test/double/chain_observer.rs b/internal/cardano-node/mithril-cardano-node-chain/src/test/double/chain_observer.rs index 00285b9a06e..0c671a5bc5e 100644 --- a/internal/cardano-node/mithril-cardano-node-chain/src/test/double/chain_observer.rs +++ b/internal/cardano-node/mithril-cardano-node-chain/src/test/double/chain_observer.rs @@ -212,7 +212,7 @@ impl ChainObserver for FakeChainObserver { #[cfg(test)] mod tests { - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use super::*; diff --git a/internal/mithril-dmq/Cargo.toml b/internal/mithril-dmq/Cargo.toml index 86b7036a5af..e660b212852 100644 --- a/internal/mithril-dmq/Cargo.toml +++ b/internal/mithril-dmq/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mithril-dmq" description = "Mechanisms to publish and consume messages of a 'Decentralized Message Queue network' through a DMQ node" -version = "0.1.4" +version = "0.1.5" authors.workspace = true documentation.workspace = true edition.workspace = true diff --git a/internal/mithril-dmq/src/message.rs b/internal/mithril-dmq/src/message.rs index e0c8021e259..08de36ae2c0 100644 --- a/internal/mithril-dmq/src/message.rs +++ b/internal/mithril-dmq/src/message.rs @@ -94,6 +94,7 @@ mod tests { use mithril_common::{ crypto_helper::{KesSignerFake, TryToBytes}, entities::{BlockNumber, ChainPoint, TimePoint}, + test_utils::double::Dummy, }; use super::*; diff --git a/internal/mithril-dmq/src/publisher/pallas.rs b/internal/mithril-dmq/src/publisher/pallas.rs index 4cae2ae4984..55f8329584b 100644 --- a/internal/mithril-dmq/src/publisher/pallas.rs +++ b/internal/mithril-dmq/src/publisher/pallas.rs @@ -82,7 +82,6 @@ impl DmqPublisher for DmqPublisherPallas #[cfg(all(test, unix))] mod tests { - use std::{fs, sync::Arc}; use pallas_network::miniprotocols::{ @@ -91,7 +90,11 @@ mod tests { use tokio::{net::UnixListener, task::JoinHandle}; use mithril_cardano_node_chain::test::double::FakeChainObserver; - use mithril_common::{crypto_helper::KesSignerFake, current_function, test_utils::TempDir}; + use mithril_common::{ + crypto_helper::KesSignerFake, + current_function, + test_utils::{TempDir, double::Dummy}, + }; use crate::{test::payload::DmqMessageTestPayload, test_tools::TestLogger}; diff --git a/internal/mithril-dmq/src/test/payload.rs b/internal/mithril-dmq/src/test/payload.rs index 2283155c4fc..6fd5098d515 100644 --- a/internal/mithril-dmq/src/test/payload.rs +++ b/internal/mithril-dmq/src/test/payload.rs @@ -3,6 +3,7 @@ use std::fmt::Debug; use mithril_common::{ StdResult, crypto_helper::{TryFromBytes, TryToBytes}, + test_utils::double::Dummy, }; /// A test message payload for the DMQ. @@ -18,9 +19,11 @@ impl DmqMessageTestPayload { message: bytes.to_vec(), } } +} +impl Dummy for DmqMessageTestPayload { /// Creates a dummy `DmqMessageTestPayload` with a predefined message. - pub fn dummy() -> Self { + fn dummy() -> Self { Self { message: b"dummy message".to_vec(), } diff --git a/internal/mithril-era/Cargo.toml b/internal/mithril-era/Cargo.toml index 729896b74ff..17c9791ab17 100644 --- a/internal/mithril-era/Cargo.toml +++ b/internal/mithril-era/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-era" -version = "0.1.2" +version = "0.1.3" authors.workspace = true documentation.workspace = true edition.workspace = true diff --git a/internal/mithril-era/src/adapters/bootstrap.rs b/internal/mithril-era/src/adapters/bootstrap.rs index f98fec178b3..ca3b0c1e38f 100644 --- a/internal/mithril-era/src/adapters/bootstrap.rs +++ b/internal/mithril-era/src/adapters/bootstrap.rs @@ -22,6 +22,8 @@ impl EraReaderAdapter for BootstrapAdapter { #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::*; #[tokio::test] diff --git a/internal/mithril-era/src/adapters/dummy.rs b/internal/mithril-era/src/adapters/dummy.rs index 0e7c641815d..1968496a84e 100644 --- a/internal/mithril-era/src/adapters/dummy.rs +++ b/internal/mithril-era/src/adapters/dummy.rs @@ -40,6 +40,7 @@ impl EraReaderAdapter for DummyAdapter { #[cfg(test)] mod tests { use mithril_common::entities::{Epoch, SupportedEra}; + use mithril_common::test_utils::double::Dummy; use super::*; diff --git a/internal/mithril-era/src/adapters/file.rs b/internal/mithril-era/src/adapters/file.rs index 496af5cd8e9..4d4de67b093 100644 --- a/internal/mithril-era/src/adapters/file.rs +++ b/internal/mithril-era/src/adapters/file.rs @@ -30,7 +30,7 @@ impl EraReaderAdapter for FileAdapter { #[cfg(test)] mod tests { use mithril_common::entities::{Epoch, SupportedEra}; - use mithril_common::test_utils::TempDir; + use mithril_common::test_utils::{TempDir, double::Dummy}; use super::*; diff --git a/internal/mithril-era/src/era_checker.rs b/internal/mithril-era/src/era_checker.rs index 1ee811a246c..828aae208da 100644 --- a/internal/mithril-era/src/era_checker.rs +++ b/internal/mithril-era/src/era_checker.rs @@ -55,6 +55,8 @@ impl ApiVersionDiscriminantSource for EraChecker { #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::*; #[test] diff --git a/internal/mithril-era/src/era_reader.rs b/internal/mithril-era/src/era_reader.rs index 200962d1a4a..691bf69390b 100644 --- a/internal/mithril-era/src/era_reader.rs +++ b/internal/mithril-era/src/era_reader.rs @@ -176,6 +176,8 @@ impl EraReader { #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::super::adapters::EraReaderDummyAdapter as DummyAdapter; use super::*; diff --git a/internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml b/internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml index 508cfa12760..eec113401e0 100644 --- a/internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml +++ b/internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signed-entity-preloader" -version = "0.0.7" +version = "0.0.8" description = "A preload mechanism for Cardano Transaction signed entity." authors = { workspace = true } edition = { workspace = true } diff --git a/internal/signed-entity/mithril-signed-entity-preloader/src/cardano_transactions_preloader.rs b/internal/signed-entity/mithril-signed-entity-preloader/src/cardano_transactions_preloader.rs index f50c729f31e..9cf2f04f759 100644 --- a/internal/signed-entity/mithril-signed-entity-preloader/src/cardano_transactions_preloader.rs +++ b/internal/signed-entity/mithril-signed-entity-preloader/src/cardano_transactions_preloader.rs @@ -128,6 +128,7 @@ mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_common::entities::{BlockNumber, ChainPoint, TimePoint}; + use mithril_common::test_utils::double::Dummy; use crate::test_tools::TestLogger; diff --git a/internal/tests/mithril-api-spec/Cargo.toml b/internal/tests/mithril-api-spec/Cargo.toml index 129c0d555bc..3e4ad960099 100644 --- a/internal/tests/mithril-api-spec/Cargo.toml +++ b/internal/tests/mithril-api-spec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-api-spec" -version = "0.1.1" +version = "0.1.2" authors.workspace = true documentation.workspace = true edition.workspace = true diff --git a/internal/tests/mithril-api-spec/src/apispec.rs b/internal/tests/mithril-api-spec/src/apispec.rs index de6a2d5d53d..74da2774683 100644 --- a/internal/tests/mithril-api-spec/src/apispec.rs +++ b/internal/tests/mithril-api-spec/src/apispec.rs @@ -343,7 +343,7 @@ mod tests { use mithril_common::entities; use mithril_common::messages::{AggregatorFeaturesMessage, SignerMessagePart}; - use mithril_common::test_utils::{TempDir, fake_data}; + use mithril_common::test_utils::{TempDir, double::Dummy, fake_data}; use super::*; diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index 2acddb8589a..fb6c02bd0a0 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.7.74" +version = "0.7.75" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs index b9792890deb..31a60961d92 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs @@ -206,7 +206,7 @@ impl AncillaryArtifactBuilder { mod tests { use std::path::PathBuf; - use mithril_common::test_utils::{TempDir, assert_equivalent}; + use mithril_common::test_utils::{TempDir, assert_equivalent, double::Dummy}; use crate::services::{DumbSnapshotter, MockSnapshotter}; use crate::test_tools::TestLogger; diff --git a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs index 7841e4f5758..f63382bebd4 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs @@ -299,7 +299,7 @@ mod tests { current_function, entities::{CardanoDbBeacon, CompressionAlgorithm}, messages::{CardanoDatabaseDigestListItemMessage, CardanoDatabaseDigestListMessage}, - test_utils::{TempDir, assert_equivalent}, + test_utils::{TempDir, assert_equivalent, double::Dummy}, }; use crate::{ diff --git a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs index d4baa074c18..a858d606135 100644 --- a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs +++ b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs @@ -38,7 +38,10 @@ impl ArtifactBuilder for MithrilStakeDistributi #[cfg(test)] mod tests { - use mithril_common::{crypto_helper::ProtocolParameters, test_utils::fake_data}; + use mithril_common::{ + crypto_helper::ProtocolParameters, + test_utils::{double::Dummy, fake_data}, + }; use std::sync::Arc; use tokio::sync::RwLock; diff --git a/mithril-aggregator/src/database/query/open_message/insert_or_replace_open_message.rs b/mithril-aggregator/src/database/query/open_message/insert_or_replace_open_message.rs index 358fed71d42..b5f35588ba3 100644 --- a/mithril-aggregator/src/database/query/open_message/insert_or_replace_open_message.rs +++ b/mithril-aggregator/src/database/query/open_message/insert_or_replace_open_message.rs @@ -34,6 +34,7 @@ impl Query for InsertOrReplaceOpenMessageQuery { #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::query::GetOpenMessageQuery; diff --git a/mithril-aggregator/src/database/record/immutable_file_digest.rs b/mithril-aggregator/src/database/record/immutable_file_digest.rs index 36e280d9a97..e7c587ae042 100644 --- a/mithril-aggregator/src/database/record/immutable_file_digest.rs +++ b/mithril-aggregator/src/database/record/immutable_file_digest.rs @@ -19,15 +19,6 @@ impl ImmutableFileDigestRecord { let aliases = SourceAlias::new(&[("{:immutable_file_digest:}", table)]); Self::get_projection().expand(aliases) } - - #[cfg(test)] - /// Create a dumb ImmutableFileDigestRecord instance mainly for test purposes - pub fn dummy() -> Self { - Self { - immutable_file_name: "123.chunk".to_string(), - digest: "dummy_digest".to_string(), - } - } } impl SqLiteEntity for ImmutableFileDigestRecord { diff --git a/mithril-aggregator/src/database/record/open_message.rs b/mithril-aggregator/src/database/record/open_message.rs index 40b0159dc75..062266164b0 100644 --- a/mithril-aggregator/src/database/record/open_message.rs +++ b/mithril-aggregator/src/database/record/open_message.rs @@ -43,25 +43,6 @@ impl OpenMessageRecord { pub fn new_id() -> Uuid { Uuid::new_v4() } - - #[cfg(test)] - /// Create a dumb OpenMessage instance mainly for test purposes - pub fn dummy() -> Self { - let beacon = mithril_common::test_utils::fake_data::beacon(); - let epoch = beacon.epoch; - let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon); - - Self { - open_message_id: Uuid::parse_str("193d1442-e89b-43cf-9519-04d8db9a12ff").unwrap(), - epoch, - signed_entity_type, - protocol_message: ProtocolMessage::new(), - is_certified: false, - is_expired: false, - created_at: Utc::now(), - expires_at: None, - } - } } impl SqLiteEntity for OpenMessageRecord { diff --git a/mithril-aggregator/src/database/repository/epoch_settings_store.rs b/mithril-aggregator/src/database/repository/epoch_settings_store.rs index 2fb2c266d0b..1a32f54947d 100644 --- a/mithril-aggregator/src/database/repository/epoch_settings_store.rs +++ b/mithril-aggregator/src/database/repository/epoch_settings_store.rs @@ -92,6 +92,8 @@ impl EpochPruningTask for EpochSettingsStore { #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use crate::database::test_helper::{insert_epoch_settings, main_db_connection}; use super::*; diff --git a/mithril-aggregator/src/database/repository/open_message_repository.rs b/mithril-aggregator/src/database/repository/open_message_repository.rs index 57f36635ee8..0d6aa6a2ba6 100644 --- a/mithril-aggregator/src/database/repository/open_message_repository.rs +++ b/mithril-aggregator/src/database/repository/open_message_repository.rs @@ -140,6 +140,7 @@ impl OpenMessageStorer for OpenMessageRepository { #[cfg(test)] mod tests { use mithril_common::entities::{BlockNumber, CardanoDbBeacon}; + use mithril_common::test_utils::double::Dummy; use crate::database::record::SingleSignatureRecord; use crate::database::test_helper::{ diff --git a/mithril-aggregator/src/dependency_injection/builder/support/compatibility.rs b/mithril-aggregator/src/dependency_injection/builder/support/compatibility.rs index 1ee493d080e..9c25a9ae75b 100644 --- a/mithril-aggregator/src/dependency_injection/builder/support/compatibility.rs +++ b/mithril-aggregator/src/dependency_injection/builder/support/compatibility.rs @@ -33,7 +33,7 @@ impl DependenciesBuilder { error: Some(e.into()), })?, _ => Arc::new(EraReaderDummyAdapter::from_markers(vec![EraMarker::new( - &SupportedEra::dummy().to_string(), + &SupportedEra::Pythagoras.to_string(), Some(Epoch(0)), )])), }; diff --git a/mithril-aggregator/src/entities/aggregator_epoch_settings.rs b/mithril-aggregator/src/entities/aggregator_epoch_settings.rs index 61ff980b062..014392f689c 100644 --- a/mithril-aggregator/src/entities/aggregator_epoch_settings.rs +++ b/mithril-aggregator/src/entities/aggregator_epoch_settings.rs @@ -9,20 +9,3 @@ pub struct AggregatorEpochSettings { /// Cardano transactions signing configuration pub cardano_transactions_signing_config: CardanoTransactionsSigningConfig, } - -impl AggregatorEpochSettings { - #[cfg(test)] - /// Create a dummy AggregatorEpochSettings - pub fn dummy() -> AggregatorEpochSettings { - use mithril_common::test_utils::fake_data; - - let protocol_parameters = fake_data::protocol_parameters(); - let cardano_transactions_signing_config = CardanoTransactionsSigningConfig::dummy(); - - // Aggregator Epoch settings - AggregatorEpochSettings { - protocol_parameters, - cardano_transactions_signing_config, - } - } -} diff --git a/mithril-aggregator/src/entities/leader_aggregator_epoch_settings.rs b/mithril-aggregator/src/entities/leader_aggregator_epoch_settings.rs index c620bf04397..cbd0a421c1a 100644 --- a/mithril-aggregator/src/entities/leader_aggregator_epoch_settings.rs +++ b/mithril-aggregator/src/entities/leader_aggregator_epoch_settings.rs @@ -23,37 +23,3 @@ pub struct LeaderAggregatorEpochSettings { /// Cardano transactions signing configuration for the next epoch pub next_cardano_transactions_signing_config: Option, } - -impl LeaderAggregatorEpochSettings { - #[cfg(test)] - /// Create a dummy LeaderAggregatorEpochSettings - pub fn dummy() -> LeaderAggregatorEpochSettings { - use mithril_common::test_utils::fake_data; - - // Beacon - let beacon = fake_data::beacon(); - - // Registration protocol parameters - let registration_protocol_parameters = fake_data::protocol_parameters(); - - // Signers - let signers = fake_data::signers(5); - let current_signers = signers[1..3].to_vec(); - let next_signers = signers[2..5].to_vec(); - - // Cardano transactions signing configuration - let cardano_transactions_signing_config = Some(CardanoTransactionsSigningConfig::dummy()); - let next_cardano_transactions_signing_config = - Some(CardanoTransactionsSigningConfig::dummy()); - - // Signer Epoch settings - LeaderAggregatorEpochSettings { - epoch: beacon.epoch, - registration_protocol_parameters, - current_signers, - next_signers, - cardano_transactions_signing_config, - next_cardano_transactions_signing_config, - } - } -} diff --git a/mithril-aggregator/src/entities/open_message.rs b/mithril-aggregator/src/entities/open_message.rs index 813ba0648b3..453755dd71f 100644 --- a/mithril-aggregator/src/entities/open_message.rs +++ b/mithril-aggregator/src/entities/open_message.rs @@ -46,30 +46,6 @@ impl OpenMessage { .map(|sig| sig.party_id.to_owned()) .collect() } - - #[cfg(test)] - /// Create a dumb OpenMessage instance mainly for test purposes - pub fn dummy() -> Self { - use mithril_common::test_utils::fake_data; - - let beacon = fake_data::beacon(); - let epoch = beacon.epoch; - let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon); - - Self { - epoch, - signed_entity_type, - protocol_message: ProtocolMessage::new(), - is_certified: false, - is_expired: false, - single_signatures: vec![ - fake_data::single_signature(vec![1, 4, 5]), - fake_data::single_signature(vec![2, 3, 8]), - ], - created_at: Utc::now(), - expires_at: None, - } - } } impl From for OpenMessage { @@ -109,7 +85,7 @@ mod test { use mithril_common::{ entities::{Epoch, ProtocolMessage, SignedEntityType}, - test_utils::fake_data, + test_utils::{double::Dummy, fake_data}, }; use crate::database::record::{OpenMessageRecord, OpenMessageWithSingleSignaturesRecord}; diff --git a/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_database.rs b/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_database.rs index 9a6f0bb59bf..60f782a476f 100644 --- a/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_database.rs +++ b/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_database.rs @@ -182,6 +182,7 @@ mod tests { CardanoDatabaseDigestListItemMessage, CardanoDatabaseSnapshotListItemMessage, CardanoDatabaseSnapshotMessage, }; + use mithril_common::test_utils::double::Dummy; use mithril_common::{MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER}; use mithril_persistence::sqlite::HydrationError; diff --git a/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs b/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs index a3300483e39..f4e2f34d4aa 100644 --- a/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs +++ b/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs @@ -170,6 +170,7 @@ pub mod tests { use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::{CardanoStakeDistributionListItemMessage, CardanoStakeDistributionMessage}, + test_utils::double::Dummy, }; use crate::{initialize_dependencies, services::MockMessageService}; diff --git a/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_transaction.rs b/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_transaction.rs index 30c789f79b8..a5c254d5679 100644 --- a/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_transaction.rs +++ b/mithril-aggregator/src/http_server/routes/artifact_routes/cardano_transaction.rs @@ -108,6 +108,7 @@ pub mod tests { use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::{CardanoTransactionSnapshotListItemMessage, CardanoTransactionSnapshotMessage}, + test_utils::double::Dummy, }; use mithril_persistence::sqlite::HydrationError; diff --git a/mithril-aggregator/src/http_server/routes/artifact_routes/mithril_stake_distribution.rs b/mithril-aggregator/src/http_server/routes/artifact_routes/mithril_stake_distribution.rs index f69e87f1083..7dfedbf533b 100644 --- a/mithril-aggregator/src/http_server/routes/artifact_routes/mithril_stake_distribution.rs +++ b/mithril-aggregator/src/http_server/routes/artifact_routes/mithril_stake_distribution.rs @@ -108,6 +108,7 @@ pub mod tests { use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::{MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage}, + test_utils::double::Dummy, }; use mithril_persistence::sqlite::HydrationError; diff --git a/mithril-aggregator/src/http_server/routes/artifact_routes/snapshot.rs b/mithril-aggregator/src/http_server/routes/artifact_routes/snapshot.rs index fa9a6041400..bb6c6c2f570 100644 --- a/mithril-aggregator/src/http_server/routes/artifact_routes/snapshot.rs +++ b/mithril-aggregator/src/http_server/routes/artifact_routes/snapshot.rs @@ -215,7 +215,7 @@ mod tests { MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, entities::{CardanoDbBeacon, SignedEntityType, Snapshot}, messages::{SnapshotListItemMessage, SnapshotMessage}, - test_utils::fake_data, + test_utils::{double::Dummy, fake_data}, }; use mithril_persistence::sqlite::HydrationError; diff --git a/mithril-aggregator/src/http_server/routes/epoch_routes.rs b/mithril-aggregator/src/http_server/routes/epoch_routes.rs index 0c52025a7d6..2cb525a90e7 100644 --- a/mithril-aggregator/src/http_server/routes/epoch_routes.rs +++ b/mithril-aggregator/src/http_server/routes/epoch_routes.rs @@ -67,6 +67,7 @@ mod tests { use mithril_api_spec::APISpec; use mithril_common::messages::EpochSettingsMessage; + use mithril_common::test_utils::double::Dummy; use crate::{initialize_dependencies, services::MockMessageService}; diff --git a/mithril-aggregator/src/http_server/routes/middlewares.rs b/mithril-aggregator/src/http_server/routes/middlewares.rs index 3caed01a0fa..5dde0112d0e 100644 --- a/mithril-aggregator/src/http_server/routes/middlewares.rs +++ b/mithril-aggregator/src/http_server/routes/middlewares.rs @@ -209,7 +209,6 @@ pub mod validators { #[cfg(test)] mod tests { - use super::*; use serde_json::Value; use std::convert::Infallible; use warp::{ @@ -219,9 +218,13 @@ mod tests { test::request, }; + use mithril_common::test_utils::double::Dummy; + use crate::http_server::routes::reply; use crate::initialize_dependencies; + use super::*; + async fn route_handler(value: Option) -> Result { Ok(reply::json(&value, StatusCode::OK)) } diff --git a/mithril-aggregator/src/http_server/routes/proof_routes.rs b/mithril-aggregator/src/http_server/routes/proof_routes.rs index 5b3180b2afb..293feb79a46 100644 --- a/mithril-aggregator/src/http_server/routes/proof_routes.rs +++ b/mithril-aggregator/src/http_server/routes/proof_routes.rs @@ -164,7 +164,7 @@ mod tests { MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, entities::{BlockNumber, CardanoTransactionsSetProof, CardanoTransactionsSnapshot}, signable_builder::SignedEntity, - test_utils::{assert_equivalent, fake_data}, + test_utils::{assert_equivalent, double::Dummy, fake_data}, }; use crate::services::MockProverService; @@ -196,7 +196,7 @@ mod tests { let signed_entity = SignedEntity:: { artifact: cardano_transactions_snapshot, - ..SignedEntity::::dummy() + ..Dummy::dummy() }; // Action diff --git a/mithril-aggregator/src/http_server/routes/root_routes.rs b/mithril-aggregator/src/http_server/routes/root_routes.rs index 8e91aa449f6..3dbf68f5da8 100644 --- a/mithril-aggregator/src/http_server/routes/root_routes.rs +++ b/mithril-aggregator/src/http_server/routes/root_routes.rs @@ -91,6 +91,7 @@ mod tests { use mithril_common::messages::{ AggregatorCapabilities, AggregatorFeaturesMessage, CardanoTransactionsProverCapabilities, }; + use mithril_common::test_utils::double::Dummy; use crate::http_server::routes::router::RouterConfig; use crate::initialize_dependencies; diff --git a/mithril-aggregator/src/http_server/routes/router.rs b/mithril-aggregator/src/http_server/routes/router.rs index f343160afdf..1eb45116364 100644 --- a/mithril-aggregator/src/http_server/routes/router.rs +++ b/mithril-aggregator/src/http_server/routes/router.rs @@ -8,6 +8,8 @@ use crate::tools::url_sanitizer::SanitizedUrlWithTrailingSlash; use mithril_common::api_version::APIVersionProvider; use mithril_common::entities::SignedEntityTypeDiscriminants; +#[cfg(test)] +use mithril_common::test_utils::double::Dummy; use mithril_common::{ CardanoNetwork, MITHRIL_API_VERSION_HEADER, MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, @@ -36,8 +38,8 @@ pub struct RouterConfig { } #[cfg(test)] -impl RouterConfig { - pub fn dummy() -> Self { +impl Dummy for RouterConfig { + fn dummy() -> Self { Self { network: CardanoNetwork::TestNet(87), server_url: SanitizedUrlWithTrailingSlash::parse("http://0.0.0.0:8000/").unwrap(), @@ -53,7 +55,10 @@ impl RouterConfig { origin_tag_white_list: HashSet::from(["DUMMY_TAG".to_string()]), } } +} +#[cfg(test)] +impl RouterConfig { pub fn dummy_with_origin_tag_white_list(origin_tag_white_list: &[&str]) -> Self { Self { origin_tag_white_list: origin_tag_white_list diff --git a/mithril-aggregator/src/http_server/routes/signatures_routes.rs b/mithril-aggregator/src/http_server/routes/signatures_routes.rs index 58ce1cf72c2..d4153aab547 100644 --- a/mithril-aggregator/src/http_server/routes/signatures_routes.rs +++ b/mithril-aggregator/src/http_server/routes/signatures_routes.rs @@ -126,7 +126,10 @@ mod tests { use warp::test::request; use mithril_api_spec::APISpec; - use mithril_common::{entities::SignedEntityType, messages::RegisterSignatureMessageHttp}; + use mithril_common::{ + entities::SignedEntityType, messages::RegisterSignatureMessageHttp, + test_utils::double::Dummy, + }; use crate::{ SingleSignatureAuthenticator, initialize_dependencies, diff --git a/mithril-aggregator/src/http_server/routes/signer_routes.rs b/mithril-aggregator/src/http_server/routes/signer_routes.rs index c9e11644a84..9bdea379c17 100644 --- a/mithril-aggregator/src/http_server/routes/signer_routes.rs +++ b/mithril-aggregator/src/http_server/routes/signer_routes.rs @@ -271,7 +271,7 @@ mod tests { crypto_helper::ProtocolRegistrationError, entities::Epoch, messages::RegisterSignerMessage, - test_utils::{MithrilFixtureBuilder, fake_data}, + test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, }; use crate::{ diff --git a/mithril-aggregator/src/http_server/routes/statistics_routes.rs b/mithril-aggregator/src/http_server/routes/statistics_routes.rs index a53430d195b..7a3d7ed3b2c 100644 --- a/mithril-aggregator/src/http_server/routes/statistics_routes.rs +++ b/mithril-aggregator/src/http_server/routes/statistics_routes.rs @@ -232,7 +232,9 @@ mod tests { use mithril_common::messages::{ CardanoDatabaseImmutableFilesRestoredMessage, SnapshotDownloadMessage, }; - use mithril_common::{MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, temp_dir}; + use mithril_common::{ + MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, temp_dir, test_utils::double::Dummy, + }; use crate::ServeCommandDependenciesContainer; use crate::event_store::EventMessage; diff --git a/mithril-aggregator/src/http_server/routes/status.rs b/mithril-aggregator/src/http_server/routes/status.rs index 4660db70add..9092c882067 100644 --- a/mithril-aggregator/src/http_server/routes/status.rs +++ b/mithril-aggregator/src/http_server/routes/status.rs @@ -115,7 +115,7 @@ mod tests { use mithril_api_spec::APISpec; use mithril_common::{ entities::{Epoch, ProtocolParameters, Stake}, - test_utils::{MithrilFixtureBuilder, fake_data}, + test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, }; use crate::{ diff --git a/mithril-aggregator/src/lib.rs b/mithril-aggregator/src/lib.rs index fe3de133ed7..e1d0fe37b65 100644 --- a/mithril-aggregator/src/lib.rs +++ b/mithril-aggregator/src/lib.rs @@ -27,6 +27,8 @@ mod multi_signer; mod runtime; pub mod services; mod store; +#[doc(hidden)] +pub mod test; mod tools; pub use crate::artifact_builder::ArtifactBuilder; diff --git a/mithril-aggregator/src/message_adapters/from_epoch_settings.rs b/mithril-aggregator/src/message_adapters/from_epoch_settings.rs index 59ad38126b2..f3fb7d2410b 100644 --- a/mithril-aggregator/src/message_adapters/from_epoch_settings.rs +++ b/mithril-aggregator/src/message_adapters/from_epoch_settings.rs @@ -32,6 +32,8 @@ impl TryFromMessageAdapter #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::*; #[test] diff --git a/mithril-aggregator/src/message_adapters/from_register_signature.rs b/mithril-aggregator/src/message_adapters/from_register_signature.rs index 1472ff683b0..6b232f4747b 100644 --- a/mithril-aggregator/src/message_adapters/from_register_signature.rs +++ b/mithril-aggregator/src/message_adapters/from_register_signature.rs @@ -28,6 +28,8 @@ impl TryFromMessageAdapter #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::*; #[test] diff --git a/mithril-aggregator/src/message_adapters/from_register_signer.rs b/mithril-aggregator/src/message_adapters/from_register_signer.rs index 5b436c439f3..5694d8dc868 100644 --- a/mithril-aggregator/src/message_adapters/from_register_signer.rs +++ b/mithril-aggregator/src/message_adapters/from_register_signer.rs @@ -39,6 +39,8 @@ impl TryFromMessageAdapter for FromRegisterSigner #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::*; #[test] diff --git a/mithril-aggregator/src/message_adapters/to_cardano_transactions_proof_message.rs b/mithril-aggregator/src/message_adapters/to_cardano_transactions_proof_message.rs index c18b90ae7da..518debb414a 100644 --- a/mithril-aggregator/src/message_adapters/to_cardano_transactions_proof_message.rs +++ b/mithril-aggregator/src/message_adapters/to_cardano_transactions_proof_message.rs @@ -60,6 +60,7 @@ fn try_adapt_set_proof_message( #[cfg(test)] mod tests { use mithril_common::crypto_helper::MKProof; + use mithril_common::test_utils::double::Dummy; use super::*; diff --git a/mithril-aggregator/src/multi_signer.rs b/mithril-aggregator/src/multi_signer.rs index cf1e0a0b512..a65ec518918 100644 --- a/mithril-aggregator/src/multi_signer.rs +++ b/mithril-aggregator/src/multi_signer.rs @@ -146,7 +146,7 @@ mod tests { use mithril_common::crypto_helper::tests_setup::*; use mithril_common::entities::{CardanoDbBeacon, Epoch, SignedEntityType, SignerWithStake}; use mithril_common::protocol::ToMessage; - use mithril_common::test_utils::{MithrilFixtureBuilder, fake_data}; + use mithril_common::test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}; use crate::entities::AggregatorEpochSettings; use crate::services::{FakeEpochService, FakeEpochServiceBuilder}; diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index affffc98395..79700d2c806 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -549,7 +549,7 @@ pub mod tests { }, signable_builder::SignableBuilderService, temp_dir, - test_utils::{MithrilFixtureBuilder, fake_data}, + test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, }; use mithril_persistence::store::StakeStorer; use mithril_signed_entity_lock::SignedEntityTypeLock; diff --git a/mithril-aggregator/src/runtime/state_machine.rs b/mithril-aggregator/src/runtime/state_machine.rs index 3b5453011d4..c290ee8d48c 100644 --- a/mithril-aggregator/src/runtime/state_machine.rs +++ b/mithril-aggregator/src/runtime/state_machine.rs @@ -383,13 +383,13 @@ impl AggregatorRuntime { #[cfg(test)] mod tests { - use crate::entities::OpenMessage; use anyhow::anyhow; use mockall::predicate; use std::time::Duration; - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; + use crate::entities::OpenMessage; use crate::test_tools::TestLogger; use super::super::runner::MockAggregatorRunner; diff --git a/mithril-aggregator/src/services/aggregator_client.rs b/mithril-aggregator/src/services/aggregator_client.rs index a81f42928cf..4b09c7c517f 100644 --- a/mithril-aggregator/src/services/aggregator_client.rs +++ b/mithril-aggregator/src/services/aggregator_client.rs @@ -383,6 +383,8 @@ impl RemoteCertificateRetriever for AggregatorHTTPClient { pub(crate) mod dumb { use tokio::sync::RwLock; + use mithril_common::test_utils::double::Dummy; + use super::*; /// This aggregator client is intended to be used by test services. @@ -421,6 +423,7 @@ mod tests { use mithril_common::api_version::DummyApiVersionDiscriminantSource; use mithril_common::messages::CertificateListItemMessage; + use mithril_common::test_utils::double::Dummy; use crate::test_tools::TestLogger; diff --git a/mithril-aggregator/src/services/certificate_chain_synchronizer/synchronizer_service.rs b/mithril-aggregator/src/services/certificate_chain_synchronizer/synchronizer_service.rs index 7342e9c3f6b..0eb8261f304 100644 --- a/mithril-aggregator/src/services/certificate_chain_synchronizer/synchronizer_service.rs +++ b/mithril-aggregator/src/services/certificate_chain_synchronizer/synchronizer_service.rs @@ -235,8 +235,8 @@ mod tests { use crate::services::{ MockOpenMessageStorer, MockRemoteCertificateRetriever, MockSynchronizedCertificateStorer, }; + use crate::test::mocks::MockCertificateVerifier; use crate::test_tools::TestLogger; - use crate::tools::mocks::MockCertificateVerifier; use super::*; diff --git a/mithril-aggregator/src/services/certifier/buffered_certifier.rs b/mithril-aggregator/src/services/certifier/buffered_certifier.rs index 9c9581b89b9..7d7f34a736b 100644 --- a/mithril-aggregator/src/services/certifier/buffered_certifier.rs +++ b/mithril-aggregator/src/services/certifier/buffered_certifier.rs @@ -191,7 +191,7 @@ mod tests { CardanoTransactions, MithrilStakeDistribution, }; use mithril_common::entities::SingleSignatureAuthenticationStatus; - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use crate::database::repository::BufferedSingleSignatureRepository; use crate::database::test_helper::main_db_connection; diff --git a/mithril-aggregator/src/services/epoch_service.rs b/mithril-aggregator/src/services/epoch_service.rs index 42c2f336980..be9174a3cde 100644 --- a/mithril-aggregator/src/services/epoch_service.rs +++ b/mithril-aggregator/src/services/epoch_service.rs @@ -560,7 +560,7 @@ pub(crate) struct FakeEpochServiceBuilder { #[cfg(test)] impl FakeEpochServiceBuilder { pub fn dummy(epoch: Epoch) -> Self { - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; let signers = fake_data::signers_with_stakes(3); Self { @@ -640,6 +640,7 @@ impl FakeEpochService { fixture: &mithril_common::test_utils::MithrilFixture, ) -> Self { use mithril_common::entities::CardanoTransactionsSigningConfig; + use mithril_common::test_utils::double::Dummy; let current_epoch_settings = AggregatorEpochSettings { protocol_parameters: fixture.protocol_parameters(), @@ -840,13 +841,14 @@ mod tests { BlockNumber, CardanoTransactionsSigningConfig, Stake, StakeDistribution, SupportedEra, }; use mithril_common::test_utils::{ - MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod, fake_data, + MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod, double::Dummy, + fake_data, }; use mockall::predicate::eq; use crate::store::{FakeEpochSettingsStorer, MockVerificationKeyStorer}; + use crate::test::mocks::MockStakeStore; use crate::test_tools::TestLogger; - use crate::tools::mocks::MockStakeStore; use super::*; diff --git a/mithril-aggregator/src/services/message.rs b/mithril-aggregator/src/services/message.rs index 6db467de300..b7b3639dace 100644 --- a/mithril-aggregator/src/services/message.rs +++ b/mithril-aggregator/src/services/message.rs @@ -342,7 +342,7 @@ impl MessageService for MithrilMessageService { #[cfg(test)] mod tests { use mithril_common::entities::{BlockNumber, Certificate, SignedEntityType}; - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use tokio::sync::RwLock; use crate::database::record::SignedEntityRecord; diff --git a/mithril-aggregator/src/services/signable_builder/signable_seed_builder.rs b/mithril-aggregator/src/services/signable_builder/signable_seed_builder.rs index 3c6b75ae2ce..92f332ce6bd 100644 --- a/mithril-aggregator/src/services/signable_builder/signable_seed_builder.rs +++ b/mithril-aggregator/src/services/signable_builder/signable_seed_builder.rs @@ -58,7 +58,7 @@ impl SignableSeedBuilder for AggregatorSignableSeedBuilder { mod tests { use mithril_common::{ entities::Epoch, - test_utils::{MithrilFixture, MithrilFixtureBuilder}, + test_utils::{MithrilFixture, MithrilFixtureBuilder, double::Dummy}, }; use crate::{entities::AggregatorEpochSettings, services::FakeEpochServiceBuilder}; diff --git a/mithril-aggregator/src/services/signature_consumer/dmq.rs b/mithril-aggregator/src/services/signature_consumer/dmq.rs index badf6bc9770..ffc401d0dc7 100644 --- a/mithril-aggregator/src/services/signature_consumer/dmq.rs +++ b/mithril-aggregator/src/services/signature_consumer/dmq.rs @@ -55,7 +55,10 @@ impl SignatureConsumer for SignatureConsumerDmq { #[cfg(test)] mod tests { - use mithril_common::{crypto_helper::ProtocolSingleSignature, test_utils::fake_keys}; + use mithril_common::{ + crypto_helper::ProtocolSingleSignature, + test_utils::{double::Dummy, fake_keys}, + }; use mithril_dmq::test::double::DmqConsumerFake; use super::*; diff --git a/mithril-aggregator/src/services/signer_registration/follower.rs b/mithril-aggregator/src/services/signer_registration/follower.rs index 78f4a0b6ce5..6b5d2b2816d 100644 --- a/mithril-aggregator/src/services/signer_registration/follower.rs +++ b/mithril-aggregator/src/services/signer_registration/follower.rs @@ -180,7 +180,7 @@ mod tests { use mithril_common::messages::{ EpochSettingsMessage, SignerMessagePart, TryFromMessageAdapter, }; - use mithril_common::test_utils::MithrilFixtureBuilder; + use mithril_common::test_utils::{MithrilFixtureBuilder, double::Dummy}; use crate::{ database::{repository::SignerRegistrationStore, test_helper::main_db_connection}, @@ -189,7 +189,7 @@ mod tests { FakeEpochService, MockLeaderAggregatorClient, MockSignerRecorder, MockSignerRegistrationVerifier, }, - tools::mocks::MockStakeStore, + test::mocks::MockStakeStore, }; use super::*; diff --git a/mithril-aggregator/src/services/signer_registration/verifier.rs b/mithril-aggregator/src/services/signer_registration/verifier.rs index f5d134763e8..e2d8cffc042 100644 --- a/mithril-aggregator/src/services/signer_registration/verifier.rs +++ b/mithril-aggregator/src/services/signer_registration/verifier.rs @@ -80,7 +80,10 @@ impl SignerRegistrationVerifier for MithrilSignerRegistrationVerifier { #[cfg(test)] mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; - use mithril_common::{entities::TimePoint, test_utils::MithrilFixtureBuilder}; + use mithril_common::{ + entities::TimePoint, + test_utils::{MithrilFixtureBuilder, double::Dummy}, + }; use super::*; diff --git a/mithril-aggregator/src/services/stake_distribution.rs b/mithril-aggregator/src/services/stake_distribution.rs index 1589cc8a048..e5a3b41af4e 100644 --- a/mithril-aggregator/src/services/stake_distribution.rs +++ b/mithril-aggregator/src/services/stake_distribution.rs @@ -227,7 +227,7 @@ mod tests { use mithril_common::temp_dir; use crate::dependency_injection::DependenciesBuilder; - use crate::tools::mocks::MockChainObserver; + use crate::test::mocks::MockChainObserver; use super::*; diff --git a/mithril-aggregator/src/store/epoch_settings_storer.rs b/mithril-aggregator/src/store/epoch_settings_storer.rs index a28d73b4d14..f322c86ca42 100644 --- a/mithril-aggregator/src/store/epoch_settings_storer.rs +++ b/mithril-aggregator/src/store/epoch_settings_storer.rs @@ -110,8 +110,8 @@ impl EpochPruningTask for FakeEpochSettingsStorer { #[cfg(test)] mod tests { - use mithril_common::entities::CardanoTransactionsSigningConfig; + use mithril_common::test_utils::double::Dummy; use super::*; diff --git a/mithril-aggregator/src/test/double/dummies.rs b/mithril-aggregator/src/test/double/dummies.rs new file mode 100644 index 00000000000..5bb10cddff8 --- /dev/null +++ b/mithril-aggregator/src/test/double/dummies.rs @@ -0,0 +1,120 @@ +use chrono::Utc; +use uuid::Uuid; + +use mithril_common::test_utils::{double::Dummy, fake_data}; + +mod record { + use mithril_common::entities::{ProtocolMessage, SignedEntityType}; + + use crate::database::record::{ImmutableFileDigestRecord, OpenMessageRecord}; + + use super::*; + + impl Dummy for ImmutableFileDigestRecord { + /// Create a dumb ImmutableFileDigestRecord instance mainly for test purposes + fn dummy() -> Self { + Self { + immutable_file_name: "123.chunk".to_string(), + digest: "dummy_digest".to_string(), + } + } + } + + impl Dummy for OpenMessageRecord { + /// Create a dumb OpenMessage instance mainly for test purposes + fn dummy() -> Self { + let beacon = fake_data::beacon(); + let epoch = beacon.epoch; + let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon); + + Self { + open_message_id: Uuid::parse_str("193d1442-e89b-43cf-9519-04d8db9a12ff").unwrap(), + epoch, + signed_entity_type, + protocol_message: ProtocolMessage::new(), + is_certified: false, + is_expired: false, + created_at: Utc::now(), + expires_at: None, + } + } + } +} + +mod entities { + use mithril_common::entities::{ + CardanoTransactionsSigningConfig, ProtocolMessage, SignedEntityType, + }; + + use crate::entities::{AggregatorEpochSettings, LeaderAggregatorEpochSettings, OpenMessage}; + + use super::*; + + impl Dummy for AggregatorEpochSettings { + /// Create a dummy `AggregatorEpochSettings` + fn dummy() -> Self { + let protocol_parameters = fake_data::protocol_parameters(); + let cardano_transactions_signing_config = CardanoTransactionsSigningConfig::dummy(); + + // Aggregator Epoch settings + AggregatorEpochSettings { + protocol_parameters, + cardano_transactions_signing_config, + } + } + } + + impl Dummy for LeaderAggregatorEpochSettings { + /// Create a dummy `LeaderAggregatorEpochSettings` + fn dummy() -> Self { + // Beacon + let beacon = fake_data::beacon(); + + // Registration protocol parameters + let registration_protocol_parameters = fake_data::protocol_parameters(); + + // Signers + let signers = fake_data::signers(5); + let current_signers = signers[1..3].to_vec(); + let next_signers = signers[2..5].to_vec(); + + // Cardano transactions signing configuration + let cardano_transactions_signing_config = + Some(CardanoTransactionsSigningConfig::dummy()); + let next_cardano_transactions_signing_config = + Some(CardanoTransactionsSigningConfig::dummy()); + + // Signer Epoch settings + LeaderAggregatorEpochSettings { + epoch: beacon.epoch, + registration_protocol_parameters, + current_signers, + next_signers, + cardano_transactions_signing_config, + next_cardano_transactions_signing_config, + } + } + } + + impl Dummy for OpenMessage { + fn dummy() -> Self { + let beacon = fake_data::beacon(); + let epoch = beacon.epoch; + let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon); + + Self { + epoch, + signed_entity_type, + protocol_message: ProtocolMessage::new(), + is_certified: false, + is_expired: false, + single_signatures: vec![ + fake_data::single_signature(vec![1, 4, 5]), + fake_data::single_signature(vec![2, 3, 8]), + ], + created_at: Utc::now(), + expires_at: None, + } + } + } +} diff --git a/mithril-aggregator/src/test/double/mod.rs b/mithril-aggregator/src/test/double/mod.rs new file mode 100644 index 00000000000..7ee7ff27e5a --- /dev/null +++ b/mithril-aggregator/src/test/double/mod.rs @@ -0,0 +1 @@ +mod dummies; diff --git a/mithril-aggregator/src/tools/mocks.rs b/mithril-aggregator/src/test/mocks.rs similarity index 100% rename from mithril-aggregator/src/tools/mocks.rs rename to mithril-aggregator/src/test/mocks.rs diff --git a/mithril-aggregator/src/test/mod.rs b/mithril-aggregator/src/test/mod.rs new file mode 100644 index 00000000000..3c35bb708a2 --- /dev/null +++ b/mithril-aggregator/src/test/mod.rs @@ -0,0 +1,3 @@ +mod double; +#[cfg(test)] +pub mod mocks; diff --git a/mithril-aggregator/src/tools/certificates_hash_migrator.rs b/mithril-aggregator/src/tools/certificates_hash_migrator.rs index 4d1505e4d40..da4fa368e85 100644 --- a/mithril-aggregator/src/tools/certificates_hash_migrator.rs +++ b/mithril-aggregator/src/tools/certificates_hash_migrator.rs @@ -216,6 +216,7 @@ mod test { Epoch, ImmutableFileNumber, SignedEntityConfig, SignedEntityType, SignedEntityTypeDiscriminants as Type, TimePoint, }; + use mithril_common::test_utils::double::Dummy; use mithril_persistence::sqlite::{ConnectionBuilder, ConnectionOptions, SqliteConnection}; use crate::database::record::{CertificateRecord, SignedEntityRecord}; diff --git a/mithril-aggregator/src/tools/file_archiver/entities.rs b/mithril-aggregator/src/tools/file_archiver/entities.rs index 757816bdd5f..35a03f9bc06 100644 --- a/mithril-aggregator/src/tools/file_archiver/entities.rs +++ b/mithril-aggregator/src/tools/file_archiver/entities.rs @@ -50,16 +50,6 @@ impl FileArchive { } } - #[cfg(test)] - pub fn dummy() -> Self { - Self { - filepath: PathBuf::from("archive.tar.gz"), - archive_filesize: 10, - uncompressed_size: 789, - compression_algorithm: CompressionAlgorithm::Gzip, - } - } - /// Get the path of the archive. pub fn get_file_path(&self) -> &Path { &self.filepath @@ -104,6 +94,18 @@ impl FileArchive { } } +#[cfg(test)] +impl mithril_common::test_utils::double::Dummy for FileArchive { + fn dummy() -> Self { + Self { + filepath: PathBuf::from("archive.tar.gz"), + archive_filesize: 10, + uncompressed_size: 789, + compression_algorithm: CompressionAlgorithm::Gzip, + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/mithril-aggregator/src/tools/mod.rs b/mithril-aggregator/src/tools/mod.rs index d8211a0f240..93163b0fd46 100644 --- a/mithril-aggregator/src/tools/mod.rs +++ b/mithril-aggregator/src/tools/mod.rs @@ -4,8 +4,6 @@ mod era; pub mod file_archiver; pub mod file_size; mod genesis; -#[cfg(test)] -pub mod mocks; mod signer_importer; mod single_signature_authenticator; pub mod url_sanitizer; diff --git a/mithril-aggregator/tests/era_checker.rs b/mithril-aggregator/tests/era_checker.rs index 4190b4f6b25..091e6ee7e36 100644 --- a/mithril-aggregator/tests/era_checker.rs +++ b/mithril-aggregator/tests/era_checker.rs @@ -5,7 +5,7 @@ use mithril_common::{ BlockNumber, ChainPoint, Epoch, ProtocolParameters, SlotNumber, SupportedEra, TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test_utils::{MithrilFixtureBuilder, double::Dummy}, }; use mithril_era::EraMarker; diff --git a/mithril-aggregator/tests/test_extensions/runtime_tester.rs b/mithril-aggregator/tests/test_extensions/runtime_tester.rs index 5cae914f313..6c974186e59 100644 --- a/mithril-aggregator/tests/test_extensions/runtime_tester.rs +++ b/mithril-aggregator/tests/test_extensions/runtime_tester.rs @@ -31,6 +31,7 @@ use mithril_common::{ }, test_utils::{ MithrilFixture, MithrilFixtureBuilder, SignerFixture, StakeDistributionGenerationMethod, + double::Dummy, }, }; use mithril_era::{EraMarker, EraReader, adapters::EraReaderDummyAdapter}; diff --git a/mithril-client-cli/Cargo.toml b/mithril-client-cli/Cargo.toml index 06538795ad7..efee7ba1041 100644 --- a/mithril-client-cli/Cargo.toml +++ b/mithril-client-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client-cli" -version = "0.12.22" +version = "0.12.23" description = "A Mithril Client" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-client-cli/src/commands/cardano_db/download/v1.rs b/mithril-client-cli/src/commands/cardano_db/download/v1.rs index d37b7803180..62c82b0c9c9 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v1.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v1.rs @@ -236,7 +236,7 @@ mod tests { MithrilCertificateMetadata, common::{CardanoDbBeacon, ProtocolMessagePartKey, SignedEntityType}, }; - use mithril_common::test_utils::TempDir; + use mithril_common::test_utils::{TempDir, double::Dummy}; use super::*; diff --git a/mithril-client-cli/src/commands/cardano_db/download/v2.rs b/mithril-client-cli/src/commands/cardano_db/download/v2.rs index b054424947e..9ea00495701 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v2.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v2.rs @@ -283,6 +283,7 @@ impl PreparedCardanoDbV2Download { #[cfg(test)] mod tests { use mithril_client::common::{AncillaryMessagePart, DigestsMessagePart, ImmutablesMessagePart}; + use mithril_common::test_utils::double::Dummy; use super::*; diff --git a/mithril-client-cli/src/commands/cardano_db/shared_steps.rs b/mithril-client-cli/src/commands/cardano_db/shared_steps.rs index 554df3f8aa7..85fb03a9f43 100644 --- a/mithril-client-cli/src/commands/cardano_db/shared_steps.rs +++ b/mithril-client-cli/src/commands/cardano_db/shared_steps.rs @@ -221,7 +221,7 @@ mod tests { MithrilCertificateMetadata, common::{CardanoDbBeacon, ProtocolMessagePartKey, SignedEntityType}, }; - use mithril_common::test_utils::TempDir; + use mithril_common::test_utils::{TempDir, double::Dummy}; use crate::utils::ProgressOutputType; diff --git a/mithril-client/Cargo.toml b/mithril-client/Cargo.toml index fc9cb6b6f0c..aff5e602ffe 100644 --- a/mithril-client/Cargo.toml +++ b/mithril-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client" -version = "0.12.22" +version = "0.12.23" description = "Mithril client library" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-client/src/cardano_database_client/api.rs b/mithril-client/src/cardano_database_client/api.rs index beec035e4db..a5bd0cbf5b5 100644 --- a/mithril-client/src/cardano_database_client/api.rs +++ b/mithril-client/src/cardano_database_client/api.rs @@ -249,6 +249,7 @@ pub(crate) mod test_dependency_injector { } mod tests { + use mithril_common::test_utils::double::Dummy; use mockall::predicate; use crate::aggregator_client::AggregatorRequest; diff --git a/mithril-client/src/cardano_database_client/download_unpack/internal_downloader.rs b/mithril-client/src/cardano_database_client/download_unpack/internal_downloader.rs index 4a1f1a72d66..6b0e3988d12 100644 --- a/mithril-client/src/cardano_database_client/download_unpack/internal_downloader.rs +++ b/mithril-client/src/cardano_database_client/download_unpack/internal_downloader.rs @@ -275,7 +275,7 @@ mod tests { use mithril_common::{ entities::{CardanoDbBeacon, Epoch, MultiFilesUri, TemplateUri}, messages::CardanoDatabaseSnapshotMessage as CardanoDatabaseSnapshot, - test_utils::temp_dir_create, + test_utils::{double::Dummy, temp_dir_create}, }; use crate::cardano_database_client::CardanoDatabaseClientDependencyInjector; diff --git a/mithril-client/src/cardano_database_client/fetch.rs b/mithril-client/src/cardano_database_client/fetch.rs index 63009829c97..e667340ae9f 100644 --- a/mithril-client/src/cardano_database_client/fetch.rs +++ b/mithril-client/src/cardano_database_client/fetch.rs @@ -66,6 +66,7 @@ mod tests { use mockall::predicate::eq; use mithril_common::entities::{CardanoDbBeacon, Epoch}; + use mithril_common::test_utils::double::Dummy; use crate::cardano_database_client::CardanoDatabaseClientDependencyInjector; diff --git a/mithril-client/src/cardano_database_client/proving.rs b/mithril-client/src/cardano_database_client/proving.rs index c6aac350a2a..711811c9cf0 100644 --- a/mithril-client/src/cardano_database_client/proving.rs +++ b/mithril-client/src/cardano_database_client/proving.rs @@ -180,7 +180,7 @@ mod tests { use mithril_common::{ entities::{CardanoDbBeacon, Epoch, HexEncodedDigest}, messages::CardanoDatabaseDigestListItemMessage, - test_utils::TempDir, + test_utils::{TempDir, double::Dummy}, }; use crate::{ diff --git a/mithril-client/src/cardano_transaction_client.rs b/mithril-client/src/cardano_transaction_client.rs index 8b8cd0c5381..c488ba55c0f 100644 --- a/mithril-client/src/cardano_transaction_client.rs +++ b/mithril-client/src/cardano_transaction_client.rs @@ -164,6 +164,8 @@ mod tests { use chrono::{DateTime, Utc}; use mockall::predicate::eq; + use mithril_common::test_utils::double::Dummy; + use crate::aggregator_client::{AggregatorClientError, MockAggregatorClient}; use crate::common::{BlockNumber, Epoch}; use crate::{ diff --git a/mithril-client/src/certificate_client/fetch.rs b/mithril-client/src/certificate_client/fetch.rs index 132b6d0b28e..f4296bb74e9 100644 --- a/mithril-client/src/certificate_client/fetch.rs +++ b/mithril-client/src/certificate_client/fetch.rs @@ -105,7 +105,7 @@ impl CertificateRetriever for InternalCertificateRetriever { #[cfg(test)] mod tests { - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use crate::certificate_client::tests_utils::CertificateClientTestBuilder; diff --git a/mithril-client/src/snapshot_client.rs b/mithril-client/src/snapshot_client.rs index 58a7489cec0..09e189a24d1 100644 --- a/mithril-client/src/snapshot_client.rs +++ b/mithril-client/src/snapshot_client.rs @@ -481,9 +481,8 @@ mod tests { }; use mithril_cardano_node_internal_database::IMMUTABLE_DIR; - use mithril_common::{ - assert_dir_eq, crypto_helper::ManifestSigner, temp_dir_create, test_utils::fake_keys, - }; + use mithril_common::test_utils::{double::Dummy, fake_keys}; + use mithril_common::{assert_dir_eq, crypto_helper::ManifestSigner, temp_dir_create}; use super::*; diff --git a/mithril-client/tests/extensions/fake_aggregator/cardano_db_v1.rs b/mithril-client/tests/extensions/fake_aggregator/cardano_db_v1.rs index 1c4fe08c900..d162821ab84 100644 --- a/mithril-client/tests/extensions/fake_aggregator/cardano_db_v1.rs +++ b/mithril-client/tests/extensions/fake_aggregator/cardano_db_v1.rs @@ -7,7 +7,7 @@ use mithril_cardano_node_internal_database::test::DummyCardanoDb; use mithril_client::{MessageBuilder, MithrilCertificate, Snapshot, SnapshotListItem}; use mithril_common::crypto_helper::ManifestVerifierSecretKey; use mithril_common::entities::{CardanoDbBeacon, CompressionAlgorithm, SignedEntityType}; -use mithril_common::test_utils::fake_data; +use mithril_common::test_utils::{double::Dummy, fake_data}; use crate::extensions::{routes, snapshot_archives}; diff --git a/mithril-client/tests/extensions/fake_aggregator/cardano_db_v2.rs b/mithril-client/tests/extensions/fake_aggregator/cardano_db_v2.rs index 4c2a8885b22..641528179ae 100644 --- a/mithril-client/tests/extensions/fake_aggregator/cardano_db_v2.rs +++ b/mithril-client/tests/extensions/fake_aggregator/cardano_db_v2.rs @@ -17,7 +17,7 @@ use mithril_client::{ CardanoDatabaseSnapshot, CardanoDatabaseSnapshotListItem, MithrilCertificate, }; use mithril_common::crypto_helper::ManifestVerifierSecretKey; -use mithril_common::test_utils::fake_data; +use mithril_common::test_utils::{double::Dummy, fake_data}; use crate::extensions::{routes, snapshot_archives}; diff --git a/mithril-client/tests/extensions/fake_aggregator/cardano_transaction.rs b/mithril-client/tests/extensions/fake_aggregator/cardano_transaction.rs index 16c6e7f6362..d55c4fd5073 100644 --- a/mithril-client/tests/extensions/fake_aggregator/cardano_transaction.rs +++ b/mithril-client/tests/extensions/fake_aggregator/cardano_transaction.rs @@ -1,6 +1,7 @@ use mithril_client::common::{BlockNumber, ProtocolMessagePartKey}; use mithril_client::{CardanoTransactionsProofs, CardanoTransactionsSetProof, MithrilCertificate}; use mithril_common::crypto_helper::{MKProof, ProtocolMkProof}; +use mithril_common::test_utils::double::Dummy; use crate::extensions::routes; diff --git a/mithril-client/tests/extensions/fake_aggregator/certificate.rs b/mithril-client/tests/extensions/fake_aggregator/certificate.rs index 4ab94b4a231..3794e5a8df9 100644 --- a/mithril-client/tests/extensions/fake_aggregator/certificate.rs +++ b/mithril-client/tests/extensions/fake_aggregator/certificate.rs @@ -1,4 +1,5 @@ use mithril_client::{MithrilCertificate, MithrilCertificateListItem}; +use mithril_common::test_utils::double::Dummy; use crate::extensions::routes; diff --git a/mithril-client/tests/extensions/fake_aggregator/mithril_stake_distribution.rs b/mithril-client/tests/extensions/fake_aggregator/mithril_stake_distribution.rs index 2ca6f1c1e6e..3a28e2750a5 100644 --- a/mithril-client/tests/extensions/fake_aggregator/mithril_stake_distribution.rs +++ b/mithril-client/tests/extensions/fake_aggregator/mithril_stake_distribution.rs @@ -1,6 +1,7 @@ use mithril_client::{ MessageBuilder, MithrilCertificate, MithrilStakeDistribution, MithrilStakeDistributionListItem, }; +use mithril_common::test_utils::double::Dummy; use crate::extensions::routes; diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 237dafa69d4..1409e5f2489 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.6.9" +version = "0.6.10" description = "Common types, interfaces, and utilities for Mithril nodes." authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-common/src/entities/cardano_chain_point.rs b/mithril-common/src/entities/cardano_chain_point.rs index b1409dd06c8..332a3963748 100644 --- a/mithril-common/src/entities/cardano_chain_point.rs +++ b/mithril-common/src/entities/cardano_chain_point.rs @@ -34,17 +34,6 @@ impl ChainPoint { block_hash: block_hash.into(), } } - - cfg_test_tools! { - /// Create a dummy ChainPoint - pub fn dummy() -> Self { - Self { - slot_number: SlotNumber(100), - block_number: BlockNumber(0), - block_hash: "block_hash-50".to_string(), - } - } - } } impl Display for ChainPoint { diff --git a/mithril-common/src/entities/cardano_transactions_set_proof.rs b/mithril-common/src/entities/cardano_transactions_set_proof.rs index fc814fccf8e..4ec4a1bbc07 100644 --- a/mithril-common/src/entities/cardano_transactions_set_proof.rs +++ b/mithril-common/src/entities/cardano_transactions_set_proof.rs @@ -53,20 +53,6 @@ impl CardanoTransactionsSetProof { } cfg_test_tools! { - /// Retrieve a dummy proof (for test only) - pub fn dummy() -> Self { - let leaves = vec![ - (BlockNumber(0), "tx-1".to_string()), - (BlockNumber(1), "tx-2".to_string()), - (BlockNumber(1), "tx-3".to_string()), - (BlockNumber(10), "tx-4".to_string()), - (BlockNumber(20), "tx-5".to_string()), - (BlockNumber(22), "tx-6".to_string()), - ]; - - Self::from_leaves::(&leaves).unwrap() - } - /// Helper to create a proof from a list of leaves pub fn from_leaves(leaves: &[(BlockNumber, TransactionHash)]) -> StdResult { let transactions_hashes: Vec = diff --git a/mithril-common/src/entities/signed_entity_config.rs b/mithril-common/src/entities/signed_entity_config.rs index 6e522c2baa2..641a1c66f78 100644 --- a/mithril-common/src/entities/signed_entity_config.rs +++ b/mithril-common/src/entities/signed_entity_config.rs @@ -19,16 +19,6 @@ pub struct SignedEntityConfig { } impl SignedEntityConfig { - cfg_test_tools! { - /// Create a dummy SignedEntityConfig - pub fn dummy() -> Self { - Self { - allowed_discriminants: SignedEntityTypeDiscriminants::all(), - cardano_transactions_signing_config: CardanoTransactionsSigningConfig::dummy(), - } - } - } - /// Default allowed discriminants /// /// Appended to the allowed discriminants in the configuration. @@ -131,13 +121,6 @@ impl CardanoTransactionsSigningConfig { } } - /// Create a dummy config - pub fn dummy() -> Self { - Self { - security_parameter: BlockNumber(0), - step: BlockNumber(15), - } - } } /// Compute the block number to be signed based on the chain tip block number. @@ -174,7 +157,7 @@ mod tests { use crate::entities::{ CardanoDbBeacon, ChainPoint, Epoch, SignedEntityType, SlotNumber, TimePoint, }; - use crate::test_utils::fake_data; + use crate::test_utils::{double::Dummy, fake_data}; use super::*; diff --git a/mithril-common/src/entities/signed_entity_type.rs b/mithril-common/src/entities/signed_entity_type.rs index 6c15eb4e80b..5f3c0ed82eb 100644 --- a/mithril-common/src/entities/signed_entity_type.rs +++ b/mithril-common/src/entities/signed_entity_type.rs @@ -67,11 +67,6 @@ pub enum SignedEntityType { } impl SignedEntityType { - /// Retrieve a dummy entity type (for test only) - pub fn dummy() -> Self { - Self::MithrilStakeDistribution(Epoch(5)) - } - /// Create a new signed entity type for a genesis certificate (a [Self::MithrilStakeDistribution]) pub fn genesis(epoch: Epoch) -> Self { Self::MithrilStakeDistribution(epoch) diff --git a/mithril-common/src/entities/supported_era.rs b/mithril-common/src/entities/supported_era.rs index dcd87d2a614..60a42ac024a 100644 --- a/mithril-common/src/entities/supported_era.rs +++ b/mithril-common/src/entities/supported_era.rs @@ -17,18 +17,16 @@ impl SupportedEra { pub fn eras() -> Vec { Self::iter().collect() } - - /// Retrieve a dummy era (for test only) - pub fn dummy() -> Self { - Self::eras().first().unwrap().to_owned() - } } #[cfg(test)] mod tests { - use super::*; use std::str::FromStr; + use crate::test_utils::double::Dummy; + + use super::*; + #[test] fn correct_number_of_eras() { let total_eras = SupportedEra::eras().len(); diff --git a/mithril-common/src/entities/time_point.rs b/mithril-common/src/entities/time_point.rs index 74fcf1db11d..494b5053a99 100644 --- a/mithril-common/src/entities/time_point.rs +++ b/mithril-common/src/entities/time_point.rs @@ -30,13 +30,6 @@ impl TimePoint { chain_point, } } - - cfg_test_tools! { - /// Create a dummy TimePoint - pub fn dummy() -> Self { - Self::new(10, 100, ChainPoint::dummy()) - } - } } impl PartialOrd for TimePoint { diff --git a/mithril-common/src/messages/aggregator_features.rs b/mithril-common/src/messages/aggregator_features.rs index 630b4b3b83b..3bcd8474755 100644 --- a/mithril-common/src/messages/aggregator_features.rs +++ b/mithril-common/src/messages/aggregator_features.rs @@ -17,22 +17,6 @@ pub struct AggregatorFeaturesMessage { pub capabilities: AggregatorCapabilities, } -impl AggregatorFeaturesMessage { - /// Create a dummy AggregatorFeaturesMessage - pub fn dummy() -> Self { - AggregatorFeaturesMessage { - open_api_version: "0.0.1".to_string(), - documentation_url: "https://example.com".to_string(), - capabilities: AggregatorCapabilities { - signed_entity_types: BTreeSet::from([ - SignedEntityTypeDiscriminants::MithrilStakeDistribution, - ]), - cardano_transactions_prover: None, - }, - } - } -} - /// Capabilities of an Aggregator #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct AggregatorCapabilities { diff --git a/mithril-common/src/messages/cardano_database.rs b/mithril-common/src/messages/cardano_database.rs index 3cb3c03b019..36472326d3d 100644 --- a/mithril-common/src/messages/cardano_database.rs +++ b/mithril-common/src/messages/cardano_database.rs @@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize}; use crate::StdResult; use crate::entities::{ - AncillaryLocation, AncillaryLocations, CardanoDbBeacon, CompressionAlgorithm, DigestLocation, - DigestsLocations, Epoch, ImmutablesLocation, ImmutablesLocations, MultiFilesUri, TemplateUri, + AncillaryLocation, AncillaryLocations, CardanoDbBeacon, DigestLocation, DigestsLocations, + ImmutablesLocation, ImmutablesLocations, }; /// The message part that represents the locations of the Cardano database digests. @@ -156,61 +156,10 @@ pub struct CardanoDatabaseSnapshotMessage { pub created_at: DateTime, } -impl CardanoDatabaseSnapshotMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - hash: "d4071d518a3ace0f6c04a9c0745b9e9560e3e2af1b373bafc4e0398423e9abfb".to_string(), - merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6" - .to_string(), - network: "preview".to_string(), - beacon: CardanoDbBeacon { - epoch: Epoch(123), - immutable_file_number: 2345, - }, - certificate_hash: "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb" - .to_string(), - total_db_size_uncompressed: 800796318, - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - digests: DigestsMessagePart { - size_uncompressed: 1024, - locations: vec![DigestLocation::Aggregator { - uri: "https://host-1/digest-1".to_string(), - }], - }, - immutables: ImmutablesMessagePart { - average_size_uncompressed: 512, - locations: vec![ - ImmutablesLocation::CloudStorage { - uri: MultiFilesUri::Template(TemplateUri( - "https://host-1/immutables-2".to_string(), - )), - compression_algorithm: Some(CompressionAlgorithm::Gzip), - }, - ImmutablesLocation::CloudStorage { - uri: MultiFilesUri::Template(TemplateUri( - "https://host-2/immutables-2".to_string(), - )), - compression_algorithm: Some(CompressionAlgorithm::Gzip), - }, - ], - }, - ancillary: AncillaryMessagePart { - size_uncompressed: 2048, - locations: vec![AncillaryLocation::CloudStorage { - uri: "https://host-1/ancillary-3".to_string(), - compression_algorithm: Some(CompressionAlgorithm::Gzip), - }], - }, - cardano_node_version: "0.0.1".to_string(), - } - } -} - #[cfg(test)] mod tests { + use crate::entities::{CompressionAlgorithm, Epoch, MultiFilesUri, TemplateUri}; + use super::*; const CURRENT_JSON: &str = r#" diff --git a/mithril-common/src/messages/cardano_database_digest_list.rs b/mithril-common/src/messages/cardano_database_digest_list.rs index 4cafcfb0bf1..dd567f0bb2e 100644 --- a/mithril-common/src/messages/cardano_database_digest_list.rs +++ b/mithril-common/src/messages/cardano_database_digest_list.rs @@ -15,16 +15,6 @@ pub struct CardanoDatabaseDigestListItemMessage { pub digest: HexEncodedDigest, } -impl CardanoDatabaseDigestListItemMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - immutable_file_name: "06685.chunk".to_string(), - digest: "0af556ab2620dd9363bf76963a231abe8948a500ea6be31b131d87907ab09b1e".to_string(), - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/cardano_database_immutable_files_restored.rs b/mithril-common/src/messages/cardano_database_immutable_files_restored.rs index 9918bdb2ae5..135f5528a4a 100644 --- a/mithril-common/src/messages/cardano_database_immutable_files_restored.rs +++ b/mithril-common/src/messages/cardano_database_immutable_files_restored.rs @@ -7,15 +7,6 @@ pub struct CardanoDatabaseImmutableFilesRestoredMessage { pub nb_immutable_files: u32, } -impl CardanoDatabaseImmutableFilesRestoredMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - nb_immutable_files: 34, - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/cardano_database_list.rs b/mithril-common/src/messages/cardano_database_list.rs index 292795493a9..2d21274f32b 100644 --- a/mithril-common/src/messages/cardano_database_list.rs +++ b/mithril-common/src/messages/cardano_database_list.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use crate::entities::{CardanoDbBeacon, Epoch}; +use crate::entities::CardanoDbBeacon; /// Message structure of a Cardano database snapshot list pub type CardanoDatabaseSnapshotListMessage = Vec; @@ -31,30 +31,10 @@ pub struct CardanoDatabaseSnapshotListItemMessage { pub created_at: DateTime, } -impl CardanoDatabaseSnapshotListItemMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - hash: "d4071d518a3ace0f6c04a9c0745b9e9560e3e2af1b373bafc4e0398423e9abfb".to_string(), - merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6" - .to_string(), - beacon: CardanoDbBeacon { - epoch: Epoch(123), - immutable_file_number: 2345, - }, - certificate_hash: "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb" - .to_string(), - total_db_size_uncompressed: 800796318, - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - cardano_node_version: "0.0.1".to_string(), - } - } -} - #[cfg(test)] mod tests { + use crate::entities::Epoch; + use super::*; const CURRENT_JSON: &str = r#" diff --git a/mithril-common/src/messages/cardano_stake_distribution.rs b/mithril-common/src/messages/cardano_stake_distribution.rs index 4a46c9c4695..70257489a0e 100644 --- a/mithril-common/src/messages/cardano_stake_distribution.rs +++ b/mithril-common/src/messages/cardano_stake_distribution.rs @@ -24,25 +24,6 @@ pub struct CardanoStakeDistributionMessage { pub created_at: DateTime, } -impl CardanoStakeDistributionMessage { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - epoch: Epoch(1), - hash: "hash-123".to_string(), - certificate_hash: "cert-hash-123".to_string(), - stake_distribution: StakeDistribution::from([ - ("pool-123".to_string(), 1000), - ]), - created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/cardano_stake_distribution_list.rs b/mithril-common/src/messages/cardano_stake_distribution_list.rs index 01e02a4c2ad..6f239b2dc96 100644 --- a/mithril-common/src/messages/cardano_stake_distribution_list.rs +++ b/mithril-common/src/messages/cardano_stake_distribution_list.rs @@ -22,20 +22,6 @@ pub struct CardanoStakeDistributionListItemMessage { pub created_at: DateTime, } -impl CardanoStakeDistributionListItemMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - epoch: Epoch(1), - hash: "hash-123".to_string(), - certificate_hash: "certificate-hash-123".to_string(), - created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/cardano_transaction_snapshot.rs b/mithril-common/src/messages/cardano_transaction_snapshot.rs index 6942cc57aa7..0c5db3716ae 100644 --- a/mithril-common/src/messages/cardano_transaction_snapshot.rs +++ b/mithril-common/src/messages/cardano_transaction_snapshot.rs @@ -26,24 +26,6 @@ pub struct CardanoTransactionSnapshotMessage { pub created_at: DateTime, } -impl CardanoTransactionSnapshotMessage { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - merkle_root: "mkroot-123".to_string(), - epoch: Epoch(10), - block_number: BlockNumber(100), - hash: "hash-123".to_string(), - certificate_hash: "cert-hash-123".to_string(), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/cardano_transaction_snapshot_list.rs b/mithril-common/src/messages/cardano_transaction_snapshot_list.rs index aae811d5567..0587331aeff 100644 --- a/mithril-common/src/messages/cardano_transaction_snapshot_list.rs +++ b/mithril-common/src/messages/cardano_transaction_snapshot_list.rs @@ -28,24 +28,6 @@ pub struct CardanoTransactionSnapshotListItemMessage { pub created_at: DateTime, } -impl CardanoTransactionSnapshotListItemMessage { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - merkle_root: "mkroot-123".to_string(), - epoch: Epoch(10), - block_number: BlockNumber(100), - hash: "hash-123".to_string(), - certificate_hash: "cert-hash-123".to_string(), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/cardano_transactions_proof.rs b/mithril-common/src/messages/cardano_transactions_proof.rs index 0ff7a654da5..a3b926b87bb 100644 --- a/mithril-common/src/messages/cardano_transactions_proof.rs +++ b/mithril-common/src/messages/cardano_transactions_proof.rs @@ -181,13 +181,15 @@ impl CardanoTransactionsProofsMessage { #[cfg(test)] mod tests { + use std::sync::Arc; + use crate::crypto_helper::{MKMap, MKMapNode, MKProof, MKTreeStoreInMemory}; use crate::entities::{BlockNumber, BlockRange, CardanoTransaction, SlotNumber}; use crate::signable_builder::{ CardanoTransactionsSignableBuilder, MockBlockRangeRootRetriever, MockTransactionsImporter, SignableBuilder, }; - use std::sync::Arc; + use crate::test_utils::double::Dummy; use super::*; diff --git a/mithril-common/src/messages/certificate.rs b/mithril-common/src/messages/certificate.rs index 0bf7193b0ca..3e10555ea51 100644 --- a/mithril-common/src/messages/certificate.rs +++ b/mithril-common/src/messages/certificate.rs @@ -9,8 +9,6 @@ use crate::entities::{ SignedEntityType, }; use crate::messages::CertificateMetadataMessagePart; -#[cfg(any(test, feature = "test_tools"))] -use crate::{entities::ProtocolMessagePartKey, test_utils::fake_keys}; /// Message structure of a certificate #[derive(Clone, PartialEq, Serialize, Deserialize)] @@ -60,35 +58,6 @@ pub struct CertificateMessage { } impl CertificateMessage { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - let mut protocol_message = ProtocolMessage::new(); - protocol_message.set_message_part( - ProtocolMessagePartKey::SnapshotDigest, - "snapshot-digest-123".to_string(), - ); - protocol_message.set_message_part( - ProtocolMessagePartKey::NextAggregateVerificationKey, - fake_keys::aggregate_verification_key()[1].to_owned(), - ); - let epoch = Epoch(10); - - Self { - hash: "hash".to_string(), - previous_hash: "previous_hash".to_string(), - epoch, - signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch), - metadata: CertificateMetadataMessagePart::dummy(), - protocol_message: protocol_message.clone(), - signed_message: "signed_message".to_string(), - aggregate_verification_key: fake_keys::aggregate_verification_key()[0].to_owned(), - multi_signature: fake_keys::multi_signature()[0].to_owned(), - genesis_signature: String::new(), - } - } - } - /// Check that the certificate signed message match the given protocol message. pub fn match_message(&self, message: &ProtocolMessage) -> bool { message.compute_hash() == self.signed_message @@ -235,7 +204,9 @@ impl TryFrom for CertificateMessage { mod tests { use chrono::{DateTime, Utc}; - use crate::entities::{CardanoDbBeacon, ProtocolParameters, StakeDistributionParty}; + use crate::entities::{ + CardanoDbBeacon, ProtocolMessagePartKey, ProtocolParameters, StakeDistributionParty, + }; use super::*; diff --git a/mithril-common/src/messages/certificate_list.rs b/mithril-common/src/messages/certificate_list.rs index f805a3bb36c..67f7d6f0af7 100644 --- a/mithril-common/src/messages/certificate_list.rs +++ b/mithril-common/src/messages/certificate_list.rs @@ -3,8 +3,7 @@ use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Formatter}; use crate::entities::{ - Epoch, ProtocolMessage, ProtocolMessagePartKey, ProtocolParameters, ProtocolVersion, - SignedEntityType, + Epoch, ProtocolMessage, ProtocolParameters, ProtocolVersion, SignedEntityType, }; /// Message structure of a certificate list @@ -82,44 +81,6 @@ pub struct CertificateListItemMessage { pub aggregate_verification_key: String, } -impl CertificateListItemMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - let mut protocol_message = ProtocolMessage::new(); - protocol_message.set_message_part( - ProtocolMessagePartKey::SnapshotDigest, - "snapshot-digest-123".to_string(), - ); - protocol_message.set_message_part( - ProtocolMessagePartKey::NextAggregateVerificationKey, - "next-avk-123".to_string(), - ); - let epoch = Epoch(10); - - Self { - hash: "hash".to_string(), - previous_hash: "previous_hash".to_string(), - epoch, - signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch), - metadata: CertificateListItemMessageMetadata { - network: "testnet".to_string(), - protocol_version: "0.1.0".to_string(), - protocol_parameters: ProtocolParameters::new(1000, 100, 0.123), - initiated_at: DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z") - .unwrap() - .with_timezone(&Utc), - sealed_at: DateTime::parse_from_rfc3339("2024-02-12T13:12:57Z") - .unwrap() - .with_timezone(&Utc), - total_signers: 2, - }, - protocol_message: protocol_message.clone(), - signed_message: "signed_message".to_string(), - aggregate_verification_key: "aggregate_verification_key".to_string(), - } - } -} - impl Debug for CertificateListItemMessage { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let should_be_exhaustive = f.alternate(); @@ -153,7 +114,7 @@ impl Debug for CertificateListItemMessage { #[cfg(test)] mod tests { - use crate::entities::CardanoDbBeacon; + use crate::entities::{CardanoDbBeacon, ProtocolMessagePartKey}; use super::*; diff --git a/mithril-common/src/messages/epoch_settings.rs b/mithril-common/src/messages/epoch_settings.rs index ae952ea5890..1860dd8daf6 100644 --- a/mithril-common/src/messages/epoch_settings.rs +++ b/mithril-common/src/messages/epoch_settings.rs @@ -27,26 +27,6 @@ pub struct EpochSettingsMessage { pub next_cardano_transactions_signing_config: Option, } -impl EpochSettingsMessage { - cfg_test_tools! { - /// Dummy instance for test purposes. - pub fn dummy() -> Self { - Self { - epoch: Epoch(10), - signer_registration_protocol_parameters: ProtocolParameters { - k: 5, - m: 100, - phi_f: 0.65, - }, - current_signers: [SignerMessagePart::dummy()].to_vec(), - next_signers: [SignerMessagePart::dummy()].to_vec(), - cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig::dummy()), - next_cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig::dummy()), - } - } - } -} - #[cfg(test)] mod tests { diff --git a/mithril-common/src/messages/message_parts/cardano_transactions_set_proof.rs b/mithril-common/src/messages/message_parts/cardano_transactions_set_proof.rs index 7d99ebc250e..296c80064a5 100644 --- a/mithril-common/src/messages/message_parts/cardano_transactions_set_proof.rs +++ b/mithril-common/src/messages/message_parts/cardano_transactions_set_proof.rs @@ -19,15 +19,6 @@ pub struct CardanoTransactionsSetProofMessagePart { pub proof: HexEncodedKey, } -impl CardanoTransactionsSetProofMessagePart { - cfg_test_tools! { - /// Retrieve a dummy proof (for test only) - pub fn dummy() -> Self { - crate::entities::CardanoTransactionsSetProof::dummy().try_into().unwrap() - } - } -} - impl TryFrom for CardanoTransactionsSetProofMessagePart { type Error = StdError; diff --git a/mithril-common/src/messages/message_parts/certificate_metadata.rs b/mithril-common/src/messages/message_parts/certificate_metadata.rs index f4b503a50c6..1b106659cee 100644 --- a/mithril-common/src/messages/message_parts/certificate_metadata.rs +++ b/mithril-common/src/messages/message_parts/certificate_metadata.rs @@ -1,6 +1,6 @@ use crate::entities::{ProtocolParameters, ProtocolVersion, StakeDistributionParty}; -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; /// CertificateMetadata represents the metadata associated to a Certificate @@ -36,33 +36,6 @@ pub struct CertificateMetadataMessagePart { pub signers: Vec, } -impl CertificateMetadataMessagePart { - /// CertificateMetadata factory - pub fn dummy() -> Self { - let initiated_at = DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z") - .unwrap() - .with_timezone(&Utc); - - Self { - network: "testnet".to_string(), - protocol_version: "0.1.0".to_string(), - protocol_parameters: ProtocolParameters::new(1000, 100, 0.123), - initiated_at, - sealed_at: initiated_at + Duration::try_seconds(100).unwrap(), - signers: vec![ - StakeDistributionParty { - party_id: "1".to_string(), - stake: 10, - }, - StakeDistributionParty { - party_id: "2".to_string(), - stake: 20, - }, - ], - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/message_parts/signer.rs b/mithril-common/src/messages/message_parts/signer.rs index 2f0849072d0..937595244cb 100644 --- a/mithril-common/src/messages/message_parts/signer.rs +++ b/mithril-common/src/messages/message_parts/signer.rs @@ -1,5 +1,7 @@ -#[cfg(any(test, feature = "test_tools"))] -use crate::test_utils::fake_keys; +use anyhow::Context; +use serde::{Deserialize, Serialize}; +use std::fmt::{Debug, Formatter}; + use crate::{ StdError, StdResult, crypto_helper::{KesPeriod, ProtocolOpCert, ProtocolSignerVerificationKeySignature}, @@ -8,9 +10,6 @@ use crate::{ Signer, SignerWithStake, Stake, }, }; -use anyhow::Context; -use serde::{Deserialize, Serialize}; -use std::fmt::{Debug, Formatter}; /// Signer with Stake Message #[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)] @@ -48,22 +47,6 @@ pub struct SignerWithStakeMessagePart { } impl SignerWithStakeMessagePart { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), - verification_key: fake_keys::signer_verification_key()[0].to_string(), - verification_key_signature: Some( - fake_keys::signer_verification_key_signature()[0].to_string(), - ), - operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()), - kes_period: Some(6), - stake: 234, - } - } - } - /// Convert a set of signers into message parts pub fn from_signers(signers: Vec) -> Vec { signers.into_iter().map(|signer| signer.into()).collect() @@ -200,21 +183,6 @@ impl SignerMessagePart { pub fn from_signers(signers: Vec) -> Vec { signers.into_iter().map(|signer| signer.into()).collect() } - - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), - verification_key: fake_keys::signer_verification_key()[0].to_string(), - verification_key_signature: Some( - fake_keys::signer_verification_key_signature()[0].to_string(), - ), - operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()), - kes_period: Some(6), - } - } - } } impl TryInto for SignerMessagePart { diff --git a/mithril-common/src/messages/mithril_stake_distribution.rs b/mithril-common/src/messages/mithril_stake_distribution.rs index a0a95810fc2..7ba53c0f314 100644 --- a/mithril-common/src/messages/mithril_stake_distribution.rs +++ b/mithril-common/src/messages/mithril_stake_distribution.rs @@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize}; use crate::entities::Epoch; use crate::entities::ProtocolParameters; -#[cfg(any(test, feature = "test_tools"))] -use crate::test_utils::fake_data; use super::SignerWithStakeMessagePart; /// Message structure of a Mithril Stake Distribution @@ -31,26 +29,10 @@ pub struct MithrilStakeDistributionMessage { pub protocol_parameters: ProtocolParameters, } -impl MithrilStakeDistributionMessage { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - epoch: Epoch(1), - signers_with_stake: vec![SignerWithStakeMessagePart::dummy()], - hash: "hash-123".to_string(), - certificate_hash: "cert-hash-123".to_string(), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - protocol_parameters: fake_data::protocol_parameters(), - } - } - } -} - #[cfg(test)] mod tests { + use crate::test_utils::fake_data; + use super::*; fn golden_message_current() -> MithrilStakeDistributionMessage { diff --git a/mithril-common/src/messages/mithril_stake_distribution_list.rs b/mithril-common/src/messages/mithril_stake_distribution_list.rs index 87d46b25d8d..c785d6e2bcf 100644 --- a/mithril-common/src/messages/mithril_stake_distribution_list.rs +++ b/mithril-common/src/messages/mithril_stake_distribution_list.rs @@ -22,20 +22,6 @@ pub struct MithrilStakeDistributionListItemMessage { pub created_at: DateTime, } -impl MithrilStakeDistributionListItemMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - epoch: Epoch(1), - hash: "hash-123".to_string(), - certificate_hash: "certificate-hash-123".to_string(), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/mithril-common/src/messages/register_signature.rs b/mithril-common/src/messages/register_signature.rs index ee6a3598b98..b591ed3a6c8 100644 --- a/mithril-common/src/messages/register_signature.rs +++ b/mithril-common/src/messages/register_signature.rs @@ -9,9 +9,6 @@ use crate::{ entities::{HexEncodedSingleSignature, LotteryIndex, PartyId, SignedEntityType}, }; -#[cfg(any(test, feature = "test_tools"))] -use crate::test_utils::fake_keys; - /// Message structure to register single signature through HTTP. #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct RegisterSignatureMessageHttp { @@ -36,22 +33,6 @@ pub struct RegisterSignatureMessageHttp { pub signed_message: String, } -impl RegisterSignatureMessageHttp { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - use crate::entities::Epoch; - Self { - signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(5)), - party_id: "party_id".to_string(), - signature: fake_keys::single_signature()[0].to_string(), - won_indexes: vec![1, 3], - signed_message: "6a7e737c312972d2346b65ac3075696e04286d046dddaf8004121e3d5e27cc0d".to_string(), - } - } - } -} - impl Debug for RegisterSignatureMessageHttp { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let is_pretty_printing = f.alternate(); @@ -82,17 +63,6 @@ pub struct RegisterSignatureMessageDmq { } impl RegisterSignatureMessageDmq { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - use crate::entities::Epoch; - Self { - signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(5)), - signature: fake_keys::single_signature()[0].try_into().unwrap(), - } - } - } - /// Convert a `RegisterSignatureMessageDmq` into bytes /// /// # Layout diff --git a/mithril-common/src/messages/register_signer.rs b/mithril-common/src/messages/register_signer.rs index b3b6890a261..6391508e919 100644 --- a/mithril-common/src/messages/register_signer.rs +++ b/mithril-common/src/messages/register_signer.rs @@ -41,26 +41,6 @@ pub struct RegisterSignerMessage { pub kes_period: Option, } -impl RegisterSignerMessage { - cfg_test_tools! { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - use crate::test_utils::fake_keys; - - Self { - epoch: Epoch(1), - party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), - verification_key: fake_keys::signer_verification_key()[0].to_string(), - verification_key_signature: Some( - fake_keys::signer_verification_key_signature()[0].to_string(), - ), - operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()), - kes_period: Some(6), - } - } - } -} - impl Debug for RegisterSignerMessage { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let should_be_exhaustive = f.alternate(); diff --git a/mithril-common/src/messages/snapshot.rs b/mithril-common/src/messages/snapshot.rs index be78ca68a99..ff6ba8abcaa 100644 --- a/mithril-common/src/messages/snapshot.rs +++ b/mithril-common/src/messages/snapshot.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use crate::entities::{CardanoDbBeacon, CompressionAlgorithm, Epoch}; +use crate::entities::{CardanoDbBeacon, CompressionAlgorithm}; /// Message structure of a snapshot #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -43,29 +43,6 @@ pub struct SnapshotMessage { } impl SnapshotMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(), - network: "preview".to_string(), - beacon: CardanoDbBeacon { - epoch: Epoch(86), - immutable_file_number: 1728, - }, - certificate_hash: "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb" - .to_string(), - size: 807803196, - ancillary_size: Some(123456789), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - locations: vec!["https://host/certificate.tar.gz".to_string()], - ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]), - compression_algorithm: CompressionAlgorithm::Gzip, - cardano_node_version: "0.0.1".to_string(), - } - } - /// Compute the total size of the snapshot including ancillary files pub fn compute_total_size(&self) -> u64 { self.size + self.ancillary_size.unwrap_or(0) @@ -74,6 +51,9 @@ impl SnapshotMessage { #[cfg(test)] mod tests { + use crate::entities::Epoch; + use crate::test_utils::double::Dummy; + use super::*; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/mithril-common/src/messages/snapshot_download.rs b/mithril-common/src/messages/snapshot_download.rs index fd242744680..97757415c3f 100644 --- a/mithril-common/src/messages/snapshot_download.rs +++ b/mithril-common/src/messages/snapshot_download.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::entities::{CardanoDbBeacon, CompressionAlgorithm, Epoch}; +use crate::entities::{CardanoDbBeacon, CompressionAlgorithm}; /// Message structure of a snapshot #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -35,28 +35,10 @@ pub struct SnapshotDownloadMessage { pub cardano_node_version: String, } -impl SnapshotDownloadMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(), - network: "preview".to_string(), - beacon: CardanoDbBeacon { - epoch: Epoch(86), - immutable_file_number: 1728, - }, - size: 807803196, - ancillary_size: Some(123456789), - locations: vec!["https://host/certificate.tar.gz".to_string()], - ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]), - compression_algorithm: CompressionAlgorithm::Gzip, - cardano_node_version: "0.0.1".to_string(), - } - } -} - #[cfg(test)] mod tests { + use crate::entities::Epoch; + use super::*; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/mithril-common/src/messages/snapshot_list.rs b/mithril-common/src/messages/snapshot_list.rs index 6a5b9533e70..a3349fdee0e 100644 --- a/mithril-common/src/messages/snapshot_list.rs +++ b/mithril-common/src/messages/snapshot_list.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; -use crate::entities::{CardanoDbBeacon, CompressionAlgorithm, Epoch}; +use crate::entities::{CardanoDbBeacon, CompressionAlgorithm}; /// Message structure of a snapshot list pub type SnapshotListMessage = Vec; @@ -45,33 +45,10 @@ pub struct SnapshotListItemMessage { pub cardano_node_version: String, } -impl SnapshotListItemMessage { - /// Return a dummy test entity (test-only). - pub fn dummy() -> Self { - Self { - digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(), - network: "preview".to_string(), - beacon: CardanoDbBeacon { - epoch: Epoch(86), - immutable_file_number: 1728, - }, - certificate_hash: "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb" - .to_string(), - size: 807803196, - ancillary_size: Some(123456789), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - locations: vec!["https://host/certificate.tar.gz".to_string()], - ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]), - compression_algorithm: CompressionAlgorithm::default(), - cardano_node_version: "0.0.1".to_string(), - } - } -} - #[cfg(test)] mod tests { + use crate::entities::Epoch; + use super::*; pub type SnapshotListMessageUntilV0_1_47 = Vec; diff --git a/mithril-common/src/signable_builder/signed_entity.rs b/mithril-common/src/signable_builder/signed_entity.rs index 2084f1a80ee..834a6e78ed2 100644 --- a/mithril-common/src/signable_builder/signed_entity.rs +++ b/mithril-common/src/signable_builder/signed_entity.rs @@ -1,15 +1,7 @@ use chrono::{DateTime, Utc}; use super::Artifact; -use crate::entities::{ - CardanoStakeDistribution, CardanoTransactionsSnapshot, MithrilStakeDistribution, - SignedEntityType, Snapshot, -}; -#[cfg(any(test, feature = "test_tools"))] -use crate::test_utils::fake_data; - -#[cfg(any(test, feature = "test_tools"))] -use crate::entities::{CardanoDbBeacon, Epoch}; +use crate::entities::SignedEntityType; /// Aggregate for signed entity #[derive(Debug, Clone)] @@ -32,72 +24,3 @@ where /// Date and time when the signed_entity was created pub created_at: DateTime, } - -impl SignedEntity { - cfg_test_tools! { - /// Create a dummy [SignedEntity] for [Snapshot] entity - pub fn dummy() -> Self { - SignedEntity { - signed_entity_id: "snapshot-id-123".to_string(), - signed_entity_type: SignedEntityType::CardanoImmutableFilesFull(CardanoDbBeacon::default()), - certificate_id: "certificate-hash-123".to_string(), - artifact: fake_data::snapshots(1)[0].to_owned(), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} - -impl SignedEntity { - cfg_test_tools! { - /// Create a dummy [SignedEntity] for [MithrilStakeDistribution] entity - pub fn dummy() -> Self { - SignedEntity { - signed_entity_id: "mithril-stake-distribution-id-123".to_string(), - signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(1)), - certificate_id: "certificate-hash-123".to_string(), - artifact: fake_data::mithril_stake_distributions(1)[0].to_owned(), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} - -impl SignedEntity { - cfg_test_tools! { - /// Create a dummy [SignedEntity] for [CardanoTransactionsSnapshot] entity - pub fn dummy() -> Self { - let block_number = crate::entities::BlockNumber(50); - SignedEntity { - signed_entity_id: "snapshot-id-123".to_string(), - signed_entity_type: SignedEntityType::CardanoTransactions(Epoch(5), block_number), - certificate_id: "certificate-hash-123".to_string(), - artifact: CardanoTransactionsSnapshot::new("mkroot123".to_string(), block_number), - created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} - -impl SignedEntity { - cfg_test_tools! { - /// Create a dummy [SignedEntity] for [CardanoStakeDistribution] entity - pub fn dummy() -> Self { - SignedEntity { - signed_entity_id: "cardano-stake-distribution-id-123".to_string(), - signed_entity_type: SignedEntityType::CardanoStakeDistribution(Epoch(1)), - certificate_id: "certificate-hash-123".to_string(), - artifact: fake_data::cardano_stake_distributions(1)[0].to_owned(), - created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z") - .unwrap() - .with_timezone(&Utc), - } - } - } -} diff --git a/mithril-common/src/test_utils/double/dummies.rs b/mithril-common/src/test_utils/double/dummies.rs new file mode 100644 index 00000000000..f4ea1c42fc0 --- /dev/null +++ b/mithril-common/src/test_utils/double/dummies.rs @@ -0,0 +1,640 @@ +use chrono::{DateTime, Utc}; + +use crate::test_utils::{double::Dummy, fake_data, fake_keys}; + +mod entities { + use crate::crypto_helper::MKTreeStoreInMemory; + use crate::entities::*; + + use super::*; + + impl Dummy for ChainPoint { + /// Return a dummy [ChainPoint] (test-only). + fn dummy() -> Self { + Self { + slot_number: SlotNumber(100), + block_number: BlockNumber(0), + block_hash: "block_hash-50".to_string(), + } + } + } + + impl Dummy for CardanoTransactionsSetProof { + /// Return a dummy [CardanoTransactionsSetProof] (test-only). + fn dummy() -> Self { + let leaves = vec![ + (BlockNumber(0), "tx-1".to_string()), + (BlockNumber(1), "tx-2".to_string()), + (BlockNumber(1), "tx-3".to_string()), + (BlockNumber(10), "tx-4".to_string()), + (BlockNumber(20), "tx-5".to_string()), + (BlockNumber(22), "tx-6".to_string()), + ]; + + Self::from_leaves::(&leaves).unwrap() + } + } + + impl Dummy for SignedEntityConfig { + /// Return a dummy [SignedEntityConfig] (test-only). + fn dummy() -> Self { + Self { + allowed_discriminants: SignedEntityTypeDiscriminants::all(), + cardano_transactions_signing_config: CardanoTransactionsSigningConfig::dummy(), + } + } + } + + impl Dummy for CardanoTransactionsSigningConfig { + /// Return a dummy [CardanoTransactionsSigningConfig] (test-only). + fn dummy() -> Self { + Self { + security_parameter: BlockNumber(0), + step: BlockNumber(15), + } + } + } + + impl Dummy for SignedEntityType { + /// Return a dummy [SignedEntityType] (test-only). + fn dummy() -> Self { + Self::MithrilStakeDistribution(Epoch(5)) + } + } + + impl Dummy for SupportedEra { + /// Return a dummy [SupportedEra] (test-only). + fn dummy() -> Self { + Self::eras().first().unwrap().to_owned() + } + } + + impl Dummy for TimePoint { + /// Return a dummy [TimePoint] (test-only). + fn dummy() -> Self { + Self::new(10, 100, ChainPoint::dummy()) + } + } +} + +mod messages { + use chrono::Duration; + use std::collections::BTreeSet; + + use crate::entities::{ + AncillaryLocation, BlockNumber, CardanoDbBeacon, CardanoTransactionsSetProof, + CardanoTransactionsSigningConfig, CompressionAlgorithm, DigestLocation, Epoch, + ImmutablesLocation, MultiFilesUri, ProtocolMessage, ProtocolMessagePartKey, + ProtocolParameters, SignedEntityType, SignedEntityTypeDiscriminants, StakeDistribution, + StakeDistributionParty, TemplateUri, + }; + use crate::messages::*; + + use super::*; + + impl Dummy for CardanoTransactionsSetProofMessagePart { + /// Return a dummy [CardanoTransactionsSetProofMessagePart] (test-only). + fn dummy() -> Self { + CardanoTransactionsSetProof::dummy().try_into().unwrap() + } + } + + impl Dummy for CertificateMetadataMessagePart { + /// Return a dummy [CertificateMetadataMessagePart] (test-only). + fn dummy() -> Self { + let initiated_at = DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z") + .unwrap() + .with_timezone(&Utc); + + Self { + network: "testnet".to_string(), + protocol_version: "0.1.0".to_string(), + protocol_parameters: ProtocolParameters::new(1000, 100, 0.123), + initiated_at, + sealed_at: initiated_at + Duration::try_seconds(100).unwrap(), + signers: vec![ + StakeDistributionParty { + party_id: "1".to_string(), + stake: 10, + }, + StakeDistributionParty { + party_id: "2".to_string(), + stake: 20, + }, + ], + } + } + } + + impl Dummy for SignerWithStakeMessagePart { + /// Return a dummy [SignerWithStakeMessagePart] (test-only). + fn dummy() -> Self { + Self { + party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), + verification_key: fake_keys::signer_verification_key()[0].to_string(), + verification_key_signature: Some( + fake_keys::signer_verification_key_signature()[0].to_string(), + ), + operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()), + kes_period: Some(6), + stake: 234, + } + } + } + + impl Dummy for SignerMessagePart { + /// Return a dummy [SignerMessagePart] (test-only). + fn dummy() -> Self { + Self { + party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), + verification_key: fake_keys::signer_verification_key()[0].to_string(), + verification_key_signature: Some( + fake_keys::signer_verification_key_signature()[0].to_string(), + ), + operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()), + kes_period: Some(6), + } + } + } + + impl Dummy for AggregatorFeaturesMessage { + /// Return a dummy [AggregatorFeaturesMessage] (test-only). + fn dummy() -> Self { + AggregatorFeaturesMessage { + open_api_version: "0.0.1".to_string(), + documentation_url: "https://example.com".to_string(), + capabilities: AggregatorCapabilities { + signed_entity_types: BTreeSet::from([ + SignedEntityTypeDiscriminants::MithrilStakeDistribution, + ]), + cardano_transactions_prover: None, + }, + } + } + } + + impl Dummy for CardanoDatabaseSnapshotMessage { + /// Return a dummy [CardanoDatabaseSnapshotMessage] (test-only). + fn dummy() -> Self { + Self { + hash: "d4071d518a3ace0f6c04a9c0745b9e9560e3e2af1b373bafc4e0398423e9abfb" + .to_string(), + merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6" + .to_string(), + network: "preview".to_string(), + beacon: CardanoDbBeacon { + epoch: Epoch(123), + immutable_file_number: 2345, + }, + certificate_hash: + "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb".to_string(), + total_db_size_uncompressed: 800796318, + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + digests: DigestsMessagePart { + size_uncompressed: 1024, + locations: vec![DigestLocation::Aggregator { + uri: "https://host-1/digest-1".to_string(), + }], + }, + immutables: ImmutablesMessagePart { + average_size_uncompressed: 512, + locations: vec![ + ImmutablesLocation::CloudStorage { + uri: MultiFilesUri::Template(TemplateUri( + "https://host-1/immutables-2".to_string(), + )), + compression_algorithm: Some(CompressionAlgorithm::Gzip), + }, + ImmutablesLocation::CloudStorage { + uri: MultiFilesUri::Template(TemplateUri( + "https://host-2/immutables-2".to_string(), + )), + compression_algorithm: Some(CompressionAlgorithm::Gzip), + }, + ], + }, + ancillary: AncillaryMessagePart { + size_uncompressed: 2048, + locations: vec![AncillaryLocation::CloudStorage { + uri: "https://host-1/ancillary-3".to_string(), + compression_algorithm: Some(CompressionAlgorithm::Gzip), + }], + }, + cardano_node_version: "0.0.1".to_string(), + } + } + } + + impl Dummy for CardanoDatabaseDigestListItemMessage { + /// Return a dummy [CardanoDatabaseDigestListItemMessage] (test-only). + fn dummy() -> Self { + Self { + immutable_file_name: "06685.chunk".to_string(), + digest: "0af556ab2620dd9363bf76963a231abe8948a500ea6be31b131d87907ab09b1e" + .to_string(), + } + } + } + + impl Dummy for CardanoDatabaseImmutableFilesRestoredMessage { + /// Return a dummy [CardanoDatabaseImmutableFilesRestoredMessage] (test-only). + fn dummy() -> Self { + Self { + nb_immutable_files: 34, + } + } + } + + impl Dummy for CardanoDatabaseSnapshotListItemMessage { + /// Return a dummy [CardanoDatabaseSnapshotListItemMessage] (test-only). + fn dummy() -> Self { + Self { + hash: "d4071d518a3ace0f6c04a9c0745b9e9560e3e2af1b373bafc4e0398423e9abfb" + .to_string(), + merkle_root: "c8224920b9f5ad7377594eb8a15f34f08eb3103cc5241d57cafc5638403ec7c6" + .to_string(), + beacon: CardanoDbBeacon { + epoch: Epoch(123), + immutable_file_number: 2345, + }, + certificate_hash: + "f6c01b373bafc4e039844071d5da3ace4a9c0745b9e9560e3e2af01823e9abfb".to_string(), + total_db_size_uncompressed: 800796318, + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + cardano_node_version: "0.0.1".to_string(), + } + } + } + + impl Dummy for CardanoStakeDistributionMessage { + /// Return a dummy [CardanoStakeDistributionMessage] (test-only). + fn dummy() -> Self { + Self { + epoch: Epoch(1), + hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), + stake_distribution: StakeDistribution::from([("pool-123".to_string(), 1000)]), + created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for CardanoStakeDistributionListItemMessage { + /// Return a dummy [CardanoStakeDistributionListItemMessage] (test-only). + fn dummy() -> Self { + Self { + epoch: Epoch(1), + hash: "hash-123".to_string(), + certificate_hash: "certificate-hash-123".to_string(), + created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for CardanoTransactionSnapshotMessage { + /// Return a dummy [CertificateMessage] (test-only). + fn dummy() -> Self { + Self { + merkle_root: "mkroot-123".to_string(), + epoch: Epoch(10), + block_number: BlockNumber(100), + hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for CardanoTransactionSnapshotListItemMessage { + /// Return a dummy [CertificateMessage] (test-only). + fn dummy() -> Self { + Self { + merkle_root: "mkroot-123".to_string(), + epoch: Epoch(10), + block_number: BlockNumber(100), + hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for CertificateMessage { + /// Return a dummy [CertificateMessage] (test-only). + fn dummy() -> Self { + let mut protocol_message = ProtocolMessage::new(); + protocol_message.set_message_part( + ProtocolMessagePartKey::SnapshotDigest, + "snapshot-digest-123".to_string(), + ); + protocol_message.set_message_part( + ProtocolMessagePartKey::NextAggregateVerificationKey, + fake_keys::aggregate_verification_key()[1].to_owned(), + ); + let epoch = Epoch(10); + + Self { + hash: "hash".to_string(), + previous_hash: "previous_hash".to_string(), + epoch, + signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch), + metadata: CertificateMetadataMessagePart::dummy(), + protocol_message: protocol_message.clone(), + signed_message: "signed_message".to_string(), + aggregate_verification_key: fake_keys::aggregate_verification_key()[0].to_owned(), + multi_signature: fake_keys::multi_signature()[0].to_owned(), + genesis_signature: String::new(), + } + } + } + + impl Dummy for CertificateListItemMessage { + /// Return a dummy [CertificateListItemMessage] (test-only). + fn dummy() -> Self { + let mut protocol_message = ProtocolMessage::new(); + protocol_message.set_message_part( + ProtocolMessagePartKey::SnapshotDigest, + "snapshot-digest-123".to_string(), + ); + protocol_message.set_message_part( + ProtocolMessagePartKey::NextAggregateVerificationKey, + "next-avk-123".to_string(), + ); + let epoch = Epoch(10); + + Self { + hash: "hash".to_string(), + previous_hash: "previous_hash".to_string(), + epoch, + signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch), + metadata: CertificateListItemMessageMetadata { + network: "testnet".to_string(), + protocol_version: "0.1.0".to_string(), + protocol_parameters: ProtocolParameters::new(1000, 100, 0.123), + initiated_at: DateTime::parse_from_rfc3339("2024-02-12T13:11:47Z") + .unwrap() + .with_timezone(&Utc), + sealed_at: DateTime::parse_from_rfc3339("2024-02-12T13:12:57Z") + .unwrap() + .with_timezone(&Utc), + total_signers: 2, + }, + protocol_message: protocol_message.clone(), + signed_message: "signed_message".to_string(), + aggregate_verification_key: "aggregate_verification_key".to_string(), + } + } + } + + impl Dummy for EpochSettingsMessage { + /// Return a dummy [EpochSettingsMessage] (test-only). + fn dummy() -> Self { + Self { + epoch: Epoch(10), + signer_registration_protocol_parameters: ProtocolParameters { + k: 5, + m: 100, + phi_f: 0.65, + }, + current_signers: [SignerMessagePart::dummy()].to_vec(), + next_signers: [SignerMessagePart::dummy()].to_vec(), + cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig::dummy()), + next_cardano_transactions_signing_config: Some( + CardanoTransactionsSigningConfig::dummy(), + ), + } + } + } + + impl Dummy for MithrilStakeDistributionMessage { + /// Return a dummy [MithrilStakeDistributionMessage] (test-only). + fn dummy() -> Self { + Self { + epoch: Epoch(1), + signers_with_stake: vec![SignerWithStakeMessagePart::dummy()], + hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + protocol_parameters: fake_data::protocol_parameters(), + } + } + } + + impl Dummy for MithrilStakeDistributionListItemMessage { + /// Return a dummy [MithrilStakeDistributionListItemMessage] (test-only). + fn dummy() -> Self { + Self { + epoch: Epoch(1), + hash: "hash-123".to_string(), + certificate_hash: "certificate-hash-123".to_string(), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for RegisterSignatureMessageHttp { + /// Return a dummy [RegisterSignatureMessageHttp] (test-only). + fn dummy() -> Self { + use crate::entities::Epoch; + Self { + signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(5)), + party_id: "party_id".to_string(), + signature: fake_keys::single_signature()[0].to_string(), + won_indexes: vec![1, 3], + signed_message: "6a7e737c312972d2346b65ac3075696e04286d046dddaf8004121e3d5e27cc0d" + .to_string(), + } + } + } + + impl Dummy for RegisterSignatureMessageDmq { + /// Return a dummy [RegisterSignatureMessageDmq] (test-only). + fn dummy() -> Self { + use crate::entities::Epoch; + Self { + signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(5)), + signature: fake_keys::single_signature()[0].try_into().unwrap(), + } + } + } + + impl Dummy for RegisterSignerMessage { + /// Return a dummy [RegisterSignerMessage] (test-only). + fn dummy() -> Self { + use crate::test_utils::fake_keys; + + Self { + epoch: Epoch(1), + party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), + verification_key: fake_keys::signer_verification_key()[0].to_string(), + verification_key_signature: Some( + fake_keys::signer_verification_key_signature()[0].to_string(), + ), + operational_certificate: Some(fake_keys::operational_certificate()[0].to_string()), + kes_period: Some(6), + } + } + } + + impl Dummy for SnapshotMessage { + /// Return a dummy [SnapshotMessage] (test-only). + fn dummy() -> Self { + Self { + digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6" + .to_string(), + network: "preview".to_string(), + beacon: CardanoDbBeacon { + epoch: Epoch(86), + immutable_file_number: 1728, + }, + certificate_hash: + "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb".to_string(), + size: 807803196, + ancillary_size: Some(123456789), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + locations: vec!["https://host/certificate.tar.gz".to_string()], + ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]), + compression_algorithm: CompressionAlgorithm::Gzip, + cardano_node_version: "0.0.1".to_string(), + } + } + } + + impl Dummy for SnapshotDownloadMessage { + /// Return a dummy [SnapshotDownloadMessage] (test-only). + fn dummy() -> Self { + Self { + digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6" + .to_string(), + network: "preview".to_string(), + beacon: CardanoDbBeacon { + epoch: Epoch(86), + immutable_file_number: 1728, + }, + size: 807803196, + ancillary_size: Some(123456789), + locations: vec!["https://host/certificate.tar.gz".to_string()], + ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]), + compression_algorithm: CompressionAlgorithm::Gzip, + cardano_node_version: "0.0.1".to_string(), + } + } + } + + impl Dummy for SnapshotListItemMessage { + /// Return a dummy [SnapshotListItemMessage] (test-only). + fn dummy() -> Self { + Self { + digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6" + .to_string(), + network: "preview".to_string(), + beacon: CardanoDbBeacon { + epoch: Epoch(86), + immutable_file_number: 1728, + }, + certificate_hash: + "d5daf6c03ace4a9c074e951844075b9b373bafc4e039160e3e2af01823e9abfb".to_string(), + size: 807803196, + ancillary_size: Some(123456789), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + locations: vec!["https://host/certificate.tar.gz".to_string()], + ancillary_locations: Some(vec!["https://host/ancillary.tar.gz".to_string()]), + compression_algorithm: CompressionAlgorithm::default(), + cardano_node_version: "0.0.1".to_string(), + } + } + } +} + +mod signable_builder { + use crate::entities::{ + CardanoDbBeacon, CardanoStakeDistribution, CardanoTransactionsSnapshot, Epoch, + MithrilStakeDistribution, SignedEntityType, Snapshot, + }; + use crate::signable_builder::SignedEntity; + + use super::*; + + impl Dummy for SignedEntity { + /// Create a dummy [SignedEntity] for [Snapshot] entity + fn dummy() -> Self { + SignedEntity { + signed_entity_id: "snapshot-id-123".to_string(), + signed_entity_type: SignedEntityType::CardanoImmutableFilesFull( + CardanoDbBeacon::default(), + ), + certificate_id: "certificate-hash-123".to_string(), + artifact: fake_data::snapshots(1)[0].to_owned(), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for SignedEntity { + /// Create a dummy [SignedEntity] for [MithrilStakeDistribution] entity + fn dummy() -> Self { + SignedEntity { + signed_entity_id: "mithril-stake-distribution-id-123".to_string(), + signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(1)), + certificate_id: "certificate-hash-123".to_string(), + artifact: fake_data::mithril_stake_distributions(1)[0].to_owned(), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for SignedEntity { + /// Create a dummy [SignedEntity] for [CardanoTransactionsSnapshot] entity + fn dummy() -> Self { + let block_number = crate::entities::BlockNumber(50); + SignedEntity { + signed_entity_id: "snapshot-id-123".to_string(), + signed_entity_type: SignedEntityType::CardanoTransactions(Epoch(5), block_number), + certificate_id: "certificate-hash-123".to_string(), + artifact: CardanoTransactionsSnapshot::new("mkroot123".to_string(), block_number), + created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } + + impl Dummy for SignedEntity { + /// Create a dummy [SignedEntity] for [CardanoStakeDistribution] entity + fn dummy() -> Self { + SignedEntity { + signed_entity_id: "cardano-stake-distribution-id-123".to_string(), + signed_entity_type: SignedEntityType::CardanoStakeDistribution(Epoch(1)), + certificate_id: "certificate-hash-123".to_string(), + artifact: fake_data::cardano_stake_distributions(1)[0].to_owned(), + created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z") + .unwrap() + .with_timezone(&Utc), + } + } + } +} diff --git a/mithril-common/src/test_utils/double/mod.rs b/mithril-common/src/test_utils/double/mod.rs new file mode 100644 index 00000000000..4563ec8d91b --- /dev/null +++ b/mithril-common/src/test_utils/double/mod.rs @@ -0,0 +1,35 @@ +//! Test doubles +//! +//! Enable unit testing with controlled inputs and predictable behavior. + +mod dummies; + +/// A trait for giving a type a dummy value. +/// +/// Sometimes in tests you need to provide a value for a type, but the actual value doesn't matter. +/// This trait allows defining a "dummy" value for a type, separated from an eventual default +/// value, that can be reused across multiple tests. +/// +/// Note: should not be confused with "fake" values, fake values aim to be believable and contain +/// valid cryptography (if they have some), dummies don't aim for those characteristics. +/// +/// # Example +/// ``` +/// use mithril_common::test_utils::double::Dummy; +/// +/// struct MyType(String); +/// +/// impl Dummy for MyType { +/// fn dummy() -> Self { +/// MyType("whatever".to_string()) +/// } +/// } +/// +/// let instance = MyType::dummy(); +/// ``` +pub trait Dummy: Sized { + /// Return a dummy value for the type + /// + /// Useful for test contexts when the actual value doesn't matter. + fn dummy() -> Self; +} diff --git a/mithril-common/src/test_utils/fake_data.rs b/mithril-common/src/test_utils/fake_data.rs index 2f0568ebcb6..a19084a5950 100644 --- a/mithril-common/src/test_utils/fake_data.rs +++ b/mithril-common/src/test_utils/fake_data.rs @@ -11,13 +11,13 @@ use crate::entities::{ ImmutablesLocations, LotteryIndex, ProtocolMessage, ProtocolMessagePartKey, SignedEntityType, SingleSignature, SlotNumber, StakeDistribution, StakeDistributionParty, }; -use crate::test_utils::MithrilFixtureBuilder; +use crate::test_utils::{MithrilFixtureBuilder, double::Dummy}; use super::fake_keys; /// Fake network -pub fn network() -> crate::CardanoNetwork { - crate::CardanoNetwork::TestNet(CardanoNetwork::DEVNET_MAGIC_ID) +pub fn network() -> CardanoNetwork { + CardanoNetwork::TestNet(CardanoNetwork::DEVNET_MAGIC_ID) } /// Fake Beacon diff --git a/mithril-common/src/test_utils/mod.rs b/mithril-common/src/test_utils/mod.rs index 535e27de0f0..ff6e9311610 100644 --- a/mithril-common/src/test_utils/mod.rs +++ b/mithril-common/src/test_utils/mod.rs @@ -6,6 +6,7 @@ //! * A builder of [MithrilFixture] to generate signers alongside a stake distribution //! +pub mod double; pub mod fake_data; pub mod fake_keys; pub mod mock_extensions; diff --git a/mithril-relay/Cargo.toml b/mithril-relay/Cargo.toml index 645cf7b087a..2cc3ed0e29d 100644 --- a/mithril-relay/Cargo.toml +++ b/mithril-relay/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-relay" -version = "0.1.47" +version = "0.1.48" description = "A Mithril relay" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-relay/src/relay/aggregator.rs b/mithril-relay/src/relay/aggregator.rs index 9ec0e155896..0d25c4c829f 100644 --- a/mithril-relay/src/relay/aggregator.rs +++ b/mithril-relay/src/relay/aggregator.rs @@ -154,6 +154,7 @@ impl AggregatorRelay { #[cfg(test)] mod tests { use httpmock::MockServer; + use mithril_common::test_utils::double::Dummy; use crate::test_tools::TestLogger; diff --git a/mithril-relay/src/relay/signer.rs b/mithril-relay/src/relay/signer.rs index 2587666f13d..8b429ee6cf3 100644 --- a/mithril-relay/src/relay/signer.rs +++ b/mithril-relay/src/relay/signer.rs @@ -398,6 +398,7 @@ mod tests { Method::{GET, POST}, MockServer, }; + use mithril_common::test_utils::double::Dummy; use tokio::sync::mpsc::error::TryRecvError; use crate::{repeater, test_tools::TestLogger}; diff --git a/mithril-relay/tests/register_signer_signature.rs b/mithril-relay/tests/register_signer_signature.rs index 39a3c12818f..7c58670c008 100644 --- a/mithril-relay/tests/register_signer_signature.rs +++ b/mithril-relay/tests/register_signer_signature.rs @@ -2,6 +2,7 @@ use std::{sync::Arc, time::Duration}; use libp2p::{Multiaddr, gossipsub}; use mithril_common::messages::{RegisterSignatureMessageHttp, RegisterSignerMessage}; +use mithril_common::test_utils::double::Dummy; use mithril_relay::{ PassiveRelay, SignerRelay, SignerRelayMode, p2p::{BroadcastMessage, PeerBehaviourEvent, PeerEvent}, diff --git a/mithril-signer/Cargo.toml b/mithril-signer/Cargo.toml index 1c1230bc888..976b825d980 100644 --- a/mithril-signer/Cargo.toml +++ b/mithril-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signer" -version = "0.2.260" +version = "0.2.261" description = "A Mithril Signer" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-signer/src/database/repository/signed_beacon_repository.rs b/mithril-signer/src/database/repository/signed_beacon_repository.rs index 5da4e1587bf..8848ef86795 100644 --- a/mithril-signer/src/database/repository/signed_beacon_repository.rs +++ b/mithril-signer/src/database/repository/signed_beacon_repository.rs @@ -90,6 +90,7 @@ mod tests { use mithril_common::entities::{ BlockNumber, Epoch, SignedEntityConfig, SignedEntityTypeDiscriminants, TimePoint, }; + use mithril_common::test_utils::double::Dummy; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::query::GetSignedBeaconQuery; diff --git a/mithril-signer/src/dependency_injection/builder.rs b/mithril-signer/src/dependency_injection/builder.rs index 84901ff2236..78ccc696f7b 100644 --- a/mithril-signer/src/dependency_injection/builder.rs +++ b/mithril-signer/src/dependency_injection/builder.rs @@ -507,6 +507,7 @@ mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_cardano_node_internal_database::test::double::DumbImmutableFileObserver; + use mithril_common::test_utils::double::Dummy; use mithril_common::{entities::TimePoint, test_utils::TempDir}; use crate::test_tools::TestLogger; diff --git a/mithril-signer/src/entities/signer_epoch_settings.rs b/mithril-signer/src/entities/signer_epoch_settings.rs index 618c6ce0df8..1a1df619ce7 100644 --- a/mithril-signer/src/entities/signer_epoch_settings.rs +++ b/mithril-signer/src/entities/signer_epoch_settings.rs @@ -24,10 +24,10 @@ pub struct SignerEpochSettings { pub next_cardano_transactions_signing_config: Option, } -impl SignerEpochSettings { - #[cfg(test)] - /// Create a dummy SignerEpochSettings - pub fn dummy() -> SignerEpochSettings { +#[cfg(test)] +impl mithril_common::test_utils::double::Dummy for SignerEpochSettings { + /// Create a dummy `SignerEpochSettings` + fn dummy() -> SignerEpochSettings { use mithril_common::test_utils::fake_data; // Beacon diff --git a/mithril-signer/src/message_adapters/from_epoch_settings.rs b/mithril-signer/src/message_adapters/from_epoch_settings.rs index 55a11b1db0a..d9cb5a61a5f 100644 --- a/mithril-signer/src/message_adapters/from_epoch_settings.rs +++ b/mithril-signer/src/message_adapters/from_epoch_settings.rs @@ -29,6 +29,8 @@ impl TryFromMessageAdapter for FromEp #[cfg(test)] mod tests { + use mithril_common::test_utils::double::Dummy; + use super::*; #[test] diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 9a6755b5ff3..95021d5acf5 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -353,7 +353,7 @@ mod tests { CardanoTransactionsSignableBuilder, MithrilSignableBuilderService, MithrilStakeDistributionSignableBuilder, SignableBuilderServiceDependencies, }, - test_utils::{MithrilFixtureBuilder, fake_data}, + test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, }; use mithril_era::{EraChecker, EraReader, adapters::EraReaderBootstrapAdapter}; use mithril_signed_entity_lock::SignedEntityTypeLock; diff --git a/mithril-signer/src/runtime/state_machine.rs b/mithril-signer/src/runtime/state_machine.rs index d277cc9663f..78e86f91b04 100644 --- a/mithril-signer/src/runtime/state_machine.rs +++ b/mithril-signer/src/runtime/state_machine.rs @@ -477,7 +477,7 @@ mod tests { use mockall::predicate; use mithril_common::entities::{ChainPoint, Epoch, ProtocolMessage, SignedEntityType}; - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use crate::runtime::runner::MockSignerRunner; use crate::services::AggregatorClientError; diff --git a/mithril-signer/src/services/aggregator_client.rs b/mithril-signer/src/services/aggregator_client.rs index 6c208255d41..d1d2fbeb1ce 100644 --- a/mithril-signer/src/services/aggregator_client.rs +++ b/mithril-signer/src/services/aggregator_client.rs @@ -380,6 +380,7 @@ impl AggregatorClient for AggregatorHTTPClient { #[cfg(test)] pub(crate) mod dumb { + use mithril_common::test_utils::double::Dummy; use tokio::sync::RwLock; use super::*; @@ -472,7 +473,7 @@ mod tests { use mithril_common::api_version::DummyApiVersionDiscriminantSource; use mithril_common::entities::Epoch; use mithril_common::messages::TryFromMessageAdapter; - use mithril_common::test_utils::{MemoryDrainForTestInspector, fake_data}; + use mithril_common::test_utils::{MemoryDrainForTestInspector, double::Dummy, fake_data}; use crate::test_tools::TestLogger; diff --git a/mithril-signer/src/services/cardano_transactions/preloader_checker.rs b/mithril-signer/src/services/cardano_transactions/preloader_checker.rs index 23739892e8c..cf118cf3fe9 100644 --- a/mithril-signer/src/services/cardano_transactions/preloader_checker.rs +++ b/mithril-signer/src/services/cardano_transactions/preloader_checker.rs @@ -43,6 +43,7 @@ mod tests { use mithril_common::{ entities::SignedEntityTypeDiscriminants, messages::AggregatorFeaturesMessage, + test_utils::double::Dummy, }; use crate::services::{AggregatorClientError, MockAggregatorClient}; diff --git a/mithril-signer/src/services/certifier.rs b/mithril-signer/src/services/certifier.rs index e3c7717dd4f..87a8babbe1c 100644 --- a/mithril-signer/src/services/certifier.rs +++ b/mithril-signer/src/services/certifier.rs @@ -156,7 +156,7 @@ mod tests { CardanoTransactionsSigningConfig, ChainPoint, Epoch, ProtocolMessagePartKey, SignedEntityTypeDiscriminants, }; - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use crate::services::{MockSignaturePublisher, MockSingleSigner}; diff --git a/mithril-signer/src/services/epoch_service.rs b/mithril-signer/src/services/epoch_service.rs index 720e8782557..59452f65e16 100644 --- a/mithril-signer/src/services/epoch_service.rs +++ b/mithril-signer/src/services/epoch_service.rs @@ -428,7 +428,7 @@ mod tests { use tokio::sync::RwLock; use mithril_common::entities::{Epoch, StakeDistribution}; - use mithril_common::test_utils::{MithrilFixtureBuilder, fake_data}; + use mithril_common::test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}; use crate::database::repository::{ProtocolInitializerRepository, StakePoolStore}; use crate::database::test_helper::main_db_connection; diff --git a/mithril-signer/src/services/signature_publisher/dmq.rs b/mithril-signer/src/services/signature_publisher/dmq.rs index bb1049fb13f..7d251efb78f 100644 --- a/mithril-signer/src/services/signature_publisher/dmq.rs +++ b/mithril-signer/src/services/signature_publisher/dmq.rs @@ -46,7 +46,7 @@ impl SignaturePublisher for SignaturePublisherDmq { #[cfg(test)] mod tests { - use mithril_common::test_utils::fake_data; + use mithril_common::test_utils::{double::Dummy, fake_data}; use mithril_dmq::test::double::DmqPublisherFake; use super::*; diff --git a/mithril-signer/tests/era_switch.rs b/mithril-signer/tests/era_switch.rs index a36b36ab3e3..70578005649 100644 --- a/mithril-signer/tests/era_switch.rs +++ b/mithril-signer/tests/era_switch.rs @@ -3,7 +3,7 @@ mod test_extensions; use mithril_common::{ crypto_helper::tests_setup, entities::{BlockNumber, ChainPoint, Epoch, SlotNumber, SupportedEra, TimePoint}, - test_utils::MithrilFixtureBuilder, + test_utils::{MithrilFixtureBuilder, double::Dummy}, }; use mithril_era::EraMarker; use test_extensions::StateMachineTester; diff --git a/mithril-signer/tests/test_extensions/certificate_handler.rs b/mithril-signer/tests/test_extensions/certificate_handler.rs index 6ad338b3f31..fb5a54903d5 100644 --- a/mithril-signer/tests/test_extensions/certificate_handler.rs +++ b/mithril-signer/tests/test_extensions/certificate_handler.rs @@ -10,7 +10,7 @@ use mithril_common::{ SignedEntityType, SignedEntityTypeDiscriminants, Signer, SingleSignature, TimePoint, }, messages::AggregatorFeaturesMessage, - test_utils::fake_data, + test_utils::{double::Dummy, fake_data}, }; use mithril_ticker::{MithrilTickerService, TickerService}; diff --git a/mithril-signer/tests/test_extensions/state_machine_tester.rs b/mithril-signer/tests/test_extensions/state_machine_tester.rs index e5871065f6a..a755eb716bd 100644 --- a/mithril-signer/tests/test_extensions/state_machine_tester.rs +++ b/mithril-signer/tests/test_extensions/state_machine_tester.rs @@ -39,6 +39,7 @@ use mithril_common::{ MithrilSignableBuilderService, MithrilStakeDistributionSignableBuilder, SignableBuilderServiceDependencies, }, + test_utils::double::Dummy, }; use mithril_era::{EraChecker, EraMarker, EraReader, adapters::EraReaderDummyAdapter}; use mithril_persistence::{