diff --git a/Cargo.lock b/Cargo.lock index 1f0e93d9428..ebac50e2060 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3928,7 +3928,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.7.75" +version = "0.7.76" dependencies = [ "anyhow", "async-trait", @@ -4009,7 +4009,7 @@ dependencies = [ [[package]] name = "mithril-api-spec" -version = "0.1.3" +version = "0.1.4" dependencies = [ "jsonschema", "mithril-common", @@ -4031,7 +4031,7 @@ dependencies = [ [[package]] name = "mithril-cardano-node-chain" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "async-trait", @@ -4059,7 +4059,7 @@ dependencies = [ [[package]] name = "mithril-cardano-node-internal-database" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "async-trait", @@ -4090,7 +4090,7 @@ dependencies = [ [[package]] name = "mithril-client" -version = "0.12.23" +version = "0.12.24" dependencies = [ "anyhow", "async-recursion", @@ -4128,7 +4128,7 @@ dependencies = [ [[package]] name = "mithril-client-cli" -version = "0.12.23" +version = "0.12.24" dependencies = [ "anyhow", "async-trait", @@ -4180,7 +4180,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.6.10" +version = "0.6.11" dependencies = [ "anyhow", "async-trait", @@ -4222,7 +4222,7 @@ dependencies = [ [[package]] name = "mithril-dmq" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "async-trait", @@ -4258,7 +4258,7 @@ dependencies = [ [[package]] name = "mithril-end-to-end" -version = "0.4.97" +version = "0.4.98" dependencies = [ "anyhow", "async-recursion", @@ -4281,7 +4281,7 @@ dependencies = [ [[package]] name = "mithril-era" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "async-trait", @@ -4295,7 +4295,7 @@ dependencies = [ [[package]] name = "mithril-metric" -version = "0.1.16" +version = "0.1.17" dependencies = [ "anyhow", "axum", @@ -4312,7 +4312,7 @@ dependencies = [ [[package]] name = "mithril-persistence" -version = "0.2.56" +version = "0.2.57" dependencies = [ "anyhow", "async-trait", @@ -4330,7 +4330,7 @@ dependencies = [ [[package]] name = "mithril-relay" -version = "0.1.48" +version = "0.1.49" dependencies = [ "anyhow", "clap", @@ -4374,7 +4374,7 @@ dependencies = [ [[package]] name = "mithril-signed-entity-preloader" -version = "0.0.8" +version = "0.0.9" dependencies = [ "anyhow", "async-trait", @@ -4390,7 +4390,7 @@ dependencies = [ [[package]] name = "mithril-signer" -version = "0.2.261" +version = "0.2.262" dependencies = [ "anyhow", "async-trait", diff --git a/internal/cardano-node/mithril-cardano-node-chain/Cargo.toml b/internal/cardano-node/mithril-cardano-node-chain/Cargo.toml index 2f1ea563933..70d4eeae3ac 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.5" +version = "0.1.6" authors.workspace = true documentation.workspace = true edition.workspace = true diff --git a/internal/cardano-node/mithril-cardano-node-chain/src/chain_observer/pallas_observer.rs b/internal/cardano-node/mithril-cardano-node-chain/src/chain_observer/pallas_observer.rs index 47505a3132d..e6983138d0e 100644 --- a/internal/cardano-node/mithril-cardano-node-chain/src/chain_observer/pallas_observer.rs +++ b/internal/cardano-node/mithril-cardano-node-chain/src/chain_observer/pallas_observer.rs @@ -529,7 +529,7 @@ mod tests { use tokio::net::UnixListener; use mithril_common::crypto_helper::ColdKeyGenerator; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use super::*; diff --git a/internal/cardano-node/mithril-cardano-node-chain/src/chain_reader/pallas_chain_reader.rs b/internal/cardano-node/mithril-cardano-node-chain/src/chain_reader/pallas_chain_reader.rs index 66f44941588..a1181162f55 100644 --- a/internal/cardano-node/mithril-cardano-node-chain/src/chain_reader/pallas_chain_reader.rs +++ b/internal/cardano-node/mithril-cardano-node-chain/src/chain_reader/pallas_chain_reader.rs @@ -160,7 +160,7 @@ mod tests { use std::fs; use tokio::net::UnixListener; - use mithril_common::{current_function, entities::BlockNumber, test_utils::TempDir}; + use mithril_common::{current_function, entities::BlockNumber, test::TempDir}; use crate::test::TestLogger; 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 0c671a5bc5e..803675aa78f 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::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; use super::*; diff --git a/internal/cardano-node/mithril-cardano-node-chain/src/test/mod.rs b/internal/cardano-node/mithril-cardano-node-chain/src/test/mod.rs index 67af92db201..33ec3bc3de9 100644 --- a/internal/cardano-node/mithril-cardano-node-chain/src/test/mod.rs +++ b/internal/cardano-node/mithril-cardano-node-chain/src/test/mod.rs @@ -9,21 +9,4 @@ pub mod double; pub(crate) mod test_cli_runner; #[cfg(test)] -pub(crate) struct TestLogger; - -#[cfg(test)] -impl TestLogger { - fn from_writer(writer: W) -> slog::Logger { - use slog::Drain; - use std::sync::Arc; - - let decorator = slog_term::PlainDecorator::new(writer); - let drain = slog_term::CompactFormat::new(decorator).build().fuse(); - let drain = slog_async::Async::new(drain).build().fuse(); - slog::Logger::root(Arc::new(drain), slog::o!()) - } - - pub(crate) fn stdout() -> slog::Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } -} +mithril_common::define_test_logger!(); diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml b/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml index 8e4436828ba..ba22abdd22e 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml +++ b/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-cardano-node-internal-database" -version = "0.1.2" +version = "0.1.3" description = "Mechanisms that allow Mithril nodes to read the files of a Cardano node internal database and compute digests from them" authors.workspace = true documentation.workspace = true diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider.rs b/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider.rs index 240f1c1cc6d..9c11a1a0632 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider.rs +++ b/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider.rs @@ -109,7 +109,7 @@ impl ImmutableFileDigestCacheProvider for JsonImmutableFileDigestCacheProvider { mod tests { use std::{collections::BTreeMap, path::PathBuf}; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use crate::digesters::cache::{ ImmutableFileDigestCacheProvider, JsonImmutableFileDigestCacheProvider, diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider_builder.rs b/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider_builder.rs index 9b317df8a09..561c277da06 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider_builder.rs +++ b/internal/cardano-node/mithril-cardano-node-internal-database/src/digesters/cache/json_provider_builder.rs @@ -86,7 +86,7 @@ impl<'a> JsonImmutableFileDigestCacheProviderBuilder<'a> { mod tests { use std::path::PathBuf; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use crate::digesters::cache::JsonImmutableFileDigestCacheProviderBuilder; diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs b/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs index 51ffdc734b5..09f9eed3c3e 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs +++ b/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs @@ -201,7 +201,7 @@ mod tests { use std::io::prelude::*; use mithril_common::temp_dir_create; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use super::*; diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/ledger_state_snapshot.rs b/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/ledger_state_snapshot.rs index f48b15a903d..4d995a8be5b 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/ledger_state_snapshot.rs +++ b/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/ledger_state_snapshot.rs @@ -191,7 +191,7 @@ mod tests { use std::fs::{File, create_dir}; use std::io::prelude::*; - use mithril_common::test_utils::temp_dir_create; + use mithril_common::test::temp_dir_create; use super::*; diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/src/test/mod.rs b/internal/cardano-node/mithril-cardano-node-internal-database/src/test/mod.rs index df456e81d81..4da2a80e34c 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/src/test/mod.rs +++ b/internal/cardano-node/mithril-cardano-node-internal-database/src/test/mod.rs @@ -11,21 +11,4 @@ pub mod fake_data; pub use dummy_cardano_db::{DummyCardanoDb, DummyCardanoDbBuilder}; #[cfg(test)] -pub(crate) struct TestLogger; - -#[cfg(test)] -impl TestLogger { - fn from_writer(writer: W) -> slog::Logger { - use slog::Drain; - use std::sync::Arc; - - let decorator = slog_term::PlainDecorator::new(writer); - let drain = slog_term::CompactFormat::new(decorator).build().fuse(); - let drain = slog_async::Async::new(drain).build().fuse(); - slog::Logger::root(Arc::new(drain), slog::o!()) - } - - pub(crate) fn stdout() -> slog::Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } -} +mithril_common::define_test_logger!(); diff --git a/internal/mithril-dmq/Cargo.toml b/internal/mithril-dmq/Cargo.toml index e660b212852..4e657f037f4 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.5" +version = "0.1.6" authors.workspace = true documentation.workspace = true edition.workspace = true diff --git a/internal/mithril-dmq/src/consumer/pallas.rs b/internal/mithril-dmq/src/consumer/pallas.rs index ef59e37c6eb..3bd75426379 100644 --- a/internal/mithril-dmq/src/consumer/pallas.rs +++ b/internal/mithril-dmq/src/consumer/pallas.rs @@ -144,14 +144,14 @@ mod tests { use std::{fs, future, time::Duration, vec}; - use mithril_common::{crypto_helper::TryToBytes, current_function, test_utils::TempDir}; + use mithril_common::{crypto_helper::TryToBytes, current_function, test::TempDir}; use pallas_network::{ facades::DmqServer, miniprotocols::{localmsgnotification, localmsgsubmission::DmqMsg}, }; use tokio::{net::UnixListener, task::JoinHandle, time::sleep}; - use crate::{test::payload::DmqMessageTestPayload, test_tools::TestLogger}; + use crate::test::{TestLogger, payload::DmqMessageTestPayload}; use super::*; diff --git a/internal/mithril-dmq/src/lib.rs b/internal/mithril-dmq/src/lib.rs index db7536fc64e..73549c74bac 100644 --- a/internal/mithril-dmq/src/lib.rs +++ b/internal/mithril-dmq/src/lib.rs @@ -9,28 +9,3 @@ pub mod test; pub use consumer::{DmqConsumer, DmqConsumerPallas}; pub use message::DmqMessageBuilder; pub use publisher::{DmqPublisher, DmqPublisherPallas}; - -#[cfg(test)] -pub(crate) mod test_tools { - use std::io; - use std::sync::Arc; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - pub struct TestLogger; - - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - } -} diff --git a/internal/mithril-dmq/src/message.rs b/internal/mithril-dmq/src/message.rs index 08de36ae2c0..79ad7589e96 100644 --- a/internal/mithril-dmq/src/message.rs +++ b/internal/mithril-dmq/src/message.rs @@ -92,9 +92,9 @@ impl DmqMessageBuilder { mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_common::{ - crypto_helper::{KesSignerFake, TryToBytes}, + crypto_helper::TryToBytes, entities::{BlockNumber, ChainPoint, TimePoint}, - test_utils::double::Dummy, + test::{crypto_helper::KesSignerFake, double::Dummy}, }; use super::*; diff --git a/internal/mithril-dmq/src/publisher/pallas.rs b/internal/mithril-dmq/src/publisher/pallas.rs index 55f8329584b..64fc089f098 100644 --- a/internal/mithril-dmq/src/publisher/pallas.rs +++ b/internal/mithril-dmq/src/publisher/pallas.rs @@ -91,12 +91,11 @@ mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_common::{ - crypto_helper::KesSignerFake, current_function, - test_utils::{TempDir, double::Dummy}, + test::{TempDir, crypto_helper::KesSignerFake, double::Dummy}, }; - use crate::{test::payload::DmqMessageTestPayload, test_tools::TestLogger}; + use crate::test::{TestLogger, payload::DmqMessageTestPayload}; use super::*; diff --git a/internal/mithril-dmq/src/test/mod.rs b/internal/mithril-dmq/src/test/mod.rs index a1d1c1930d9..77858983f2e 100644 --- a/internal/mithril-dmq/src/test/mod.rs +++ b/internal/mithril-dmq/src/test/mod.rs @@ -8,3 +8,6 @@ pub mod double; #[cfg(test)] pub(crate) mod payload; + +#[cfg(test)] +mithril_common::define_test_logger!(); diff --git a/internal/mithril-dmq/src/test/payload.rs b/internal/mithril-dmq/src/test/payload.rs index 6fd5098d515..d43b5b9d52f 100644 --- a/internal/mithril-dmq/src/test/payload.rs +++ b/internal/mithril-dmq/src/test/payload.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use mithril_common::{ StdResult, crypto_helper::{TryFromBytes, TryToBytes}, - test_utils::double::Dummy, + test::double::Dummy, }; /// A test message payload for the DMQ. diff --git a/internal/mithril-era/Cargo.toml b/internal/mithril-era/Cargo.toml index 17c9791ab17..aa6e6eb3e93 100644 --- a/internal/mithril-era/Cargo.toml +++ b/internal/mithril-era/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-era" -version = "0.1.3" +version = "0.1.4" 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 ca3b0c1e38f..11ac02ea7ca 100644 --- a/internal/mithril-era/src/adapters/bootstrap.rs +++ b/internal/mithril-era/src/adapters/bootstrap.rs @@ -22,7 +22,7 @@ impl EraReaderAdapter for BootstrapAdapter { #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/internal/mithril-era/src/adapters/dummy.rs b/internal/mithril-era/src/adapters/dummy.rs index 1968496a84e..6bfdda65844 100644 --- a/internal/mithril-era/src/adapters/dummy.rs +++ b/internal/mithril-era/src/adapters/dummy.rs @@ -40,7 +40,7 @@ impl EraReaderAdapter for DummyAdapter { #[cfg(test)] mod tests { use mithril_common::entities::{Epoch, SupportedEra}; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/internal/mithril-era/src/adapters/file.rs b/internal/mithril-era/src/adapters/file.rs index 4d4de67b093..746590ff12c 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, double::Dummy}; + use mithril_common::test::{TempDir, double::Dummy}; use super::*; diff --git a/internal/mithril-era/src/era_checker.rs b/internal/mithril-era/src/era_checker.rs index 828aae208da..92417325bde 100644 --- a/internal/mithril-era/src/era_checker.rs +++ b/internal/mithril-era/src/era_checker.rs @@ -55,7 +55,7 @@ impl ApiVersionDiscriminantSource for EraChecker { #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/internal/mithril-era/src/era_reader.rs b/internal/mithril-era/src/era_reader.rs index 691bf69390b..bdd673887f0 100644 --- a/internal/mithril-era/src/era_reader.rs +++ b/internal/mithril-era/src/era_reader.rs @@ -176,7 +176,7 @@ impl EraReader { #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::super::adapters::EraReaderDummyAdapter as DummyAdapter; use super::*; diff --git a/internal/mithril-metric/Cargo.toml b/internal/mithril-metric/Cargo.toml index 1b5fd4aac2a..9b531462bf2 100644 --- a/internal/mithril-metric/Cargo.toml +++ b/internal/mithril-metric/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-metric" -version = "0.1.16" +version = "0.1.17" description = "Common tools to expose metrics." authors = { workspace = true } edition = { workspace = true } diff --git a/internal/mithril-metric/src/helper.rs b/internal/mithril-metric/src/helper.rs index 979dd8ca768..5ca9b7eea2b 100644 --- a/internal/mithril-metric/src/helper.rs +++ b/internal/mithril-metric/src/helper.rs @@ -106,26 +106,7 @@ macro_rules! build_metrics_service { #[cfg(test)] pub(crate) mod test_tools { - use std::{io, sync::Arc}; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - pub struct TestLogger; - - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - } + mithril_common::define_test_logger!(); } #[cfg(test)] diff --git a/internal/mithril-persistence/Cargo.toml b/internal/mithril-persistence/Cargo.toml index 86648425e5f..b314733bbc1 100644 --- a/internal/mithril-persistence/Cargo.toml +++ b/internal/mithril-persistence/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-persistence" -version = "0.2.56" +version = "0.2.57" description = "Common types, interfaces, and utilities to persist data for Mithril nodes." authors = { workspace = true } edition = { workspace = true } diff --git a/internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs b/internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs index cec8b7b93f3..63e7cd37e4f 100644 --- a/internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs +++ b/internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs @@ -325,7 +325,7 @@ impl BlockRangeRootRetriever for CardanoTransactionRepositor #[cfg(test)] mod tests { - use mithril_common::test_utils::CardanoTransactionsBuilder; + use mithril_common::test::builder::CardanoTransactionsBuilder; use crate::database::query::GetBlockRangeRootQuery; use crate::database::test_helper::cardano_tx_db_connection; diff --git a/internal/mithril-persistence/src/database/version_checker.rs b/internal/mithril-persistence/src/database/version_checker.rs index 186e65f1c27..3e5f2ffe94e 100644 --- a/internal/mithril-persistence/src/database/version_checker.rs +++ b/internal/mithril-persistence/src/database/version_checker.rs @@ -269,7 +269,7 @@ impl Eq for SqlMigration {} #[cfg(test)] mod tests { use anyhow::Context; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use mithril_common::{StdResult, current_function}; use sqlite::{Connection, ConnectionThreadSafe}; use std::path::PathBuf; diff --git a/internal/mithril-persistence/src/sqlite/cleaner.rs b/internal/mithril-persistence/src/sqlite/cleaner.rs index 67586412331..19fc2ae0b1f 100644 --- a/internal/mithril-persistence/src/sqlite/cleaner.rs +++ b/internal/mithril-persistence/src/sqlite/cleaner.rs @@ -95,7 +95,7 @@ mod tests { use std::ops::Range; use std::path::Path; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use crate::sqlite::{ConnectionBuilder, ConnectionOptions, SqliteConnection}; diff --git a/internal/mithril-persistence/src/sqlite/connection_builder.rs b/internal/mithril-persistence/src/sqlite/connection_builder.rs index 77469157e6d..582142c7fb9 100644 --- a/internal/mithril-persistence/src/sqlite/connection_builder.rs +++ b/internal/mithril-persistence/src/sqlite/connection_builder.rs @@ -144,7 +144,7 @@ impl ConnectionBuilder { mod tests { use sqlite::Value; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use crate::sqlite::ConnectionOptions::ForceDisableForeignKeys; diff --git a/internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml b/internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml index eec113401e0..3b75ef97e53 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.8" +version = "0.0.9" 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 9cf2f04f759..f480ffeae5d 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,7 +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 mithril_common::test::double::Dummy; use crate::test_tools::TestLogger; diff --git a/internal/signed-entity/mithril-signed-entity-preloader/src/lib.rs b/internal/signed-entity/mithril-signed-entity-preloader/src/lib.rs index 70da053686e..18cb4e8bf18 100644 --- a/internal/signed-entity/mithril-signed-entity-preloader/src/lib.rs +++ b/internal/signed-entity/mithril-signed-entity-preloader/src/lib.rs @@ -9,25 +9,5 @@ pub use cardano_transactions_preloader::*; #[cfg(test)] pub(crate) mod test_tools { - use std::io; - use std::sync::Arc; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - pub struct TestLogger; - - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - } + mithril_common::define_test_logger!(); } diff --git a/internal/tests/mithril-api-spec/Cargo.toml b/internal/tests/mithril-api-spec/Cargo.toml index 113a2ba6687..b77d61e6237 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.3" +version = "0.1.4" 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 7f41cb3dcf4..fabe5ff99b0 100644 --- a/internal/tests/mithril-api-spec/src/apispec.rs +++ b/internal/tests/mithril-api-spec/src/apispec.rs @@ -343,7 +343,10 @@ mod tests { use mithril_common::entities; use mithril_common::messages::{AggregatorFeaturesMessage, SignerMessagePart}; - use mithril_common::test_utils::{TempDir, double::Dummy, fake_data}; + use mithril_common::test::{ + TempDir, + double::{Dummy, fake_data}, + }; use super::*; diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index fb6c02bd0a0..6e54759ea8f 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.7.75" +version = "0.7.76" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-aggregator/benches/cardano_transactions_get.rs b/mithril-aggregator/benches/cardano_transactions_get.rs index f7b3aa525be..ab1efa132bd 100644 --- a/mithril-aggregator/benches/cardano_transactions_get.rs +++ b/mithril-aggregator/benches/cardano_transactions_get.rs @@ -5,7 +5,7 @@ use sqlite::ConnectionThreadSafe; use mithril_aggregator::services::TransactionStore; use mithril_common::entities::{BlockNumber, CardanoTransaction, SlotNumber}; -use mithril_common::test_utils::TempDir; +use mithril_common::test::TempDir; use mithril_persistence::database::repository::CardanoTransactionRepository; use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnectionPool}; diff --git a/mithril-aggregator/benches/cardano_transactions_import.rs b/mithril-aggregator/benches/cardano_transactions_import.rs index a36af17452e..4e5a66d0472 100644 --- a/mithril-aggregator/benches/cardano_transactions_import.rs +++ b/mithril-aggregator/benches/cardano_transactions_import.rs @@ -3,7 +3,7 @@ use sqlite::ConnectionThreadSafe; use std::sync::Arc; use mithril_common::entities::{BlockNumber, CardanoTransaction, SlotNumber}; -use mithril_common::test_utils::TempDir; +use mithril_common::test::TempDir; use mithril_persistence::database::repository::CardanoTransactionRepository; use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnectionPool}; diff --git a/mithril-aggregator/src/artifact_builder/cardano_database.rs b/mithril-aggregator/src/artifact_builder/cardano_database.rs index cd4e66cf8b6..e09b76cc6c4 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database.rs @@ -112,7 +112,10 @@ mod tests { ImmutablesLocation, MultiFilesUri, ProtocolMessage, ProtocolMessagePartKey, TemplateUri, }, - test_utils::{TempDir, fake_data, fake_keys}, + test::{ + TempDir, + double::{fake_data, fake_keys}, + }, }; use crate::{ @@ -122,7 +125,7 @@ mod tests { immutable_file_digest_mapper::MockImmutableFileDigestMapper, services::CompressedArchiveSnapshotter, services::ancillary_signer::MockAncillarySigner, - test_tools::TestLogger, + test::TestLogger, tools::{file_archiver::FileArchiver, url_sanitizer::SanitizedUrlWithTrailingSlash}, }; 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 31a60961d92..c21a595a2fc 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs @@ -206,10 +206,10 @@ impl AncillaryArtifactBuilder { mod tests { use std::path::PathBuf; - use mithril_common::test_utils::{TempDir, assert_equivalent, double::Dummy}; + use mithril_common::test::{TempDir, assert_equivalent, double::Dummy}; use crate::services::{DumbSnapshotter, MockSnapshotter}; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; @@ -345,7 +345,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( locations, vec![AncillaryLocation::CloudStorage { uri: "an_uri".to_string(), @@ -385,7 +385,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( locations, vec![ AncillaryLocation::CloudStorage { 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 f63382bebd4..a16608d497c 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs @@ -299,12 +299,12 @@ mod tests { current_function, entities::{CardanoDbBeacon, CompressionAlgorithm}, messages::{CardanoDatabaseDigestListItemMessage, CardanoDatabaseDigestListMessage}, - test_utils::{TempDir, assert_equivalent, double::Dummy}, + test::{TempDir, assert_equivalent, double::Dummy}, }; use crate::{ file_uploaders::FileUploadRetryPolicy, - immutable_file_digest_mapper::MockImmutableFileDigestMapper, test_tools::TestLogger, + immutable_file_digest_mapper::MockImmutableFileDigestMapper, test::TestLogger, tools::file_archiver::FileArchiver, }; @@ -522,7 +522,7 @@ mod tests { let locations = builder.upload_digest_file(&FileArchive::dummy()).await.unwrap(); - assert_equivalent( + assert_equivalent!( locations, vec![ DigestLocation::CloudStorage { @@ -562,7 +562,7 @@ mod tests { let locations = builder.upload_digest_file(&FileArchive::dummy()).await.unwrap(); - assert_equivalent( + assert_equivalent!( locations, vec![ DigestLocation::CloudStorage { diff --git a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/immutable.rs b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/immutable.rs index 81874bc5708..5c7b3f9c3c5 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/immutable.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/immutable.rs @@ -281,12 +281,12 @@ mod tests { use mithril_cardano_node_internal_database::test::DummyCardanoDbBuilder; use mithril_common::{ entities::TemplateUri, - test_utils::{TempDir, assert_equivalent, equivalent_to}, + test::{TempDir, assert_equivalent, equivalent_to}, }; use crate::services::ancillary_signer::MockAncillarySigner; use crate::services::{CompressedArchiveSnapshotter, DumbSnapshotter, MockSnapshotter}; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use crate::tools::file_archiver::FileArchiver; use super::*; @@ -383,7 +383,7 @@ mod tests { let upload = builder.upload(2).await.unwrap(); - assert_equivalent( + assert_equivalent!( upload.locations, vec![ImmutablesLocation::CloudStorage { uri: MultiFilesUri::Template(TemplateUri("archive.tar.gz".to_string())), @@ -469,7 +469,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( archive_paths, vec![ work_dir.join("00000.tar.gz"), @@ -641,7 +641,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( archive_paths, vec![ work_dir.join("00000.tar.gz"), @@ -683,7 +683,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( archive_paths, vec![ work_dir.join("00000.tar.gz"), @@ -794,7 +794,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( archive_paths, vec![ImmutablesLocation::CloudStorage { uri: MultiFilesUri::Template(TemplateUri("archive_2.tar.gz".to_string())), @@ -836,7 +836,7 @@ mod tests { .await .unwrap(); - assert_equivalent( + assert_equivalent!( archive_paths, vec![ ImmutablesLocation::CloudStorage { @@ -853,7 +853,7 @@ mod tests { } mod batch_upload { - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use crate::file_uploaders::FileUploadRetryPolicy; use crate::tools::url_sanitizer::SanitizedUrlWithTrailingSlash; diff --git a/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs b/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs index a0b4aebd86b..d6602b121bd 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs @@ -206,11 +206,10 @@ mod tests { use anyhow::anyhow; use tempfile::NamedTempFile; - use mithril_common::{entities::CompressionAlgorithm, test_utils::fake_data}; + use mithril_common::{entities::CompressionAlgorithm, test::double::fake_data}; use crate::{ - DumbUploader, file_uploaders::MockFileUploader, services::DumbSnapshotter, - test_tools::TestLogger, + DumbUploader, file_uploaders::MockFileUploader, services::DumbSnapshotter, test::TestLogger, }; use super::*; diff --git a/mithril-aggregator/src/artifact_builder/cardano_stake_distribution.rs b/mithril-aggregator/src/artifact_builder/cardano_stake_distribution.rs index 305ba745c8a..f26253458a4 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_stake_distribution.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_stake_distribution.rs @@ -43,7 +43,7 @@ impl ArtifactBuilder for CardanoStakeDistributi #[cfg(test)] mod tests { - use mithril_common::{entities::StakeDistribution, test_utils::fake_data}; + use mithril_common::{entities::StakeDistribution, test::double::fake_data}; use mockall::{mock, predicate::eq}; use super::*; diff --git a/mithril-aggregator/src/artifact_builder/cardano_transactions.rs b/mithril-aggregator/src/artifact_builder/cardano_transactions.rs index d845efb57af..1aa5f823a86 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_transactions.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_transactions.rs @@ -58,7 +58,7 @@ impl ArtifactBuilder #[cfg(test)] mod tests { - use mithril_common::{entities::ProtocolMessage, test_utils::fake_data}; + use mithril_common::{entities::ProtocolMessage, test::double::fake_data}; use crate::services::MockProverService; diff --git a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs index a858d606135..3e703a70a8e 100644 --- a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs +++ b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs @@ -40,7 +40,7 @@ impl ArtifactBuilder for MithrilStakeDistributi mod tests { use mithril_common::{ crypto_helper::ProtocolParameters, - test_utils::{double::Dummy, fake_data}, + test::double::{Dummy, fake_data}, }; use std::sync::Arc; use tokio::sync::RwLock; diff --git a/mithril-aggregator/src/commands/config_association.rs b/mithril-aggregator/src/commands/config_association.rs index 3a94d759711..22e0dccd1c6 100644 --- a/mithril-aggregator/src/commands/config_association.rs +++ b/mithril-aggregator/src/commands/config_association.rs @@ -73,7 +73,7 @@ macro_rules! extract_all { mod tests { use std::collections::HashMap; - use mithril_common::assert_equivalent_macro; + use mithril_common::assert_equivalent; use mithril_doc::StructDoc; #[allow(dead_code)] @@ -167,7 +167,7 @@ mod tests { "mithril commande subcommande".to_string(), ]; - assert_equivalent_macro!(expected, keys); + assert_equivalent!(expected, keys); } #[test] diff --git a/mithril-aggregator/src/commands/database_command.rs b/mithril-aggregator/src/commands/database_command.rs index abd2d0d4013..dd807c9e40f 100644 --- a/mithril-aggregator/src/commands/database_command.rs +++ b/mithril-aggregator/src/commands/database_command.rs @@ -189,7 +189,7 @@ mod tests { use mithril_common::temp_dir; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/commands/genesis_command.rs b/mithril-aggregator/src/commands/genesis_command.rs index d4054adf202..dff8fe35dff 100644 --- a/mithril-aggregator/src/commands/genesis_command.rs +++ b/mithril-aggregator/src/commands/genesis_command.rs @@ -368,7 +368,7 @@ mod tests { use mithril_common::temp_dir; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/commands/tools_command.rs b/mithril-aggregator/src/commands/tools_command.rs index ba87c89f56a..d8df52b5bc9 100644 --- a/mithril-aggregator/src/commands/tools_command.rs +++ b/mithril-aggregator/src/commands/tools_command.rs @@ -140,7 +140,7 @@ mod tests { use mithril_common::temp_dir; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/database/query/certificate/get_certificate.rs b/mithril-aggregator/src/database/query/certificate/get_certificate.rs index 8808cd57218..f3343da48b5 100644 --- a/mithril-aggregator/src/database/query/certificate/get_certificate.rs +++ b/mithril-aggregator/src/database/query/certificate/get_certificate.rs @@ -60,8 +60,8 @@ impl Query for GetCertificateRecordQuery { #[cfg(test)] mod tests { use mithril_common::crypto_helper::ProtocolParameters; - use mithril_common::crypto_helper::tests_setup::setup_certificate_chain; - use mithril_common::test_utils::CertificateChainBuilder; + use mithril_common::test::builder::CertificateChainBuilder; + use mithril_common::test::crypto_helper::setup_certificate_chain; use mithril_persistence::sqlite::ConnectionExtensions; diff --git a/mithril-aggregator/src/database/query/certificate/insert_certificate.rs b/mithril-aggregator/src/database/query/certificate/insert_certificate.rs index 381e0321e23..93d49eba4ce 100644 --- a/mithril-aggregator/src/database/query/certificate/insert_certificate.rs +++ b/mithril-aggregator/src/database/query/certificate/insert_certificate.rs @@ -40,7 +40,7 @@ impl Query for InsertCertificateRecordQuery { #[cfg(test)] mod tests { - use mithril_common::crypto_helper::tests_setup::setup_certificate_chain; + use mithril_common::test::crypto_helper::setup_certificate_chain; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::test_helper::main_db_connection; diff --git a/mithril-aggregator/src/database/query/certificate/insert_or_replace_certificate.rs b/mithril-aggregator/src/database/query/certificate/insert_or_replace_certificate.rs index fa34bb91588..e604f165286 100644 --- a/mithril-aggregator/src/database/query/certificate/insert_or_replace_certificate.rs +++ b/mithril-aggregator/src/database/query/certificate/insert_or_replace_certificate.rs @@ -38,9 +38,8 @@ impl Query for InsertOrReplaceCertificateRecordQuery { mod tests { use std::collections::HashMap; - use mithril_common::crypto_helper::tests_setup::setup_certificate_chain; use mithril_common::entities::Epoch; - use mithril_common::test_utils::fake_data; + use mithril_common::test::{crypto_helper::setup_certificate_chain, double::fake_data}; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::query::{GetCertificateRecordQuery, InsertCertificateRecordQuery}; diff --git a/mithril-aggregator/src/database/query/epoch_settings/get_epoch_settings.rs b/mithril-aggregator/src/database/query/epoch_settings/get_epoch_settings.rs index 95194f4038c..670f623e114 100644 --- a/mithril-aggregator/src/database/query/epoch_settings/get_epoch_settings.rs +++ b/mithril-aggregator/src/database/query/epoch_settings/get_epoch_settings.rs @@ -69,7 +69,10 @@ mod tests { ); assert_eq!( - CardanoTransactionsSigningConfig::new(BlockNumber(10), BlockNumber(15)), + CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(10), + step: BlockNumber(15) + }, epoch_settings_record.cardano_transactions_signing_config ); diff --git a/mithril-aggregator/src/database/query/epoch_settings/update_epoch_settings.rs b/mithril-aggregator/src/database/query/epoch_settings/update_epoch_settings.rs index 534fc1f63ec..d21c1312059 100644 --- a/mithril-aggregator/src/database/query/epoch_settings/update_epoch_settings.rs +++ b/mithril-aggregator/src/database/query/epoch_settings/update_epoch_settings.rs @@ -53,7 +53,7 @@ impl Query for UpdateEpochSettingsQuery { #[cfg(test)] mod tests { use mithril_common::entities::{BlockNumber, CardanoTransactionsSigningConfig}; - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::query::GetEpochSettingsQuery; @@ -68,10 +68,10 @@ mod tests { let epoch_settings_send_to_update = AggregatorEpochSettings { protocol_parameters: fake_data::protocol_parameters(), - cardano_transactions_signing_config: CardanoTransactionsSigningConfig::new( - BlockNumber(24), - BlockNumber(62), - ), + cardano_transactions_signing_config: CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(24), + step: BlockNumber(62), + }, }; let record_returned_by_update_query = connection .fetch_first(UpdateEpochSettingsQuery::one( 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 b5f35588ba3..3fc3158f4fa 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,7 +34,7 @@ impl Query for InsertOrReplaceOpenMessageQuery { #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::query::GetOpenMessageQuery; diff --git a/mithril-aggregator/src/database/query/signed_entity/get_signed_entity.rs b/mithril-aggregator/src/database/query/signed_entity/get_signed_entity.rs index 088ead61920..99f25dcfe00 100644 --- a/mithril-aggregator/src/database/query/signed_entity/get_signed_entity.rs +++ b/mithril-aggregator/src/database/query/signed_entity/get_signed_entity.rs @@ -96,7 +96,7 @@ mod tests { use chrono::DateTime; use mithril_common::{ entities::{CardanoDbBeacon, SignedEntityType}, - test_utils::fake_data, + test::double::fake_data, }; use mithril_persistence::sqlite::ConnectionExtensions; use sqlite::ConnectionThreadSafe; diff --git a/mithril-aggregator/src/database/query/signer_registration/get_signer_registration.rs b/mithril-aggregator/src/database/query/signer_registration/get_signer_registration.rs index d5b66ea2ec0..190622e74ce 100644 --- a/mithril-aggregator/src/database/query/signer_registration/get_signer_registration.rs +++ b/mithril-aggregator/src/database/query/signer_registration/get_signer_registration.rs @@ -59,7 +59,7 @@ mod tests { use chrono::{DateTime, Utc}; use mithril_common::entities::SignerWithStake; - use mithril_common::test_utils::MithrilFixtureBuilder; + use mithril_common::test::builder::MithrilFixtureBuilder; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::test_helper::{insert_signer_registrations, main_db_connection}; diff --git a/mithril-aggregator/src/database/query/signer_registration/insert_or_replace_signer_registration.rs b/mithril-aggregator/src/database/query/signer_registration/insert_or_replace_signer_registration.rs index 916a0154016..bebc696f8e7 100644 --- a/mithril-aggregator/src/database/query/signer_registration/insert_or_replace_signer_registration.rs +++ b/mithril-aggregator/src/database/query/signer_registration/insert_or_replace_signer_registration.rs @@ -63,7 +63,7 @@ impl Query for InsertOrReplaceSignerRegistrationRecordQuery { #[cfg(test)] mod tests { use mithril_common::entities::Epoch; - use mithril_common::test_utils::MithrilFixtureBuilder; + use mithril_common::test::builder::MithrilFixtureBuilder; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::test_helper::main_db_connection; diff --git a/mithril-aggregator/src/database/record/buffered_single_signature_record.rs b/mithril-aggregator/src/database/record/buffered_single_signature_record.rs index 89843cb3ea8..6a302464145 100644 --- a/mithril-aggregator/src/database/record/buffered_single_signature_record.rs +++ b/mithril-aggregator/src/database/record/buffered_single_signature_record.rs @@ -3,7 +3,10 @@ use chrono::{DateTime, Utc}; use mithril_common::entities::{ HexEncodedSingleSignature, LotteryIndex, SignedEntityTypeDiscriminants, SingleSignature, }; +#[cfg(test)] +use mithril_common::test::entities_extensions::SingleSignatureTestExtension; use mithril_common::{StdError, StdResult}; + use mithril_persistence::sqlite::{HydrationError, Projection, SqLiteEntity}; /// `BufferedSingleSignatureRecord` record is the representation of a buffered single_signature @@ -176,7 +179,7 @@ mod tests { use mithril_common::entities::SignedEntityTypeDiscriminants::{ CardanoTransactions, MithrilStakeDistribution, }; - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-aggregator/src/database/record/certificate.rs b/mithril-aggregator/src/database/record/certificate.rs index 493c91b747e..e6f517565c9 100644 --- a/mithril-aggregator/src/database/record/certificate.rs +++ b/mithril-aggregator/src/database/record/certificate.rs @@ -12,7 +12,7 @@ use mithril_common::messages::{ #[cfg(test)] use mithril_common::{ entities::{CardanoDbBeacon, ImmutableFileNumber}, - test_utils::{fake_data, fake_keys}, + test::double::{fake_data, fake_keys}, }; use mithril_persistence::{ database::Hydrator, @@ -384,7 +384,7 @@ impl SqLiteEntity for CertificateRecord { #[cfg(test)] mod tests { - use mithril_common::crypto_helper::tests_setup::setup_certificate_chain; + use mithril_common::test::crypto_helper::setup_certificate_chain; use super::*; diff --git a/mithril-aggregator/src/database/record/signed_entity.rs b/mithril-aggregator/src/database/record/signed_entity.rs index 3ea224a5477..76f3a4af294 100644 --- a/mithril-aggregator/src/database/record/signed_entity.rs +++ b/mithril-aggregator/src/database/record/signed_entity.rs @@ -101,7 +101,7 @@ impl SignedEntityRecord { } pub(crate) fn fake_records(number_if_records: usize) -> Vec { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; let snapshots = fake_data::snapshots(number_if_records as u64); (0..number_if_records) @@ -435,7 +435,7 @@ impl SqLiteEntity for SignedEntityRecord { #[cfg(test)] mod tests { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-aggregator/src/database/record/signer_registration.rs b/mithril-aggregator/src/database/record/signer_registration.rs index 275e40b78ff..6e72169a167 100644 --- a/mithril-aggregator/src/database/record/signer_registration.rs +++ b/mithril-aggregator/src/database/record/signer_registration.rs @@ -172,7 +172,7 @@ impl SqLiteEntity for SignerRegistrationRecord { #[cfg(test)] mod tests { - use mithril_common::test_utils::MithrilFixtureBuilder; + use mithril_common::test::builder::MithrilFixtureBuilder; use super::*; diff --git a/mithril-aggregator/src/database/record/single_signature.rs b/mithril-aggregator/src/database/record/single_signature.rs index 5484b3c140e..6fc03592463 100644 --- a/mithril-aggregator/src/database/record/single_signature.rs +++ b/mithril-aggregator/src/database/record/single_signature.rs @@ -133,7 +133,7 @@ impl SqLiteEntity for SingleSignatureRecord { #[cfg(test)] mod tests { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-aggregator/src/database/repository/buffered_single_signature_repository.rs b/mithril-aggregator/src/database/repository/buffered_single_signature_repository.rs index eff564bad60..dcc49c3ae74 100644 --- a/mithril-aggregator/src/database/repository/buffered_single_signature_repository.rs +++ b/mithril-aggregator/src/database/repository/buffered_single_signature_repository.rs @@ -104,7 +104,7 @@ mod tests { use mithril_common::entities::SignedEntityTypeDiscriminants::{ CardanoTransactions, MithrilStakeDistribution, }; - use mithril_common::test_utils::fake_keys; + use mithril_common::test::double::fake_keys; use crate::database::record::{BufferedSingleSignatureRecord, strip_buffered_sigs_date}; use crate::database::test_helper::{insert_buffered_single_signatures, main_db_connection}; diff --git a/mithril-aggregator/src/database/repository/certificate_repository.rs b/mithril-aggregator/src/database/repository/certificate_repository.rs index ebb985ee5a3..f1d2c4572f5 100644 --- a/mithril-aggregator/src/database/repository/certificate_repository.rs +++ b/mithril-aggregator/src/database/repository/certificate_repository.rs @@ -164,7 +164,7 @@ impl SynchronizedCertificateStorer for CertificateRepository { #[cfg(test)] mod tests { - use mithril_common::crypto_helper::tests_setup::setup_certificate_chain; + use mithril_common::test::crypto_helper::setup_certificate_chain; use crate::database::test_helper::{insert_certificate_records, main_db_connection}; diff --git a/mithril-aggregator/src/database/repository/epoch_settings_store.rs b/mithril-aggregator/src/database/repository/epoch_settings_store.rs index 1a32f54947d..8949657149a 100644 --- a/mithril-aggregator/src/database/repository/epoch_settings_store.rs +++ b/mithril-aggregator/src/database/repository/epoch_settings_store.rs @@ -92,7 +92,7 @@ impl EpochPruningTask for EpochSettingsStore { #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use crate::database::test_helper::{insert_epoch_settings, main_db_connection}; diff --git a/mithril-aggregator/src/database/repository/immutable_file_digest_repository.rs b/mithril-aggregator/src/database/repository/immutable_file_digest_repository.rs index bd1e9742220..2811b370f4f 100644 --- a/mithril-aggregator/src/database/repository/immutable_file_digest_repository.rs +++ b/mithril-aggregator/src/database/repository/immutable_file_digest_repository.rs @@ -139,7 +139,7 @@ mod tests { } mod repository { - use mithril_common::test_utils::assert_equivalent; + use mithril_common::test::assert_equivalent; use super::*; @@ -191,7 +191,7 @@ mod tests { let all_immutable_file_digests = repository.get_all_immutable_file_digest().await.unwrap(); - assert_equivalent( + assert_equivalent!( vec![ ImmutableFileDigestRecord { immutable_file_name: "123.chunk".to_string(), diff --git a/mithril-aggregator/src/database/repository/open_message_repository.rs b/mithril-aggregator/src/database/repository/open_message_repository.rs index 0d6aa6a2ba6..eb51730f466 100644 --- a/mithril-aggregator/src/database/repository/open_message_repository.rs +++ b/mithril-aggregator/src/database/repository/open_message_repository.rs @@ -140,7 +140,7 @@ impl OpenMessageStorer for OpenMessageRepository { #[cfg(test)] mod tests { use mithril_common::entities::{BlockNumber, CardanoDbBeacon}; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use crate::database::record::SingleSignatureRecord; use crate::database::test_helper::{ diff --git a/mithril-aggregator/src/database/repository/signed_entity_store.rs b/mithril-aggregator/src/database/repository/signed_entity_store.rs index 202ff163836..72bdd8229df 100644 --- a/mithril-aggregator/src/database/repository/signed_entity_store.rs +++ b/mithril-aggregator/src/database/repository/signed_entity_store.rs @@ -166,7 +166,7 @@ mod tests { use mithril_common::{ entities::{Epoch, MithrilStakeDistribution, Snapshot}, signable_builder::SignedEntity, - test_utils::fake_data, + test::double::fake_data, }; use crate::database::test_helper::{insert_signed_entities, main_db_connection}; diff --git a/mithril-aggregator/src/database/repository/signer_registration_store.rs b/mithril-aggregator/src/database/repository/signer_registration_store.rs index 05ddd590395..a74e31ee299 100644 --- a/mithril-aggregator/src/database/repository/signer_registration_store.rs +++ b/mithril-aggregator/src/database/repository/signer_registration_store.rs @@ -142,7 +142,7 @@ mod tests { use crate::database::test_helper::{insert_signer_registrations, main_db_connection}; use mithril_common::entities::{Epoch, PartyId, Signer, SignerWithStake}; - use mithril_common::test_utils::fake_keys; + use mithril_common::test::double::fake_keys; use std::collections::HashMap; use std::sync::Arc; diff --git a/mithril-aggregator/src/database/test_helper.rs b/mithril-aggregator/src/database/test_helper.rs index 19f072b7bd1..9d3ed820bc4 100644 --- a/mithril-aggregator/src/database/test_helper.rs +++ b/mithril-aggregator/src/database/test_helper.rs @@ -6,7 +6,7 @@ use uuid::Uuid; use mithril_common::entities::{ BlockNumber, CardanoTransactionsSigningConfig, ProtocolParameters, SignerWithStake, }; -use mithril_common::{StdError, StdResult, entities::Epoch, test_utils::fake_keys}; +use mithril_common::{StdError, StdResult, entities::Epoch, test::double::fake_keys}; use mithril_persistence::sqlite::{ ConnectionBuilder, ConnectionExtensions, ConnectionOptions, Query, SqliteConnection, }; @@ -205,10 +205,10 @@ pub fn insert_epoch_settings( Epoch(1), AggregatorEpochSettings { protocol_parameters: ProtocolParameters::new(1, 2, 1.0), - cardano_transactions_signing_config: CardanoTransactionsSigningConfig::new( - BlockNumber(0), - BlockNumber(0), - ), + cardano_transactions_signing_config: CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(0), + step: BlockNumber(0), + }, }, ) .filters() @@ -222,7 +222,10 @@ pub fn insert_epoch_settings( ( epoch, ProtocolParameters::new(*epoch, epoch + 1, 1.0), - CardanoTransactionsSigningConfig::new(BlockNumber(epoch * 10), BlockNumber(15)), + CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(epoch * 10), + step: BlockNumber(15), + }, ) }) { diff --git a/mithril-aggregator/src/dependency_injection/builder/mod.rs b/mithril-aggregator/src/dependency_injection/builder/mod.rs index d14398c7d1d..bb0a6499654 100644 --- a/mithril-aggregator/src/dependency_injection/builder/mod.rs +++ b/mithril-aggregator/src/dependency_injection/builder/mod.rs @@ -526,6 +526,6 @@ impl DependenciesBuilder { #[cfg(test)] impl DependenciesBuilder { pub(crate) fn new_with_stdout_logger(configuration: Arc) -> Self { - Self::new(crate::test_tools::TestLogger::stdout(), configuration) + Self::new(crate::test::TestLogger::stdout(), configuration) } } diff --git a/mithril-aggregator/src/dependency_injection/containers/serve.rs b/mithril-aggregator/src/dependency_injection/containers/serve.rs index 000902c84ca..b37d783aad5 100644 --- a/mithril-aggregator/src/dependency_injection/containers/serve.rs +++ b/mithril-aggregator/src/dependency_injection/containers/serve.rs @@ -10,7 +10,7 @@ use mithril_common::{ StakeDistribution, }, signable_builder::SignableBuilderService, - test_utils::MithrilFixture, + test::builder::MithrilFixture, }; use mithril_era::{EraChecker, EraReader}; diff --git a/mithril-aggregator/src/entities/open_message.rs b/mithril-aggregator/src/entities/open_message.rs index 453755dd71f..4f4ae482875 100644 --- a/mithril-aggregator/src/entities/open_message.rs +++ b/mithril-aggregator/src/entities/open_message.rs @@ -85,7 +85,7 @@ mod test { use mithril_common::{ entities::{Epoch, ProtocolMessage, SignedEntityType}, - test_utils::{double::Dummy, fake_data}, + test::double::{Dummy, fake_data}, }; use crate::database::record::{OpenMessageRecord, OpenMessageWithSingleSignaturesRecord}; diff --git a/mithril-aggregator/src/event_store/database/repository.rs b/mithril-aggregator/src/event_store/database/repository.rs index 370e3bed624..22346b0f260 100644 --- a/mithril-aggregator/src/event_store/database/repository.rs +++ b/mithril-aggregator/src/event_store/database/repository.rs @@ -437,7 +437,7 @@ mod tests { use crate::event_store::database::test_helper::event_store_db_connection; use mithril_common::entities::{SignerWithStake, Stake}; - use mithril_common::{StdResult, test_utils::fake_data}; + use mithril_common::{StdResult, test::double::fake_data}; use sqlite::ConnectionThreadSafe; use super::{EventMessage, EventPersister}; diff --git a/mithril-aggregator/src/file_uploaders/local_uploader.rs b/mithril-aggregator/src/file_uploaders/local_uploader.rs index 54f023d3687..a62eb48da12 100644 --- a/mithril-aggregator/src/file_uploaders/local_uploader.rs +++ b/mithril-aggregator/src/file_uploaders/local_uploader.rs @@ -92,9 +92,9 @@ mod tests { use std::path::{Path, PathBuf}; use std::time::Duration; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; 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 60f782a476f..6e1f5301b70 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,7 +182,7 @@ mod tests { CardanoDatabaseDigestListItemMessage, CardanoDatabaseSnapshotListItemMessage, CardanoDatabaseSnapshotMessage, }; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::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 f4e2f34d4aa..2867cbb0174 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,7 +170,7 @@ pub mod tests { use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::{CardanoStakeDistributionListItemMessage, CardanoStakeDistributionMessage}, - test_utils::double::Dummy, + test::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 a5c254d5679..60dcd0b3568 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,7 +108,7 @@ pub mod tests { use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::{CardanoTransactionSnapshotListItemMessage, CardanoTransactionSnapshotMessage}, - test_utils::double::Dummy, + test::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 7dfedbf533b..89b46b0861e 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,7 +108,7 @@ pub mod tests { use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::{MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage}, - test_utils::double::Dummy, + test::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 bb6c6c2f570..5b90e4d23db 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::{double::Dummy, fake_data}, + test::double::{Dummy, fake_data}, }; use mithril_persistence::sqlite::HydrationError; diff --git a/mithril-aggregator/src/http_server/routes/certificate_routes.rs b/mithril-aggregator/src/http_server/routes/certificate_routes.rs index d9bf9aca7d1..a8678174f06 100644 --- a/mithril-aggregator/src/http_server/routes/certificate_routes.rs +++ b/mithril-aggregator/src/http_server/routes/certificate_routes.rs @@ -140,7 +140,7 @@ mod tests { use mithril_api_spec::APISpec; use mithril_common::{ MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, messages::CertificateMessage, - test_utils::fake_data, + test::double::fake_data, }; use crate::{initialize_dependencies, services::MockMessageService}; diff --git a/mithril-aggregator/src/http_server/routes/epoch_routes.rs b/mithril-aggregator/src/http_server/routes/epoch_routes.rs index 2cb525a90e7..52f6cca873e 100644 --- a/mithril-aggregator/src/http_server/routes/epoch_routes.rs +++ b/mithril-aggregator/src/http_server/routes/epoch_routes.rs @@ -67,7 +67,7 @@ mod tests { use mithril_api_spec::APISpec; use mithril_common::messages::EpochSettingsMessage; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::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 5dde0112d0e..85c3aa0eae9 100644 --- a/mithril-aggregator/src/http_server/routes/middlewares.rs +++ b/mithril-aggregator/src/http_server/routes/middlewares.rs @@ -218,7 +218,7 @@ mod tests { test::request, }; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use crate::http_server::routes::reply; use crate::initialize_dependencies; diff --git a/mithril-aggregator/src/http_server/routes/proof_routes.rs b/mithril-aggregator/src/http_server/routes/proof_routes.rs index 293feb79a46..6289fb6959b 100644 --- a/mithril-aggregator/src/http_server/routes/proof_routes.rs +++ b/mithril-aggregator/src/http_server/routes/proof_routes.rs @@ -164,7 +164,10 @@ mod tests { MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, entities::{BlockNumber, CardanoTransactionsSetProof, CardanoTransactionsSnapshot}, signable_builder::SignedEntity, - test_utils::{assert_equivalent, double::Dummy, fake_data}, + test::{ + assert_equivalent, + double::{Dummy, fake_data}, + }, }; use crate::services::MockProverService; @@ -440,6 +443,6 @@ mod tests { transaction_hashes: format!("{tx1},{tx2},{tx2},{tx1},{tx2}",), }; - assert_equivalent(params.sanitize(), vec![tx1, tx2]); + assert_equivalent!(params.sanitize(), vec![tx1, tx2]); } } diff --git a/mithril-aggregator/src/http_server/routes/root_routes.rs b/mithril-aggregator/src/http_server/routes/root_routes.rs index 3dbf68f5da8..c5ca9954c28 100644 --- a/mithril-aggregator/src/http_server/routes/root_routes.rs +++ b/mithril-aggregator/src/http_server/routes/root_routes.rs @@ -91,7 +91,7 @@ mod tests { use mithril_common::messages::{ AggregatorCapabilities, AggregatorFeaturesMessage, CardanoTransactionsProverCapabilities, }; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::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 1eb45116364..e19d92585bc 100644 --- a/mithril-aggregator/src/http_server/routes/router.rs +++ b/mithril-aggregator/src/http_server/routes/router.rs @@ -9,7 +9,7 @@ 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::test::double::Dummy; use mithril_common::{ CardanoNetwork, MITHRIL_API_VERSION_HEADER, MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, diff --git a/mithril-aggregator/src/http_server/routes/signatures_routes.rs b/mithril-aggregator/src/http_server/routes/signatures_routes.rs index d4153aab547..87b9e31dfe4 100644 --- a/mithril-aggregator/src/http_server/routes/signatures_routes.rs +++ b/mithril-aggregator/src/http_server/routes/signatures_routes.rs @@ -127,8 +127,7 @@ mod tests { use mithril_api_spec::APISpec; use mithril_common::{ - entities::SignedEntityType, messages::RegisterSignatureMessageHttp, - test_utils::double::Dummy, + entities::SignedEntityType, messages::RegisterSignatureMessageHttp, test::double::Dummy, }; use crate::{ diff --git a/mithril-aggregator/src/http_server/routes/signer_routes.rs b/mithril-aggregator/src/http_server/routes/signer_routes.rs index 9bdea379c17..233ddb1e113 100644 --- a/mithril-aggregator/src/http_server/routes/signer_routes.rs +++ b/mithril-aggregator/src/http_server/routes/signer_routes.rs @@ -271,7 +271,10 @@ mod tests { crypto_helper::ProtocolRegistrationError, entities::Epoch, messages::RegisterSignerMessage, - test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, + test::{ + builder::MithrilFixtureBuilder, + double::{Dummy, fake_data}, + }, }; use crate::{ @@ -281,7 +284,7 @@ mod tests { initialize_dependencies, services::{FakeEpochService, MockSignerRegisterer}, store::MockVerificationKeyStorer, - test_tools::TestLogger, + test::TestLogger, }; use super::*; diff --git a/mithril-aggregator/src/http_server/routes/statistics_routes.rs b/mithril-aggregator/src/http_server/routes/statistics_routes.rs index 7a3d7ed3b2c..1d79e5574bf 100644 --- a/mithril-aggregator/src/http_server/routes/statistics_routes.rs +++ b/mithril-aggregator/src/http_server/routes/statistics_routes.rs @@ -233,7 +233,7 @@ mod tests { CardanoDatabaseImmutableFilesRestoredMessage, SnapshotDownloadMessage, }; use mithril_common::{ - MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, temp_dir, test_utils::double::Dummy, + MITHRIL_CLIENT_TYPE_HEADER, MITHRIL_ORIGIN_TAG_HEADER, temp_dir, test::double::Dummy, }; use crate::ServeCommandDependenciesContainer; diff --git a/mithril-aggregator/src/http_server/routes/status.rs b/mithril-aggregator/src/http_server/routes/status.rs index 9092c882067..c379d7a3d24 100644 --- a/mithril-aggregator/src/http_server/routes/status.rs +++ b/mithril-aggregator/src/http_server/routes/status.rs @@ -115,7 +115,10 @@ mod tests { use mithril_api_spec::APISpec; use mithril_common::{ entities::{Epoch, ProtocolParameters, Stake}, - test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, + test::{ + builder::MithrilFixtureBuilder, + double::{Dummy, fake_data}, + }, }; use crate::{ diff --git a/mithril-aggregator/src/lib.rs b/mithril-aggregator/src/lib.rs index e1d0fe37b65..7d9909bff76 100644 --- a/mithril-aggregator/src/lib.rs +++ b/mithril-aggregator/src/lib.rs @@ -69,35 +69,3 @@ use tikv_jemallocator::Jemalloc; #[cfg(all(not(target_env = "msvc"), feature = "jemallocator"))] #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; - -#[cfg(test)] -pub(crate) mod test_tools { - use std::io; - use std::sync::Arc; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - use mithril_common::test_utils::{MemoryDrainForTest, MemoryDrainForTestInspector}; - - pub struct TestLogger; - - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - - pub fn memory() -> (Logger, MemoryDrainForTestInspector) { - let (drain, inspector) = MemoryDrainForTest::new(); - (Logger::root(drain.fuse(), slog::o!()), inspector) - } - } -} diff --git a/mithril-aggregator/src/message_adapters/from_epoch_settings.rs b/mithril-aggregator/src/message_adapters/from_epoch_settings.rs index f3fb7d2410b..685a45fe691 100644 --- a/mithril-aggregator/src/message_adapters/from_epoch_settings.rs +++ b/mithril-aggregator/src/message_adapters/from_epoch_settings.rs @@ -32,7 +32,7 @@ impl TryFromMessageAdapter #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/mithril-aggregator/src/message_adapters/from_register_signature.rs b/mithril-aggregator/src/message_adapters/from_register_signature.rs index 6b232f4747b..7b948484ac5 100644 --- a/mithril-aggregator/src/message_adapters/from_register_signature.rs +++ b/mithril-aggregator/src/message_adapters/from_register_signature.rs @@ -28,7 +28,7 @@ impl TryFromMessageAdapter #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/mithril-aggregator/src/message_adapters/from_register_signer.rs b/mithril-aggregator/src/message_adapters/from_register_signer.rs index 5694d8dc868..47bb2d5995c 100644 --- a/mithril-aggregator/src/message_adapters/from_register_signer.rs +++ b/mithril-aggregator/src/message_adapters/from_register_signer.rs @@ -39,7 +39,7 @@ impl TryFromMessageAdapter for FromRegisterSigner #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; 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 518debb414a..2907ffea8b9 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,7 +60,8 @@ fn try_adapt_set_proof_message( #[cfg(test)] mod tests { use mithril_common::crypto_helper::MKProof; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::crypto_helper::MKProofTestExtension; + use mithril_common::test::double::Dummy; use super::*; diff --git a/mithril-aggregator/src/metrics/service.rs b/mithril-aggregator/src/metrics/service.rs index 755faad0696..1517e487e65 100644 --- a/mithril-aggregator/src/metrics/service.rs +++ b/mithril-aggregator/src/metrics/service.rs @@ -198,7 +198,7 @@ impl Default for MetricLabelValueMap { #[cfg(test)] mod tests { - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/multi_signer.rs b/mithril-aggregator/src/multi_signer.rs index a65ec518918..44e81c74472 100644 --- a/mithril-aggregator/src/multi_signer.rs +++ b/mithril-aggregator/src/multi_signer.rs @@ -143,14 +143,17 @@ mod tests { use std::sync::Arc; use tokio::sync::RwLock; - 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, double::Dummy, fake_data}; + use mithril_common::test::{ + builder::MithrilFixtureBuilder, + crypto_helper::setup_message, + double::{Dummy, fake_data}, + }; use crate::entities::AggregatorEpochSettings; use crate::services::{FakeEpochService, FakeEpochServiceBuilder}; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/runtime/error.rs b/mithril-aggregator/src/runtime/error.rs index 17632fd38c3..0cd500f7f07 100644 --- a/mithril-aggregator/src/runtime/error.rs +++ b/mithril-aggregator/src/runtime/error.rs @@ -93,7 +93,7 @@ impl From for RuntimeError { mod tests { use anyhow::anyhow; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index 79700d2c806..e9de8698a9a 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -549,7 +549,10 @@ pub mod tests { }, signable_builder::SignableBuilderService, temp_dir, - test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, + test::{ + builder::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 c290ee8d48c..fc613f3f5c8 100644 --- a/mithril-aggregator/src/runtime/state_machine.rs +++ b/mithril-aggregator/src/runtime/state_machine.rs @@ -387,10 +387,10 @@ mod tests { use mockall::predicate; use std::time::Duration; - use mithril_common::test_utils::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; use crate::entities::OpenMessage; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::super::runner::MockAggregatorRunner; use super::*; diff --git a/mithril-aggregator/src/services/aggregator_client.rs b/mithril-aggregator/src/services/aggregator_client.rs index 4b09c7c517f..836993c8721 100644 --- a/mithril-aggregator/src/services/aggregator_client.rs +++ b/mithril-aggregator/src/services/aggregator_client.rs @@ -383,7 +383,7 @@ impl RemoteCertificateRetriever for AggregatorHTTPClient { pub(crate) mod dumb { use tokio::sync::RwLock; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; @@ -421,11 +421,10 @@ mod tests { use reqwest::IntoUrl; use serde_json::json; - use mithril_common::api_version::DummyApiVersionDiscriminantSource; use mithril_common::messages::CertificateListItemMessage; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::{Dummy, DummyApiVersionDiscriminantSource}; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; @@ -813,7 +812,7 @@ mod tests { mod warn_if_api_version_mismatch { use std::collections::HashMap; - use mithril_common::test_utils::MemoryDrainForTestInspector; + use mithril_common::test::logging::MemoryDrainForTestInspector; use super::*; @@ -1006,7 +1005,7 @@ mod tests { } mod remote_certificate_retriever { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-aggregator/src/services/cardano_transactions_importer.rs b/mithril-aggregator/src/services/cardano_transactions_importer.rs index d9d991b0587..58e58c2dc83 100644 --- a/mithril-aggregator/src/services/cardano_transactions_importer.rs +++ b/mithril-aggregator/src/services/cardano_transactions_importer.rs @@ -230,7 +230,7 @@ mod tests { use mithril_persistence::sqlite::SqliteConnectionPool; use crate::database::test_helper::cardano_tx_db_connection; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; 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 0eb8261f304..871b1442fd1 100644 --- a/mithril-aggregator/src/services/certificate_chain_synchronizer/synchronizer_service.rs +++ b/mithril-aggregator/src/services/certificate_chain_synchronizer/synchronizer_service.rs @@ -224,19 +224,18 @@ mod tests { use anyhow::anyhow; use std::sync::RwLock; - use mithril_common::certificate_chain::{ - FakeCertificaterRetriever, MithrilCertificateVerifier, - }; - use mithril_common::test_utils::{ - CertificateChainBuilder, CertificateChainFixture, fake_data, fake_keys, + use mithril_common::certificate_chain::MithrilCertificateVerifier; + use mithril_common::test::{ + builder::{CertificateChainBuilder, CertificateChainFixture}, + double::{FakeCertificaterRetriever, fake_data, fake_keys}, mock_extensions::MockBuilder, }; use crate::services::{ MockOpenMessageStorer, MockRemoteCertificateRetriever, MockSynchronizedCertificateStorer, }; - use crate::test::mocks::MockCertificateVerifier; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; + use crate::test::double::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 7d7f34a736b..322a52f83a1 100644 --- a/mithril-aggregator/src/services/certifier/buffered_certifier.rs +++ b/mithril-aggregator/src/services/certifier/buffered_certifier.rs @@ -191,14 +191,15 @@ mod tests { CardanoTransactions, MithrilStakeDistribution, }; use mithril_common::entities::SingleSignatureAuthenticationStatus; - use mithril_common::test_utils::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; + use mithril_common::test::entities_extensions::SingleSignatureTestExtension; use crate::database::repository::BufferedSingleSignatureRepository; use crate::database::test_helper::main_db_connection; use crate::services::{ CertifierServiceError, MockBufferedSingleSignatureStore, MockCertifierService, }; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/services/certifier/certifier_service.rs b/mithril-aggregator/src/services/certifier/certifier_service.rs index a26230c8cb1..574867822d5 100644 --- a/mithril-aggregator/src/services/certifier/certifier_service.rs +++ b/mithril-aggregator/src/services/certifier/certifier_service.rs @@ -413,13 +413,16 @@ mod tests { use crate::{ ServeCommandConfiguration, dependency_injection::DependenciesBuilder, - multi_signer::MockMultiSigner, services::FakeEpochService, test_tools::TestLogger, + multi_signer::MockMultiSigner, services::FakeEpochService, test::TestLogger, }; use chrono::{DateTime, Days}; use mithril_common::{ entities::{CardanoDbBeacon, ProtocolMessagePartKey}, temp_dir, - test_utils::{MithrilFixture, MithrilFixtureBuilder, fake_data}, + test::{ + builder::{MithrilFixture, MithrilFixtureBuilder}, + double::fake_data, + }, }; use tokio::sync::RwLock; diff --git a/mithril-aggregator/src/services/epoch_service.rs b/mithril-aggregator/src/services/epoch_service.rs index be9174a3cde..3c9a109b534 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::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; let signers = fake_data::signers_with_stakes(3); Self { @@ -637,10 +637,10 @@ impl FakeEpochServiceBuilder { impl FakeEpochService { pub fn from_fixture( epoch: Epoch, - fixture: &mithril_common::test_utils::MithrilFixture, + fixture: &mithril_common::test::builder::MithrilFixture, ) -> Self { use mithril_common::entities::CardanoTransactionsSigningConfig; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; let current_epoch_settings = AggregatorEpochSettings { protocol_parameters: fixture.protocol_parameters(), @@ -836,19 +836,20 @@ impl EpochService for FakeEpochService { #[cfg(test)] mod tests { + use mockall::predicate::eq; + use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_common::entities::{ BlockNumber, CardanoTransactionsSigningConfig, Stake, StakeDistribution, SupportedEra, }; - use mithril_common::test_utils::{ - MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod, double::Dummy, - fake_data, + use mithril_common::test::{ + builder::{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::test::TestLogger; + use crate::test::double::mocks::MockStakeStore; use super::*; @@ -1124,8 +1125,10 @@ mod tests { async fn inform_epoch_get_signed_entity_config_from_its_dependencies_and_store() { let epoch = Epoch(5); - let cardano_transactions_signing_config = - CardanoTransactionsSigningConfig::new(BlockNumber(29), BlockNumber(986)); + let cardano_transactions_signing_config = CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(29), + step: BlockNumber(986), + }; let allowed_discriminants = BTreeSet::from([ SignedEntityTypeDiscriminants::CardanoTransactions, SignedEntityTypeDiscriminants::CardanoImmutableFilesFull, diff --git a/mithril-aggregator/src/services/message.rs b/mithril-aggregator/src/services/message.rs index b7b3639dace..9e8f3d4f83d 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::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; use tokio::sync::RwLock; use crate::database::record::SignedEntityRecord; @@ -437,7 +437,7 @@ mod tests { mod epoch_settings { use mithril_common::{ entities::{CardanoTransactionsSigningConfig, ProtocolParameters}, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use crate::{entities::AggregatorEpochSettings, services::FakeEpochServiceBuilder}; @@ -467,17 +467,17 @@ mod tests { assert_eq!(message.next_signers.len(), 3); assert_eq!( message.cardano_transactions_signing_config, - Some(CardanoTransactionsSigningConfig::new( - BlockNumber(0), - BlockNumber(15) - )) + Some(CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(0), + step: BlockNumber(15) + }) ); assert_eq!( message.next_cardano_transactions_signing_config, - Some(CardanoTransactionsSigningConfig::new( - BlockNumber(0), - BlockNumber(15) - )) + Some(CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(0), + step: BlockNumber(15) + }) ); } @@ -561,17 +561,17 @@ mod tests { #[tokio::test] async fn get_epoch_settings_message_retrieves_signing_configuration_from_epoch_service() { let current_epoch_settings = AggregatorEpochSettings { - cardano_transactions_signing_config: CardanoTransactionsSigningConfig::new( - BlockNumber(100), - BlockNumber(15), - ), + cardano_transactions_signing_config: CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(100), + step: BlockNumber(15), + }, ..AggregatorEpochSettings::dummy() }; let next_epoch_settings = AggregatorEpochSettings { - cardano_transactions_signing_config: CardanoTransactionsSigningConfig::new( - BlockNumber(200), - BlockNumber(15), - ), + cardano_transactions_signing_config: CardanoTransactionsSigningConfig { + security_parameter: BlockNumber(200), + step: BlockNumber(15), + }, ..AggregatorEpochSettings::dummy() }; let epoch_service = FakeEpochServiceBuilder { diff --git a/mithril-aggregator/src/services/prover.rs b/mithril-aggregator/src/services/prover.rs index ebe20d9385b..e4581eb003f 100644 --- a/mithril-aggregator/src/services/prover.rs +++ b/mithril-aggregator/src/services/prover.rs @@ -213,11 +213,11 @@ mod tests { MKMap, MKMapNode, MKTreeNode, MKTreeStoreInMemory, MKTreeStorer, }; use mithril_common::entities::CardanoTransaction; - use mithril_common::test_utils::CardanoTransactionsBuilder; + use mithril_common::test::builder::CardanoTransactionsBuilder; use mockall::mock; use mockall::predicate::eq; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; 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 92f332ce6bd..d1ed66f8af5 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,10 @@ impl SignableSeedBuilder for AggregatorSignableSeedBuilder { mod tests { use mithril_common::{ entities::Epoch, - test_utils::{MithrilFixture, MithrilFixtureBuilder, double::Dummy}, + test::{ + builder::{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 ffc401d0dc7..1bdf0b771cf 100644 --- a/mithril-aggregator/src/services/signature_consumer/dmq.rs +++ b/mithril-aggregator/src/services/signature_consumer/dmq.rs @@ -57,7 +57,7 @@ impl SignatureConsumer for SignatureConsumerDmq { mod tests { use mithril_common::{ crypto_helper::ProtocolSingleSignature, - test_utils::{double::Dummy, fake_keys}, + test::double::{Dummy, fake_keys}, }; use mithril_dmq::test::double::DmqConsumerFake; diff --git a/mithril-aggregator/src/services/signature_consumer/fake.rs b/mithril-aggregator/src/services/signature_consumer/fake.rs index 0eb07d7630f..9381195cd97 100644 --- a/mithril-aggregator/src/services/signature_consumer/fake.rs +++ b/mithril-aggregator/src/services/signature_consumer/fake.rs @@ -46,7 +46,7 @@ impl SignatureConsumer for FakeSignatureConsumer { mod tests { use super::*; - use mithril_common::{entities::Epoch, test_utils::fake_data}; + use mithril_common::{entities::Epoch, test::double::fake_data}; #[tokio::test] async fn fake_signature_consumer_returns_signature_batches_in_expected_order() { diff --git a/mithril-aggregator/src/services/signature_processor.rs b/mithril-aggregator/src/services/signature_processor.rs index 02054b36b6d..65240936e90 100644 --- a/mithril-aggregator/src/services/signature_processor.rs +++ b/mithril-aggregator/src/services/signature_processor.rs @@ -99,7 +99,7 @@ mod tests { use anyhow::anyhow; use mithril_common::{ entities::{Epoch, SignedEntityType}, - test_utils::fake_data, + test::double::fake_data, }; use mockall::predicate::eq; use tokio::{ @@ -112,7 +112,7 @@ mod tests { FakeSignatureConsumer, MockCertifierService, MockSignatureConsumer, SignatureRegistrationStatus, }, - test_tools::TestLogger, + test::TestLogger, }; use super::*; diff --git a/mithril-aggregator/src/services/signed_entity.rs b/mithril-aggregator/src/services/signed_entity.rs index 83e22540404..7cd5d3531f2 100644 --- a/mithril-aggregator/src/services/signed_entity.rs +++ b/mithril-aggregator/src/services/signed_entity.rs @@ -504,7 +504,7 @@ mod tests { use mithril_common::{ entities::{CardanoTransactionsSnapshot, Epoch, StakeDistribution}, signable_builder, - test_utils::fake_data, + test::double::fake_data, }; use mithril_metric::CounterValue; use serde::{Serialize, de::DeserializeOwned}; @@ -512,7 +512,7 @@ mod tests { use crate::artifact_builder::MockArtifactBuilder; use crate::database::repository::MockSignedEntityStorer; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/services/signer_registration/follower.rs b/mithril-aggregator/src/services/signer_registration/follower.rs index 6b5d2b2816d..68465ff4de3 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, double::Dummy}; + use mithril_common::test::{builder::MithrilFixtureBuilder, double::Dummy}; use crate::{ database::{repository::SignerRegistrationStore, test_helper::main_db_connection}, @@ -189,7 +189,7 @@ mod tests { FakeEpochService, MockLeaderAggregatorClient, MockSignerRecorder, MockSignerRegistrationVerifier, }, - test::mocks::MockStakeStore, + test::double::mocks::MockStakeStore, }; use super::*; diff --git a/mithril-aggregator/src/services/signer_registration/leader.rs b/mithril-aggregator/src/services/signer_registration/leader.rs index c5978332610..5a4ca839cbb 100644 --- a/mithril-aggregator/src/services/signer_registration/leader.rs +++ b/mithril-aggregator/src/services/signer_registration/leader.rs @@ -150,7 +150,7 @@ mod tests { use mithril_common::{ entities::{Epoch, Signer, SignerWithStake}, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use crate::{ diff --git a/mithril-aggregator/src/services/signer_registration/verifier.rs b/mithril-aggregator/src/services/signer_registration/verifier.rs index e2d8cffc042..7e0fb62f3c6 100644 --- a/mithril-aggregator/src/services/signer_registration/verifier.rs +++ b/mithril-aggregator/src/services/signer_registration/verifier.rs @@ -82,7 +82,7 @@ mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_common::{ entities::TimePoint, - test_utils::{MithrilFixtureBuilder, double::Dummy}, + test::{builder::MithrilFixtureBuilder, double::Dummy}, }; use super::*; diff --git a/mithril-aggregator/src/services/snapshotter/ancillary_signer/with_secret_key.rs b/mithril-aggregator/src/services/snapshotter/ancillary_signer/with_secret_key.rs index c8e7a15e64d..42b5370a42c 100644 --- a/mithril-aggregator/src/services/snapshotter/ancillary_signer/with_secret_key.rs +++ b/mithril-aggregator/src/services/snapshotter/ancillary_signer/with_secret_key.rs @@ -41,7 +41,7 @@ mod tests { use std::collections::BTreeMap; use std::path::PathBuf; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs b/mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs index 152457e4d8b..900a136b204 100644 --- a/mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs +++ b/mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs @@ -325,11 +325,11 @@ mod tests { use std::sync::Arc; use mithril_cardano_node_internal_database::test::DummyCardanoDbBuilder; - use mithril_common::test_utils::assert_equivalent; + use mithril_common::test::assert_equivalent; use mithril_common::{assert_dir_eq, current_function, temp_dir_create}; use crate::services::ancillary_signer::MockAncillarySigner; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; @@ -470,8 +470,8 @@ mod tests { let unpacked_files = list_files(&unpack_dir); let unpacked_immutable_files = list_files(&unpack_dir.join(IMMUTABLE_DIR)); - assert_equivalent(vec![IMMUTABLE_DIR.to_string()], unpacked_files); - assert_equivalent( + assert_equivalent!(vec![IMMUTABLE_DIR.to_string()], unpacked_files); + assert_equivalent!( vec![ "00001.chunk".to_string(), "00001.primary".to_string(), @@ -510,8 +510,8 @@ mod tests { let unpacked_files = list_files(&unpack_dir); let unpacked_immutable_files = list_files(&unpack_dir.join(IMMUTABLE_DIR)); - assert_equivalent(vec![IMMUTABLE_DIR.to_string()], unpacked_files); - assert_equivalent( + assert_equivalent!(vec![IMMUTABLE_DIR.to_string()], unpacked_files); + assert_equivalent!( vec![ "00002.chunk".to_string(), "00002.primary".to_string(), @@ -523,7 +523,7 @@ mod tests { } mod snapshot_ancillary { - use mithril_common::test_utils::fake_keys; + use mithril_common::test::double::fake_keys; use super::*; diff --git a/mithril-aggregator/src/services/stake_distribution.rs b/mithril-aggregator/src/services/stake_distribution.rs index e5a3b41af4e..af48d0aac0a 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::test::mocks::MockChainObserver; + use crate::test::double::mocks::MockChainObserver; use super::*; diff --git a/mithril-aggregator/src/services/upkeep.rs b/mithril-aggregator/src/services/upkeep.rs index e9891dcfd15..055575626e9 100644 --- a/mithril-aggregator/src/services/upkeep.rs +++ b/mithril-aggregator/src/services/upkeep.rs @@ -199,7 +199,7 @@ mod tests { use crate::event_store::database::test_helper::{ event_store_db_connection, event_store_db_file_connection, }; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/services/usage_reporter.rs b/mithril-aggregator/src/services/usage_reporter.rs index 105baedcc54..0c1590e61a1 100644 --- a/mithril-aggregator/src/services/usage_reporter.rs +++ b/mithril-aggregator/src/services/usage_reporter.rs @@ -166,7 +166,7 @@ mod tests { use super::UsageReporter; use super::*; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; fn build_usage_reporter() -> ( UsageReporter, diff --git a/mithril-aggregator/src/store/epoch_settings_storer.rs b/mithril-aggregator/src/store/epoch_settings_storer.rs index f322c86ca42..54f645956b8 100644 --- a/mithril-aggregator/src/store/epoch_settings_storer.rs +++ b/mithril-aggregator/src/store/epoch_settings_storer.rs @@ -111,7 +111,7 @@ impl EpochPruningTask for FakeEpochSettingsStorer { #[cfg(test)] mod tests { use mithril_common::entities::CardanoTransactionsSigningConfig; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/mithril-aggregator/src/test/double/dummies.rs b/mithril-aggregator/src/test/double/dummies.rs index 5bb10cddff8..f56092afbac 100644 --- a/mithril-aggregator/src/test/double/dummies.rs +++ b/mithril-aggregator/src/test/double/dummies.rs @@ -1,7 +1,7 @@ use chrono::Utc; use uuid::Uuid; -use mithril_common::test_utils::{double::Dummy, fake_data}; +use mithril_common::test::double::{Dummy, fake_data}; mod record { use mithril_common::entities::{ProtocolMessage, SignedEntityType}; diff --git a/mithril-aggregator/src/test/mocks.rs b/mithril-aggregator/src/test/double/mocks.rs similarity index 100% rename from mithril-aggregator/src/test/mocks.rs rename to mithril-aggregator/src/test/double/mocks.rs diff --git a/mithril-aggregator/src/test/double/mod.rs b/mithril-aggregator/src/test/double/mod.rs index 7ee7ff27e5a..f56475fc994 100644 --- a/mithril-aggregator/src/test/double/mod.rs +++ b/mithril-aggregator/src/test/double/mod.rs @@ -1 +1,7 @@ +//! Test doubles +//! +//! Enable unit testing with controlled inputs and predictable behavior. + mod dummies; +#[cfg(test)] +pub mod mocks; diff --git a/mithril-aggregator/src/test/mod.rs b/mithril-aggregator/src/test/mod.rs index 3c35bb708a2..14d1a095866 100644 --- a/mithril-aggregator/src/test/mod.rs +++ b/mithril-aggregator/src/test/mod.rs @@ -1,3 +1,4 @@ -mod double; +pub mod double; + #[cfg(test)] -pub mod mocks; +mithril_common::define_test_logger!(); diff --git a/mithril-aggregator/src/tools/certificates_hash_migrator.rs b/mithril-aggregator/src/tools/certificates_hash_migrator.rs index da4fa368e85..6b477687e73 100644 --- a/mithril-aggregator/src/tools/certificates_hash_migrator.rs +++ b/mithril-aggregator/src/tools/certificates_hash_migrator.rs @@ -216,12 +216,12 @@ mod test { Epoch, ImmutableFileNumber, SignedEntityConfig, SignedEntityType, SignedEntityTypeDiscriminants as Type, TimePoint, }; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use mithril_persistence::sqlite::{ConnectionBuilder, ConnectionOptions, SqliteConnection}; use crate::database::record::{CertificateRecord, SignedEntityRecord}; use crate::database::repository::SignedEntityStore; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/tools/era.rs b/mithril-aggregator/src/tools/era.rs index 92730ee0dd6..98947fac662 100644 --- a/mithril-aggregator/src/tools/era.rs +++ b/mithril-aggregator/src/tools/era.rs @@ -78,7 +78,7 @@ impl EraTools { mod tests { use mithril_common::{ crypto_helper::{EraMarkersVerifierSecretKey, EraMarkersVerifierVerificationKey}, - test_utils::TempDir, + test::TempDir, }; use std::fs::read_to_string; diff --git a/mithril-aggregator/src/tools/file_archiver/api.rs b/mithril-aggregator/src/tools/file_archiver/api.rs index ca9ad5f9ddb..e0aff2ee7ff 100644 --- a/mithril-aggregator/src/tools/file_archiver/api.rs +++ b/mithril-aggregator/src/tools/file_archiver/api.rs @@ -44,7 +44,7 @@ impl FileArchiver { #[cfg(test)] pub fn new_for_test(verification_temp_dir: PathBuf) -> Self { - use crate::test_tools::TestLogger; + use crate::test::TestLogger; Self { zstandard_compression_parameter: ZstandardCompressionParameters::default(), verification_temp_dir, @@ -292,7 +292,7 @@ impl FileArchiver { mod tests { use std::fs::File; - use mithril_common::test_utils::assert_equivalent; + use mithril_common::test::assert_equivalent; use crate::tools::file_archiver::appender::{AppenderDirAll, AppenderFile}; use crate::tools::file_archiver::test_tools::*; @@ -400,7 +400,7 @@ mod tests { .expect_err("FileArchiver::archive should fail if the db is empty."); let remaining_files: Vec = list_remaining_files(&test_dir); - assert_equivalent( + assert_equivalent!( vec!["other-process.file".to_string(), "archive.tar.gz".to_string()], remaining_files, ); diff --git a/mithril-aggregator/src/tools/file_archiver/entities.rs b/mithril-aggregator/src/tools/file_archiver/entities.rs index 35a03f9bc06..91dfbcb1cec 100644 --- a/mithril-aggregator/src/tools/file_archiver/entities.rs +++ b/mithril-aggregator/src/tools/file_archiver/entities.rs @@ -95,7 +95,7 @@ impl FileArchive { } #[cfg(test)] -impl mithril_common::test_utils::double::Dummy for FileArchive { +impl mithril_common::test::double::Dummy for FileArchive { fn dummy() -> Self { Self { filepath: PathBuf::from("archive.tar.gz"), diff --git a/mithril-aggregator/src/tools/file_archiver/mod.rs b/mithril-aggregator/src/tools/file_archiver/mod.rs index f365d850649..024f937f9a0 100644 --- a/mithril-aggregator/src/tools/file_archiver/mod.rs +++ b/mithril-aggregator/src/tools/file_archiver/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod test_tools { use std::fs::File; use std::path::{Path, PathBuf}; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; pub fn get_test_directory(dir_name: &str) -> PathBuf { TempDir::create("file_archiver", dir_name) diff --git a/mithril-aggregator/src/tools/file_size.rs b/mithril-aggregator/src/tools/file_size.rs index 8bb08363f6a..d53be02d65b 100644 --- a/mithril-aggregator/src/tools/file_size.rs +++ b/mithril-aggregator/src/tools/file_size.rs @@ -73,7 +73,7 @@ mod tests { use std::io::Write; use mithril_common::current_function; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use super::*; diff --git a/mithril-aggregator/src/tools/genesis.rs b/mithril-aggregator/src/tools/genesis.rs index b9fdf3b08c7..deb9bc598b7 100644 --- a/mithril-aggregator/src/tools/genesis.rs +++ b/mithril-aggregator/src/tools/genesis.rs @@ -206,12 +206,12 @@ mod tests { ProtocolGenesisSecretKey, ProtocolGenesisSigner, ProtocolGenesisVerificationKey, ProtocolGenesisVerifier, }, - test_utils::{MithrilFixtureBuilder, TempDir, fake_data}, + test::{TempDir, builder::MithrilFixtureBuilder, double::fake_data}, }; use std::{fs::read_to_string, path::PathBuf}; use crate::database::test_helper::main_db_connection; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/tools/signer_importer.rs b/mithril-aggregator/src/tools/signer_importer.rs index cdf9f151a9b..0e753b5f71e 100644 --- a/mithril-aggregator/src/tools/signer_importer.rs +++ b/mithril-aggregator/src/tools/signer_importer.rs @@ -201,7 +201,7 @@ mod tests { use crate::database::repository::{SignerGetter, SignerStore}; use crate::database::test_helper::main_db_connection; use crate::http_server::routes::reply; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/tools/single_signature_authenticator.rs b/mithril-aggregator/src/tools/single_signature_authenticator.rs index edab41fd39c..cbec2451833 100644 --- a/mithril-aggregator/src/tools/single_signature_authenticator.rs +++ b/mithril-aggregator/src/tools/single_signature_authenticator.rs @@ -88,7 +88,7 @@ impl SingleSignatureAuthenticator { Self { multi_signer: Arc::new(multi_signer), - logger: crate::test_tools::TestLogger::stdout(), + logger: crate::test::TestLogger::stdout(), } } @@ -103,7 +103,7 @@ impl SingleSignatureAuthenticator { Self { multi_signer: Arc::new(multi_signer), - logger: crate::test_tools::TestLogger::stdout(), + logger: crate::test::TestLogger::stdout(), } } } @@ -112,8 +112,10 @@ impl SingleSignatureAuthenticator { mod tests { use anyhow::anyhow; + use mithril_common::test::entities_extensions::SingleSignatureTestExtension; + use crate::multi_signer::MockMultiSigner; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/src/tools/vacuum_tracker.rs b/mithril-aggregator/src/tools/vacuum_tracker.rs index 9b90f6ce122..d185a8b9ff6 100644 --- a/mithril-aggregator/src/tools/vacuum_tracker.rs +++ b/mithril-aggregator/src/tools/vacuum_tracker.rs @@ -90,7 +90,7 @@ impl VacuumTracker { mod tests { use mithril_common::temp_dir_create; - use crate::test_tools::TestLogger; + use crate::test::TestLogger; use super::*; diff --git a/mithril-aggregator/tests/cardano_stake_distribution_verify_stakes.rs b/mithril-aggregator/tests/cardano_stake_distribution_verify_stakes.rs index 07421c11fef..2dbe303d143 100644 --- a/mithril-aggregator/tests/cardano_stake_distribution_verify_stakes.rs +++ b/mithril-aggregator/tests/cardano_stake_distribution_verify_stakes.rs @@ -9,7 +9,7 @@ use mithril_common::{ SignedEntityTypeDiscriminants, SlotNumber, StakeDistribution, StakeDistributionParty, TimePoint, }, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::ExpectedMetrics; use test_extensions::{ExpectedCertificate, RuntimeTester, utilities::get_test_dir}; diff --git a/mithril-aggregator/tests/certificate_chain.rs b/mithril-aggregator/tests/certificate_chain.rs index c2632ead7e6..dcf7ab2a62f 100644 --- a/mithril-aggregator/tests/certificate_chain.rs +++ b/mithril-aggregator/tests/certificate_chain.rs @@ -8,7 +8,7 @@ use mithril_common::{ TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ ExpectedCertificate, ExpectedMetrics, RuntimeTester, utilities::get_test_dir, diff --git a/mithril-aggregator/tests/create_certificate.rs b/mithril-aggregator/tests/create_certificate.rs index b68a6c5cdf8..b6a34970664 100644 --- a/mithril-aggregator/tests/create_certificate.rs +++ b/mithril-aggregator/tests/create_certificate.rs @@ -8,7 +8,7 @@ use mithril_common::{ StakeDistributionParty, TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ ExpectedCertificate, ExpectedMetrics, RuntimeTester, utilities::get_test_dir, diff --git a/mithril-aggregator/tests/create_certificate_follower.rs b/mithril-aggregator/tests/create_certificate_follower.rs index 3ded9df4bed..371fe067b06 100644 --- a/mithril-aggregator/tests/create_certificate_follower.rs +++ b/mithril-aggregator/tests/create_certificate_follower.rs @@ -9,8 +9,9 @@ use mithril_common::{ SignedEntityTypeDiscriminants, SlotNumber, StakeDistributionParty, TimePoint, }, temp_dir, - test_utils::{ - MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod, TempDir, + test::{ + TempDir, + builder::{MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod}, }, }; use test_extensions::{ExpectedCertificate, RuntimeTester, utilities::get_test_dir}; diff --git a/mithril-aggregator/tests/create_certificate_with_buffered_signatures.rs b/mithril-aggregator/tests/create_certificate_with_buffered_signatures.rs index 82163ef3adf..073b1e5b587 100644 --- a/mithril-aggregator/tests/create_certificate_with_buffered_signatures.rs +++ b/mithril-aggregator/tests/create_certificate_with_buffered_signatures.rs @@ -8,7 +8,7 @@ use mithril_common::{ TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ ExpectedCertificate, ExpectedMetrics, RuntimeTester, utilities::get_test_dir, diff --git a/mithril-aggregator/tests/era_checker.rs b/mithril-aggregator/tests/era_checker.rs index 091e6ee7e36..36202f14da9 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, double::Dummy}, + test::{builder::MithrilFixtureBuilder, double::Dummy}, }; use mithril_era::EraMarker; diff --git a/mithril-aggregator/tests/genesis_to_signing.rs b/mithril-aggregator/tests/genesis_to_signing.rs index 8c8e6677483..e47dba18f5a 100644 --- a/mithril-aggregator/tests/genesis_to_signing.rs +++ b/mithril-aggregator/tests/genesis_to_signing.rs @@ -4,7 +4,7 @@ use mithril_aggregator::ServeCommandConfiguration; use mithril_common::{ entities::{BlockNumber, ChainPoint, Epoch, ProtocolParameters, SlotNumber, TimePoint}, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ExpectedCertificate, RuntimeTester, utilities::get_test_dir}; diff --git a/mithril-aggregator/tests/open_message_expiration.rs b/mithril-aggregator/tests/open_message_expiration.rs index ecbdd059ac3..4e321f2b158 100644 --- a/mithril-aggregator/tests/open_message_expiration.rs +++ b/mithril-aggregator/tests/open_message_expiration.rs @@ -9,7 +9,7 @@ use mithril_common::{ SignedEntityTypeDiscriminants, SlotNumber, TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ ExpectedCertificate, ExpectedMetrics, RuntimeTester, utilities::get_test_dir, diff --git a/mithril-aggregator/tests/open_message_newer_exists.rs b/mithril-aggregator/tests/open_message_newer_exists.rs index a215a3ab967..f3850e3201a 100644 --- a/mithril-aggregator/tests/open_message_newer_exists.rs +++ b/mithril-aggregator/tests/open_message_newer_exists.rs @@ -7,7 +7,7 @@ use mithril_common::{ SignedEntityTypeDiscriminants, SlotNumber, StakeDistributionParty, TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ ExpectedCertificate, ExpectedMetrics, RuntimeTester, utilities::get_test_dir, diff --git a/mithril-aggregator/tests/prove_transactions.rs b/mithril-aggregator/tests/prove_transactions.rs index 564a0bf748b..4125ed824d3 100644 --- a/mithril-aggregator/tests/prove_transactions.rs +++ b/mithril-aggregator/tests/prove_transactions.rs @@ -5,7 +5,7 @@ use mithril_common::{ ProtocolParameters, SignedEntityType, SignedEntityTypeDiscriminants, SlotNumber, TimePoint, }, temp_dir, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; use test_extensions::{ ExpectedCertificate, ExpectedMetrics, RuntimeTester, utilities::get_test_dir, diff --git a/mithril-aggregator/tests/test_extensions/runtime_tester.rs b/mithril-aggregator/tests/test_extensions/runtime_tester.rs index 6c974186e59..2adb9d8d70b 100644 --- a/mithril-aggregator/tests/test_extensions/runtime_tester.rs +++ b/mithril-aggregator/tests/test_extensions/runtime_tester.rs @@ -29,8 +29,10 @@ use mithril_common::{ SingleSignatureAuthenticationStatus, SlotNumber, StakeDistribution, SupportedEra, TimePoint, }, - test_utils::{ - MithrilFixture, MithrilFixtureBuilder, SignerFixture, StakeDistributionGenerationMethod, + test::{ + builder::{ + MithrilFixture, MithrilFixtureBuilder, SignerFixture, StakeDistributionGenerationMethod, + }, double::Dummy, }, }; diff --git a/mithril-aggregator/tests/test_extensions/utilities.rs b/mithril-aggregator/tests/test_extensions/utilities.rs index c6921470b6a..efa842d9793 100644 --- a/mithril-aggregator/tests/test_extensions/utilities.rs +++ b/mithril-aggregator/tests/test_extensions/utilities.rs @@ -1,4 +1,4 @@ -use mithril_common::test_utils::TempDir; +use mithril_common::test::TempDir; use slog_scope::debug; use std::{ path::PathBuf, diff --git a/mithril-client-cli/Cargo.toml b/mithril-client-cli/Cargo.toml index efee7ba1041..6a51bb4f904 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.23" +version = "0.12.24" 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 62c82b0c9c9..dc6197d14b9 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, double::Dummy}; + use mithril_common::test::{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 9ea00495701..9c604b8a281 100644 --- a/mithril-client-cli/src/commands/cardano_db/download/v2.rs +++ b/mithril-client-cli/src/commands/cardano_db/download/v2.rs @@ -283,7 +283,7 @@ impl PreparedCardanoDbV2Download { #[cfg(test)] mod tests { use mithril_client::common::{AncillaryMessagePart, DigestsMessagePart, ImmutablesMessagePart}; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::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 85fb03a9f43..5efdd3e675d 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, double::Dummy}; + use mithril_common::test::{TempDir, double::Dummy}; use crate::utils::ProgressOutputType; diff --git a/mithril-client-cli/src/utils/cardano_db_download_checker.rs b/mithril-client-cli/src/utils/cardano_db_download_checker.rs index ac7dcb61791..d3a9fc48630 100644 --- a/mithril-client-cli/src/utils/cardano_db_download_checker.rs +++ b/mithril-client-cli/src/utils/cardano_db_download_checker.rs @@ -176,7 +176,7 @@ impl CardanoDbDownloadChecker { #[cfg(test)] mod test { - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use super::*; diff --git a/mithril-client/Cargo.toml b/mithril-client/Cargo.toml index aff5e602ffe..f9c27c73a67 100644 --- a/mithril-client/Cargo.toml +++ b/mithril-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client" -version = "0.12.23" +version = "0.12.24" description = "Mithril client library" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-client/src/aggregator_client.rs b/mithril-client/src/aggregator_client.rs index c8dbf9fc5b1..1da283f88d3 100644 --- a/mithril-client/src/aggregator_client.rs +++ b/mithril-client/src/aggregator_client.rs @@ -877,7 +877,7 @@ mod tests { mod warn_if_api_version_mismatch { use http::response::Builder as HttpResponseBuilder; - use mithril_common::test_utils::MemoryDrainForTestInspector; + use mithril_common::test::logging::MemoryDrainForTestInspector; use super::*; diff --git a/mithril-client/src/cardano_database_client/api.rs b/mithril-client/src/cardano_database_client/api.rs index a5bd0cbf5b5..3f643e3fa49 100644 --- a/mithril-client/src/cardano_database_client/api.rs +++ b/mithril-client/src/cardano_database_client/api.rs @@ -249,7 +249,7 @@ pub(crate) mod test_dependency_injector { } mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use mockall::predicate; use crate::aggregator_client::AggregatorRequest; diff --git a/mithril-client/src/cardano_database_client/download_unpack/download_task.rs b/mithril-client/src/cardano_database_client/download_unpack/download_task.rs index c2613ac8343..0dd25d53ac9 100644 --- a/mithril-client/src/cardano_database_client/download_unpack/download_task.rs +++ b/mithril-client/src/cardano_database_client/download_unpack/download_task.rs @@ -162,7 +162,7 @@ pub struct LocationToDownload { #[cfg(test)] mod tests { use mithril_common::entities::FileUri; - use mithril_common::test_utils::{assert_dir_eq, fake_keys, temp_dir_create}; + use mithril_common::test::{assert_dir_eq, double::fake_keys, temp_dir_create}; use crate::file_downloader::MockFileDownloaderBuilder; use crate::test_utils::TestLogger; 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 6b0e3988d12..3764338fb36 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::{double::Dummy, temp_dir_create}, + test::{double::Dummy, temp_dir_create}, }; use crate::cardano_database_client::CardanoDatabaseClientDependencyInjector; @@ -532,7 +532,7 @@ mod tests { } mod building_download_tasks { - use mithril_common::{entities::CompressionAlgorithm, test_utils::fake_keys}; + use mithril_common::{entities::CompressionAlgorithm, test::double::fake_keys}; use crate::file_downloader::MockFileDownloader; diff --git a/mithril-client/src/cardano_database_client/fetch.rs b/mithril-client/src/cardano_database_client/fetch.rs index e667340ae9f..16bafbcc739 100644 --- a/mithril-client/src/cardano_database_client/fetch.rs +++ b/mithril-client/src/cardano_database_client/fetch.rs @@ -66,7 +66,7 @@ mod tests { use mockall::predicate::eq; use mithril_common::entities::{CardanoDbBeacon, Epoch}; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::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 711811c9cf0..ff8be6882d4 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, double::Dummy}, + test::{TempDir, double::Dummy}, }; use crate::{ diff --git a/mithril-client/src/cardano_transaction_client.rs b/mithril-client/src/cardano_transaction_client.rs index c488ba55c0f..d048f4c5268 100644 --- a/mithril-client/src/cardano_transaction_client.rs +++ b/mithril-client/src/cardano_transaction_client.rs @@ -164,7 +164,7 @@ mod tests { use chrono::{DateTime, Utc}; use mockall::predicate::eq; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use crate::aggregator_client::{AggregatorClientError, MockAggregatorClient}; use crate::common::{BlockNumber, Epoch}; diff --git a/mithril-client/src/certificate_client/fetch.rs b/mithril-client/src/certificate_client/fetch.rs index f4296bb74e9..7c8b00b4b55 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::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; use crate::certificate_client::tests_utils::CertificateClientTestBuilder; diff --git a/mithril-client/src/certificate_client/verify.rs b/mithril-client/src/certificate_client/verify.rs index 30f498d994d..c7e8af2464e 100644 --- a/mithril-client/src/certificate_client/verify.rs +++ b/mithril-client/src/certificate_client/verify.rs @@ -244,7 +244,7 @@ impl CertificateVerifier for MithrilCertificateVerifier { #[cfg(test)] mod tests { - use mithril_common::test_utils::CertificateChainBuilder; + use mithril_common::test::builder::CertificateChainBuilder; use crate::certificate_client::tests_utils::CertificateClientTestBuilder; use crate::feedback::StackFeedbackReceiver; @@ -321,7 +321,7 @@ mod tests { #[cfg(feature = "unstable")] mod cache { use chrono::TimeDelta; - use mithril_common::test_utils::CertificateChainingMethod; + use mithril_common::test::builder::CertificateChainingMethod; use mockall::predicate::eq; use crate::aggregator_client::MockAggregatorClient; diff --git a/mithril-client/src/certificate_client/verify_cache/memory_cache.rs b/mithril-client/src/certificate_client/verify_cache/memory_cache.rs index 480d8e39ea6..edee4932a93 100644 --- a/mithril-client/src/certificate_client/verify_cache/memory_cache.rs +++ b/mithril-client/src/certificate_client/verify_cache/memory_cache.rs @@ -161,7 +161,7 @@ pub(crate) mod test_tools { #[cfg(test)] mod tests { use mithril_common::entities::Certificate; - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-client/src/file_downloader/http.rs b/mithril-client/src/file_downloader/http.rs index e51243faf46..83750375ca4 100644 --- a/mithril-client/src/file_downloader/http.rs +++ b/mithril-client/src/file_downloader/http.rs @@ -242,7 +242,7 @@ mod tests { use httpmock::MockServer; - use mithril_common::{entities::FileUri, test_utils::TempDir}; + use mithril_common::{entities::FileUri, test::TempDir}; use crate::{ feedback::{MithrilEvent, MithrilEventCardanoDatabase, StackFeedbackReceiver}, diff --git a/mithril-client/src/lib.rs b/mithril-client/src/lib.rs index 15ea396668a..22647c6333e 100644 --- a/mithril-client/src/lib.rs +++ b/mithril-client/src/lib.rs @@ -144,33 +144,5 @@ pub use type_alias::*; #[cfg(test)] pub(crate) mod test_utils { - use std::io; - use std::sync::Arc; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - use mithril_common::test_utils::{MemoryDrainForTest, MemoryDrainForTestInspector}; - - pub struct TestLogger; - - #[allow(unused)] - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - - pub fn memory() -> (Logger, MemoryDrainForTestInspector) { - let (drain, inspector) = MemoryDrainForTest::new(); - (Logger::root(drain.fuse(), slog::o!()), inspector) - } - } + mithril_common::define_test_logger!(); } diff --git a/mithril-client/src/mithril_stake_distribution_client.rs b/mithril-client/src/mithril_stake_distribution_client.rs index 18243ec3ec7..5f5ccc169df 100644 --- a/mithril-client/src/mithril_stake_distribution_client.rs +++ b/mithril-client/src/mithril_stake_distribution_client.rs @@ -95,7 +95,7 @@ impl MithrilStakeDistributionClient { #[cfg(test)] mod tests { use chrono::{DateTime, Utc}; - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use crate::MithrilSigner; use crate::aggregator_client::MockAggregatorClient; diff --git a/mithril-client/src/snapshot_client.rs b/mithril-client/src/snapshot_client.rs index 09e189a24d1..7177b62b163 100644 --- a/mithril-client/src/snapshot_client.rs +++ b/mithril-client/src/snapshot_client.rs @@ -481,7 +481,7 @@ mod tests { }; use mithril_cardano_node_internal_database::IMMUTABLE_DIR; - use mithril_common::test_utils::{double::Dummy, fake_keys}; + use mithril_common::test::double::{Dummy, fake_keys}; use mithril_common::{assert_dir_eq, crypto_helper::ManifestSigner, temp_dir_create}; use super::*; diff --git a/mithril-client/src/utils/ancillary_verifier.rs b/mithril-client/src/utils/ancillary_verifier.rs index 62447c94df0..173a7d8659a 100644 --- a/mithril-client/src/utils/ancillary_verifier.rs +++ b/mithril-client/src/utils/ancillary_verifier.rs @@ -131,7 +131,7 @@ mod tests { use std::collections::BTreeMap; use mithril_common::entities::SignableManifest; - use mithril_common::{crypto_helper::ManifestSigner, test_utils::fake_keys}; + use mithril_common::{crypto_helper::ManifestSigner, test::double::fake_keys}; use super::*; diff --git a/mithril-client/tests/cardano_db_snapshot_list_get_download_verify.rs b/mithril-client/tests/cardano_db_snapshot_list_get_download_verify.rs index 5750213e5f9..6058fd96af4 100644 --- a/mithril-client/tests/cardano_db_snapshot_list_get_download_verify.rs +++ b/mithril-client/tests/cardano_db_snapshot_list_get_download_verify.rs @@ -11,7 +11,7 @@ use mithril_client::{ cardano_database_client::{DownloadUnpackOptions, ImmutableFileRange}, feedback::SlogFeedbackReceiver, }; -use mithril_common::crypto_helper::ManifestSigner; +use mithril_common::{crypto_helper::ManifestSigner, test::double::fake_keys}; use crate::extensions::fake_aggregator::{ CardanoDatabaseSnapshotV2Fixture, FakeAggregator, FakeCertificateVerifier, @@ -20,8 +20,7 @@ use crate::extensions::fake_aggregator::{ #[tokio::test] async fn cardano_db_snapshot_list_get_download_verify() { let work_dir = extensions::get_test_dir("cardano_db_snapshot_list_get_download_verify"); - let genesis_verification_key = - mithril_common::test_utils::fake_keys::genesis_verification_key()[0]; + let genesis_verification_key = fake_keys::genesis_verification_key()[0]; let (ancillary_manifest_signing_key, ancillary_manifest_signer_verification_key) = { let signer = ManifestSigner::create_deterministic_signer(); (signer.secret_key(), signer.verification_key()) diff --git a/mithril-client/tests/cardano_transaction_proof.rs b/mithril-client/tests/cardano_transaction_proof.rs index 369caaf28c8..c1da74e7b6c 100644 --- a/mithril-client/tests/cardano_transaction_proof.rs +++ b/mithril-client/tests/cardano_transaction_proof.rs @@ -1,12 +1,13 @@ mod extensions; -use crate::extensions::fake_aggregator::{FakeAggregator, FakeCertificateVerifier}; use mithril_client::{ClientBuilder, MessageBuilder, aggregator_client::AggregatorRequest}; +use mithril_common::test::double::fake_keys; + +use crate::extensions::fake_aggregator::{FakeAggregator, FakeCertificateVerifier}; #[tokio::test] async fn cardano_transaction_proof_get_validate() { - let genesis_verification_key = - mithril_common::test_utils::fake_keys::genesis_verification_key()[0]; + let genesis_verification_key = fake_keys::genesis_verification_key()[0]; let transactions_hashes = ["abc", "def"]; let certificate_hash = "certificate_hash"; diff --git a/mithril-client/tests/certificate_get_list.rs b/mithril-client/tests/certificate_get_list.rs index 4035dbd294a..46453c5c8db 100644 --- a/mithril-client/tests/certificate_get_list.rs +++ b/mithril-client/tests/certificate_get_list.rs @@ -1,13 +1,14 @@ mod extensions; -use crate::extensions::fake_aggregator::FakeAggregator; use mithril_client::{ClientBuilder, aggregator_client::AggregatorRequest}; +use mithril_common::test::double::fake_keys; + +use crate::extensions::fake_aggregator::FakeAggregator; #[tokio::test] async fn certificate_get_list() { let certificate_hash_list = vec!["certificate-123".to_string(), "certificate-456".to_string()]; - let genesis_verification_key = - mithril_common::test_utils::fake_keys::genesis_verification_key()[0]; + let genesis_verification_key = fake_keys::genesis_verification_key()[0]; let fake_aggregator = FakeAggregator::spawn_with_certificate(&certificate_hash_list); let client = ClientBuilder::aggregator(&fake_aggregator.server_root_url(), genesis_verification_key) 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 d162821ab84..cc86198f47e 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::{double::Dummy, fake_data}; +use mithril_common::test::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 641528179ae..f05e188f4f5 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::{double::Dummy, fake_data}; +use mithril_common::test::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 d55c4fd5073..7d05c948e87 100644 --- a/mithril-client/tests/extensions/fake_aggregator/cardano_transaction.rs +++ b/mithril-client/tests/extensions/fake_aggregator/cardano_transaction.rs @@ -1,7 +1,8 @@ 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 mithril_common::test::crypto_helper::MKProofTestExtension; +use mithril_common::test::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 3794e5a8df9..8ca4cf68df0 100644 --- a/mithril-client/tests/extensions/fake_aggregator/certificate.rs +++ b/mithril-client/tests/extensions/fake_aggregator/certificate.rs @@ -1,5 +1,5 @@ use mithril_client::{MithrilCertificate, MithrilCertificateListItem}; -use mithril_common::test_utils::double::Dummy; +use mithril_common::test::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 3a28e2750a5..5706769d85c 100644 --- a/mithril-client/tests/extensions/fake_aggregator/mithril_stake_distribution.rs +++ b/mithril-client/tests/extensions/fake_aggregator/mithril_stake_distribution.rs @@ -1,7 +1,7 @@ use mithril_client::{ MessageBuilder, MithrilCertificate, MithrilStakeDistribution, MithrilStakeDistributionListItem, }; -use mithril_common::test_utils::double::Dummy; +use mithril_common::test::double::Dummy; use crate::extensions::routes; diff --git a/mithril-client/tests/extensions/mod.rs b/mithril-client/tests/extensions/mod.rs index 8e7d65495af..ef039448e5e 100644 --- a/mithril-client/tests/extensions/mod.rs +++ b/mithril-client/tests/extensions/mod.rs @@ -8,7 +8,7 @@ mod routes; #[cfg(feature = "fs")] mod snapshot_archives; -use mithril_common::test_utils::TempDir; +use mithril_common::test::TempDir; use std::path::PathBuf; pub fn get_test_dir(subdir_name: &str) -> PathBuf { diff --git a/mithril-client/tests/mithril_stake_distribution_list_get_show_verify.rs b/mithril-client/tests/mithril_stake_distribution_list_get_show_verify.rs index 9cf6a62ed43..736f2578bac 100644 --- a/mithril-client/tests/mithril_stake_distribution_list_get_show_verify.rs +++ b/mithril-client/tests/mithril_stake_distribution_list_get_show_verify.rs @@ -1,12 +1,13 @@ mod extensions; -use crate::extensions::fake_aggregator::{FakeAggregator, FakeCertificateVerifier}; use mithril_client::{ClientBuilder, MessageBuilder, aggregator_client::AggregatorRequest}; +use mithril_common::test::double::fake_keys; + +use crate::extensions::fake_aggregator::{FakeAggregator, FakeCertificateVerifier}; #[tokio::test] async fn mithril_stake_distribution_list_get_show_verify() { - let genesis_verification_key = - mithril_common::test_utils::fake_keys::genesis_verification_key()[0]; + let genesis_verification_key = fake_keys::genesis_verification_key()[0]; let msd_hash = "msd_hash"; let certificate_hash = "certificate_hash"; let fake_aggregator = diff --git a/mithril-client/tests/snapshot_list_get_show_download_verify.rs b/mithril-client/tests/snapshot_list_get_show_download_verify.rs index 741f723eae7..abc030c3437 100644 --- a/mithril-client/tests/snapshot_list_get_show_download_verify.rs +++ b/mithril-client/tests/snapshot_list_get_show_download_verify.rs @@ -7,14 +7,14 @@ use mithril_client::aggregator_client::AggregatorRequest; use mithril_client::feedback::SlogFeedbackReceiver; use mithril_client::{ClientBuilder, MessageBuilder}; use mithril_common::crypto_helper::ManifestSigner; +use mithril_common::test::double::fake_keys; use crate::extensions::fake_aggregator::{FakeAggregator, FakeCertificateVerifier}; #[tokio::test] async fn snapshot_list_get_show_download_verify() { let work_dir = extensions::get_test_dir("snapshot_list_get_show_download_verify"); - let genesis_verification_key = - mithril_common::test_utils::fake_keys::genesis_verification_key()[0]; + let genesis_verification_key = fake_keys::genesis_verification_key()[0]; let (ancillary_manifest_signing_key, ancillary_manifest_signer_verification_key) = { let signer = ManifestSigner::create_deterministic_signer(); (signer.secret_key(), signer.verification_key()) diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 1409e5f2489..accbd6eb4e9 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.6.10" +version = "0.6.11" description = "Common types, interfaces, and utilities for Mithril nodes." authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-common/src/api_version.rs b/mithril-common/src/api_version.rs index 9c21216979d..3d069df2113 100644 --- a/mithril-common/src/api_version.rs +++ b/mithril-common/src/api_version.rs @@ -73,38 +73,10 @@ impl APIVersionProvider { } } -cfg_test_tools! { - /// A dummy implementation of the `ApiVersionDiscriminantSource` trait for testing purposes. - pub struct DummyApiVersionDiscriminantSource { - discriminant: String, - } - - impl DummyApiVersionDiscriminantSource { - /// Create a new instance of `DummyApiVersionDiscriminantSource` with the given discriminant. - pub fn new>(discrimant: T) -> Self { - Self { - discriminant: discrimant.into(), - } - } - } - - impl Default for DummyApiVersionDiscriminantSource { - fn default() -> Self { - Self { - discriminant: "dummy".to_string(), - } - } - } - - impl ApiVersionDiscriminantSource for DummyApiVersionDiscriminantSource { - fn get_discriminant(&self) -> String { - self.discriminant.clone() - } - } -} - #[cfg(test)] mod test { + use crate::test::double::DummyApiVersionDiscriminantSource; + use super::*; #[test] diff --git a/mithril-common/src/certificate_chain/certificate_genesis.rs b/mithril-common/src/certificate_chain/certificate_genesis.rs index ee6bc96bb2a..afaf2344e85 100644 --- a/mithril-common/src/certificate_chain/certificate_genesis.rs +++ b/mithril-common/src/certificate_chain/certificate_genesis.rs @@ -111,7 +111,7 @@ impl CertificateGenesisProducer { mod tests { use super::*; - use crate::{entities::ProtocolMessagePartKey, test_utils::MithrilFixtureBuilder}; + use crate::{entities::ProtocolMessagePartKey, test::builder::MithrilFixtureBuilder}; #[test] fn test_create_genesis_protocol_message_has_expected_keys_and_values() { diff --git a/mithril-common/src/certificate_chain/certificate_verifier.rs b/mithril-common/src/certificate_chain/certificate_verifier.rs index 4f308ec49a3..9de7ca53e45 100644 --- a/mithril-common/src/certificate_chain/certificate_verifier.rs +++ b/mithril-common/src/certificate_chain/certificate_verifier.rs @@ -421,18 +421,21 @@ mod tests { use std::collections::HashMap; use async_trait::async_trait; - use mockall::mock; use tokio::sync::Mutex; - use super::CertificateRetriever; - use super::*; - - use crate::certificate_chain::{CertificateRetrieverError, FakeCertificaterRetriever}; - use crate::crypto_helper::{ProtocolClerk, tests_setup::*}; - use crate::test_utils::{ - CertificateChainBuilder, CertificateChainBuilderContext, MithrilFixtureBuilder, TestLogger, + use crate::test::{ + TestLogger, + builder::{CertificateChainBuilder, CertificateChainBuilderContext, MithrilFixtureBuilder}, + crypto_helper::{setup_certificate_chain, setup_message, setup_protocol_parameters}, + double::FakeCertificaterRetriever, + }; + use crate::{ + certificate_chain::certificate_retriever::MockCertificateRetriever, + crypto_helper::ProtocolClerk, }; + use super::*; + macro_rules! assert_error_matches { ( $expected_error:path, $error:expr ) => {{ let error = $error @@ -447,27 +450,14 @@ mod tests { }}; } - mock! { - pub CertificateRetrieverImpl { } - - #[async_trait] - impl CertificateRetriever for CertificateRetrieverImpl { - - async fn get_certificate_details( - &self, - certificate_hash: &str, - ) -> Result; - } - } - struct MockDependencyInjector { - mock_certificate_retriever: MockCertificateRetrieverImpl, + mock_certificate_retriever: MockCertificateRetriever, } impl MockDependencyInjector { fn new() -> MockDependencyInjector { MockDependencyInjector { - mock_certificate_retriever: MockCertificateRetrieverImpl::new(), + mock_certificate_retriever: MockCertificateRetriever::new(), } } @@ -504,7 +494,7 @@ mod tests { let verifier = MithrilCertificateVerifier::new( TestLogger::stdout(), - Arc::new(MockCertificateRetrieverImpl::new()), + Arc::new(MockCertificateRetriever::new()), ); let message_tampered = message_hash[1..].to_vec(); assert!( diff --git a/mithril-common/src/certificate_chain/mod.rs b/mithril-common/src/certificate_chain/mod.rs index dda71e61ffb..07ce00ab5cb 100644 --- a/mithril-common/src/certificate_chain/mod.rs +++ b/mithril-common/src/certificate_chain/mod.rs @@ -3,16 +3,9 @@ mod certificate_genesis; mod certificate_retriever; mod certificate_verifier; -cfg_test_tools! { - mod fake_certificate_retriever; -} pub use certificate_genesis::CertificateGenesisProducer; pub use certificate_retriever::{CertificateRetriever, CertificateRetrieverError}; pub use certificate_verifier::{ CertificateVerifier, CertificateVerifierError, MithrilCertificateVerifier, }; - -cfg_test_tools! { - pub use fake_certificate_retriever::FakeCertificaterRetriever; -} diff --git a/mithril-common/src/crypto_helper/cardano/codec.rs b/mithril-common/src/crypto_helper/cardano/codec.rs index d0518619012..976c43757c9 100644 --- a/mithril-common/src/crypto_helper/cardano/codec.rs +++ b/mithril-common/src/crypto_helper/cardano/codec.rs @@ -180,7 +180,7 @@ impl<'a> TryFrom<&'a mut Sum6KesBytes> for Sum6Kes<'a> { #[cfg(test)] mod test { use super::*; - use crate::test_utils::TempDir; + use crate::test::TempDir; #[test] fn compat_with_shelly_format() { diff --git a/mithril-common/src/crypto_helper/cardano/kes/mod.rs b/mithril-common/src/crypto_helper/cardano/kes/mod.rs index b555fe2843f..eca6050728d 100644 --- a/mithril-common/src/crypto_helper/cardano/kes/mod.rs +++ b/mithril-common/src/crypto_helper/cardano/kes/mod.rs @@ -7,10 +7,3 @@ pub use error::*; pub use interface::*; pub use signer_with_key::*; pub use verifier_standard::*; - -cfg_test_tools! { - mod signer_fake; - pub mod tests_setup; - - pub use signer_fake::*; -} diff --git a/mithril-common/src/crypto_helper/cardano/kes/signer_with_key.rs b/mithril-common/src/crypto_helper/cardano/kes/signer_with_key.rs index c2c7122f3d2..95ef80fedc4 100644 --- a/mithril-common/src/crypto_helper/cardano/kes/signer_with_key.rs +++ b/mithril-common/src/crypto_helper/cardano/kes/signer_with_key.rs @@ -64,12 +64,9 @@ impl KesSigner for KesSignerStandard { mod tests { use super::*; - use crate::crypto_helper::cardano::kes::{ - KesVerifier, KesVerifierStandard, - tests_setup::{ - KesCryptographicMaterialForTest, KesPartyIndexForTest, - create_kes_cryptographic_material, - }, + use crate::crypto_helper::cardano::kes::{KesVerifier, KesVerifierStandard}; + use crate::test::crypto_helper::{ + KesCryptographicMaterialForTest, KesPartyIndexForTest, create_kes_cryptographic_material, }; #[test] diff --git a/mithril-common/src/crypto_helper/cardano/kes/verifier_standard.rs b/mithril-common/src/crypto_helper/cardano/kes/verifier_standard.rs index bba6abac0bc..da660bb22e9 100644 --- a/mithril-common/src/crypto_helper/cardano/kes/verifier_standard.rs +++ b/mithril-common/src/crypto_helper/cardano/kes/verifier_standard.rs @@ -47,12 +47,9 @@ impl KesVerifier for KesVerifierStandard { #[cfg(test)] mod tests { - use crate::crypto_helper::cardano::kes::{ - KesSigner, KesSignerStandard, - tests_setup::{ - KesCryptographicMaterialForTest, KesPartyIndexForTest, - create_kes_cryptographic_material, - }, + use crate::crypto_helper::cardano::kes::{KesSigner, KesSignerStandard}; + use crate::test::crypto_helper::{ + KesCryptographicMaterialForTest, KesPartyIndexForTest, create_kes_cryptographic_material, }; use super::*; diff --git a/mithril-common/src/crypto_helper/cardano/key_certification.rs b/mithril-common/src/crypto_helper/cardano/key_certification.rs index 5cbd057f275..f80bbebc378 100644 --- a/mithril-common/src/crypto_helper/cardano/key_certification.rs +++ b/mithril-common/src/crypto_helper/cardano/key_certification.rs @@ -214,13 +214,6 @@ impl StmInitializerWrapper { kes_signature, }) } - - cfg_test_tools! { - /// Override the protocol parameters of the `Initializer` for testing purposes only. - pub fn override_protocol_parameters(&mut self, protocol_parameters: &ProtocolParameters) { - self.stm_initializer.params = protocol_parameters.to_owned(); - } - } } /// Wrapper structure for [MithrilStm:KeyRegistration](mithril_stm::key_reg::KeyRegistration). @@ -299,16 +292,26 @@ impl KeyRegWrapper { } } +#[cfg(any(test, feature = "test_tools"))] +mod test_extensions { + use crate::test::crypto_helper::ProtocolInitializerTestExtension; + + use super::*; + + impl ProtocolInitializerTestExtension for StmInitializerWrapper { + fn override_protocol_parameters(&mut self, protocol_parameters: &ProtocolParameters) { + self.stm_initializer.params = protocol_parameters.to_owned(); + } + } +} + #[cfg(test)] mod test { - use crate::crypto_helper::cardano::kes::{ - KesSignerStandard, - tests_setup::{ - KesCryptographicMaterialForTest, KesPartyIndexForTest, - create_kes_cryptographic_material, - }, - }; + use crate::crypto_helper::cardano::kes::KesSignerStandard; use crate::crypto_helper::{OpCert, SerDeShelleyFileFormat}; + use crate::test::crypto_helper::{ + KesCryptographicMaterialForTest, KesPartyIndexForTest, create_kes_cryptographic_material, + }; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; diff --git a/mithril-common/src/crypto_helper/cardano/opcert.rs b/mithril-common/src/crypto_helper/cardano/opcert.rs index d2fbabfbf52..dd62c5c95e8 100644 --- a/mithril-common/src/crypto_helper/cardano/opcert.rs +++ b/mithril-common/src/crypto_helper/cardano/opcert.rs @@ -179,7 +179,7 @@ impl<'de> Deserialize<'de> for OpCert { mod tests { use super::*; use crate::crypto_helper::cardano::ColdKeyGenerator; - use crate::test_utils::TempDir; + use crate::test::TempDir; use kes_summed_ed25519::{kes::Sum6Kes, traits::KesSk}; use std::path::PathBuf; diff --git a/mithril-common/src/crypto_helper/conversions.rs b/mithril-common/src/crypto_helper/conversions.rs index 7d067635b51..c3b34b8addc 100644 --- a/mithril-common/src/crypto_helper/conversions.rs +++ b/mithril-common/src/crypto_helper/conversions.rs @@ -30,7 +30,7 @@ impl From<&entities::SignerWithStake> for (types::ProtocolPartyId, types::Protoc #[cfg(test)] pub mod tests { - use crate::test_utils::MithrilFixtureBuilder; + use crate::test::builder::MithrilFixtureBuilder; use super::*; diff --git a/mithril-common/src/crypto_helper/merkle_map.rs b/mithril-common/src/crypto_helper/merkle_map.rs index 55d757333cd..22c8bc9bb6c 100644 --- a/mithril-common/src/crypto_helper/merkle_map.rs +++ b/mithril-common/src/crypto_helper/merkle_map.rs @@ -468,6 +468,7 @@ mod tests { use crate::{ crypto_helper::MKTreeStoreInMemory, entities::{BlockNumber, BlockRange}, + test::entities_extensions::BlockRangeTestExtension, }; use super::*; diff --git a/mithril-common/src/crypto_helper/merkle_tree.rs b/mithril-common/src/crypto_helper/merkle_tree.rs index 9a63a0cc7b8..1a3bbc28b77 100644 --- a/mithril-common/src/crypto_helper/merkle_tree.rs +++ b/mithril-common/src/crypto_helper/merkle_tree.rs @@ -169,33 +169,6 @@ impl MKProof { .collect::>() } - cfg_test_tools! { - /// Build a [MKProof] based on the given leaves (*Test only*). - pub fn from_leaves + Clone>( - leaves: &[T], - ) -> StdResult { - Self::from_subset_of_leaves(leaves, leaves) - } - - /// Build a [MKProof] based on the given leaves (*Test only*). - pub fn from_subset_of_leaves + Clone>( - leaves: &[T], - leaves_to_verify: &[T], - ) -> StdResult { - let leaves = Self::list_to_mknode(leaves); - let leaves_to_verify = - Self::list_to_mknode(leaves_to_verify); - - let mktree = - MKTree::::new(&leaves).with_context(|| "MKTree creation should not fail")?; - mktree.compute_proof(&leaves_to_verify) - } - - fn list_to_mknode + Clone>(hashes: &[T]) -> Vec { - hashes.iter().map(|h| h.clone().into()).collect() - } - } - /// Convert the proof to bytes pub fn to_bytes(&self) -> StdResult { bincode::serde::encode_to_vec(self, bincode::config::standard()).map_err(|e| e.into()) @@ -465,6 +438,8 @@ impl Clone for MKTree { #[cfg(test)] mod tests { + use crate::test::crypto_helper::MKProofTestExtension; + use super::*; fn generate_leaves(total_leaves: usize) -> Vec { diff --git a/mithril-common/src/crypto_helper/mod.rs b/mithril-common/src/crypto_helper/mod.rs index 6ae2dc7615b..23b31c81e25 100644 --- a/mithril-common/src/crypto_helper/mod.rs +++ b/mithril-common/src/crypto_helper/mod.rs @@ -9,10 +9,6 @@ mod merkle_map; mod merkle_tree; mod types; -cfg_test_tools! { - pub mod tests_setup; -} - pub use cardano::ColdKeyGenerator; pub use cardano::{ @@ -20,9 +16,6 @@ pub use cardano::{ OpCert, ProtocolInitializerErrorWrapper, ProtocolRegistrationErrorWrapper, SerDeShelleyFileFormat, Sum6KesBytes, }; -cfg_test_tools! { - pub use cardano::KesSignerFake; -} pub use codec::*; pub use ed25519_alias::{era::*, genesis::*, manifest::*}; pub use merkle_map::{MKMap, MKMapKey, MKMapNode, MKMapProof, MKMapValue}; diff --git a/mithril-common/src/crypto_helper/types/protocol_key.rs b/mithril-common/src/crypto_helper/types/protocol_key.rs index 9900409eacf..aa4fed3961e 100644 --- a/mithril-common/src/crypto_helper/types/protocol_key.rs +++ b/mithril-common/src/crypto_helper/types/protocol_key.rs @@ -287,7 +287,7 @@ macro_rules! impl_codec_and_type_conversions_for_protocol_key { mod test { use crate::{ crypto_helper::ProtocolKey, - test_utils::{TempDir, fake_keys}, + test::{TempDir, double::fake_keys}, }; use mithril_stm::VerificationKeyProofOfPossession; use serde::{Deserialize, Serialize}; diff --git a/mithril-common/src/entities/block_range.rs b/mithril-common/src/entities/block_range.rs index 3bb09cc818a..c678dcdb902 100644 --- a/mithril-common/src/entities/block_range.rs +++ b/mithril-common/src/entities/block_range.rs @@ -27,33 +27,6 @@ impl BlockRange { /// Important: this value should be updated with extreme care (probably with an era change) in order to avoid signing disruptions. pub const LENGTH: BlockRangeLength = BlockNumber(15); - cfg_test_tools! { - /// BlockRange factory - pub fn new(start: u64, end: u64) -> Self { - Self { - inner_range: BlockNumber(start)..BlockNumber(end), - } - } - - /// Try to add two BlockRanges - pub fn try_add(&self, other: &BlockRange) -> StdResult { - if self.inner_range.end.max(other.inner_range.end) - < self.inner_range.start.min(other.inner_range.start) - { - return Err(anyhow!( - "BlockRange cannot be added as they don't strictly overlap" - )); - } - - Ok(Self { - inner_range: Range { - start: self.inner_range.start.min(other.inner_range.start), - end: self.inner_range.end.max(other.inner_range.end), - }, - }) - } - } - /// Get the start of the block range that contains the given block number pub fn start(number: BlockNumber) -> BlockNumber { Self::start_with_length(number, Self::LENGTH) @@ -228,10 +201,44 @@ impl ExactSizeIterator for BlockRangesSequence { } } +#[cfg(any(test, feature = "test_tools"))] +mod test_extensions { + use crate::test::entities_extensions::BlockRangeTestExtension; + + use super::*; + + impl BlockRangeTestExtension for BlockRange { + fn new(start: u64, end: u64) -> Self { + Self { + inner_range: BlockNumber(start)..BlockNumber(end), + } + } + + fn try_add(&self, other: &BlockRange) -> StdResult { + if self.inner_range.end.max(other.inner_range.end) + < self.inner_range.start.min(other.inner_range.start) + { + return Err(anyhow!( + "BlockRange cannot be added as they don't strictly overlap" + )); + } + + Ok(Self { + inner_range: Range { + start: self.inner_range.start.min(other.inner_range.start), + end: self.inner_range.end.max(other.inner_range.end), + }, + }) + } + } +} + #[cfg(test)] mod tests { use std::ops::Not; + use crate::test::entities_extensions::BlockRangeTestExtension; + use super::*; #[test] diff --git a/mithril-common/src/entities/cardano_transactions_set_proof.rs b/mithril-common/src/entities/cardano_transactions_set_proof.rs index 4ec4a1bbc07..4423d9f4339 100644 --- a/mithril-common/src/entities/cardano_transactions_set_proof.rs +++ b/mithril-common/src/entities/cardano_transactions_set_proof.rs @@ -4,12 +4,6 @@ use crate::entities::TransactionHash; use super::BlockRange; -cfg_test_tools! { - use crate::crypto_helper::{MKMap, MKTree, MKTreeNode, MKMapNode, MKTreeStorer, MKTreeStoreInMemory}; - use crate::entities::BlockNumber; - use std::collections::HashMap; -} - /// A cryptographic proof of a set of Cardano transactions is included in the global Cardano transactions set #[derive(Clone, Debug, PartialEq)] pub struct CardanoTransactionsSetProof { @@ -51,46 +45,14 @@ impl CardanoTransactionsSetProof { Ok(()) } - - cfg_test_tools! { - /// Helper to create a proof from a list of leaves - pub fn from_leaves(leaves: &[(BlockNumber, TransactionHash)]) -> StdResult { - let transactions_hashes: Vec = - leaves.iter().map(|(_, t)| t.into()).collect(); - let mut transactions_by_block_ranges: HashMap> = - HashMap::new(); - for (block_number, transaction_hash) in leaves { - let block_range = BlockRange::from_block_number(*block_number); - transactions_by_block_ranges - .entry(block_range) - .or_default() - .push(transaction_hash.to_owned()); - } - let mk_map = MKMap::<_, _, MKTreeStoreInMemory>::new( - transactions_by_block_ranges - .into_iter() - .try_fold( - vec![], - |mut acc, (block_range, transactions)| -> StdResult)>> { - acc.push((block_range, MKTree::::new(&transactions)?.into())); - Ok(acc) - }, - )? - .as_slice(), - )?; - let mk_leaves: Vec = transactions_hashes - .iter() - .map(|h| h.to_owned().into()) - .collect(); - let mk_proof = mk_map.compute_proof(&mk_leaves)?; - Ok(Self::new(transactions_hashes, mk_proof)) - } - - } } #[cfg(test)] mod tests { + use crate::crypto_helper::MKTreeStoreInMemory; + use crate::entities::BlockNumber; + use crate::test::entities_extensions::CardanoTransactionsSetProofTestExtension; + use super::*; #[test] diff --git a/mithril-common/src/entities/certificate.rs b/mithril-common/src/entities/certificate.rs index 5f98198b79a..7114941f552 100644 --- a/mithril-common/src/entities/certificate.rs +++ b/mithril-common/src/entities/certificate.rs @@ -163,16 +163,18 @@ impl Debug for Certificate { #[cfg(test)] mod tests { - use super::*; + use chrono::{DateTime, Duration, Utc}; + use crate::entities::SignedEntityType::CardanoStakeDistribution; use crate::{ entities::{ ProtocolMessagePartKey, ProtocolParameters, certificate_metadata::StakeDistributionParty, }, - test_utils::fake_keys, + test::double::fake_keys, }; - use chrono::{DateTime, Duration, Utc}; + + use super::*; fn get_parties() -> Vec { vec![ diff --git a/mithril-common/src/entities/mithril_stake_distribution.rs b/mithril-common/src/entities/mithril_stake_distribution.rs index b5a01c1d3a9..d9051200643 100644 --- a/mithril-common/src/entities/mithril_stake_distribution.rs +++ b/mithril-common/src/entities/mithril_stake_distribution.rs @@ -56,7 +56,7 @@ impl MithrilStakeDistribution { #[cfg(test)] mod tests { - use crate::test_utils::{MithrilFixtureBuilder, fake_data}; + use crate::test::{builder::MithrilFixtureBuilder, double::fake_data}; use super::*; diff --git a/mithril-common/src/entities/signed_entity_config.rs b/mithril-common/src/entities/signed_entity_config.rs index 641a1c66f78..e1e69f65ded 100644 --- a/mithril-common/src/entities/signed_entity_config.rs +++ b/mithril-common/src/entities/signed_entity_config.rs @@ -112,17 +112,6 @@ pub struct CardanoTransactionsSigningConfig { } impl CardanoTransactionsSigningConfig { - cfg_test_tools! { - /// Create a new CardanoTransactionsSigningConfig - pub fn new(security_parameter: BlockNumber, step: BlockNumber) -> Self { - Self { - security_parameter, - step, - } - } - - } - /// Compute the block number to be signed based on the chain tip block number. /// /// The latest block number to be signed is the highest multiple of the step less or equal than the @@ -157,7 +146,7 @@ mod tests { use crate::entities::{ CardanoDbBeacon, ChainPoint, Epoch, SignedEntityType, SlotNumber, TimePoint, }; - use crate::test_utils::{double::Dummy, fake_data}; + use crate::test::{double::Dummy, double::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 5f3c0ed82eb..d36ce7bca4f 100644 --- a/mithril-common/src/entities/signed_entity_type.rs +++ b/mithril-common/src/entities/signed_entity_type.rs @@ -248,7 +248,7 @@ Accepted values are (case-sensitive): {}."#, mod tests { use digest::Digest; - use crate::test_utils::assert_same_json; + use crate::test::assert_same_json; use super::*; diff --git a/mithril-common/src/entities/signer.rs b/mithril-common/src/entities/signer.rs index dbb4639b5c7..2f921d89130 100644 --- a/mithril-common/src/entities/signer.rs +++ b/mithril-common/src/entities/signer.rs @@ -264,7 +264,7 @@ impl Debug for SignerWithStake { #[cfg(test)] mod tests { - use crate::test_utils::{MithrilFixtureBuilder, fake_keys}; + use crate::test::{builder::MithrilFixtureBuilder, double::fake_keys}; use super::*; diff --git a/mithril-common/src/entities/single_signature.rs b/mithril-common/src/entities/single_signature.rs index 48e1b86ce19..dc5c411f9e7 100644 --- a/mithril-common/src/entities/single_signature.rs +++ b/mithril-common/src/entities/single_signature.rs @@ -62,34 +62,6 @@ impl SingleSignature { } } -cfg_test_tools! { -impl SingleSignature { - /// Create a fake [SingleSignature] with valid cryptographic data for testing purposes. - pub fn fake, TMessage: Into>(party_id: TPartyId, message: TMessage) -> Self { - use crate::entities::{ProtocolParameters}; - use crate::test_utils::{MithrilFixtureBuilder, StakeDistributionGenerationMethod}; - - let party_id = party_id.into(); - let message = message.into(); - - let fixture = MithrilFixtureBuilder::default() - .with_stake_distribution(StakeDistributionGenerationMethod::Custom( - std::collections::BTreeMap::from([(party_id.to_string(), 100)]), - )) - .with_protocol_parameters(ProtocolParameters::new(1, 1, 1.0)) - .build(); - let signature = fixture.signers_fixture()[0].sign(&message).unwrap(); - - Self { - party_id, - signature: signature.signature, - won_indexes: vec![10, 15], - authentication_status: SingleSignatureAuthenticationStatus::Unauthenticated, - } - } -} -} - impl Debug for SingleSignature { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let is_pretty_printing = f.alternate(); @@ -109,8 +81,9 @@ impl Debug for SingleSignature { #[cfg(test)] mod tests { + use crate::test::{builder::MithrilFixtureBuilder, crypto_helper::setup_message}; + use super::*; - use crate::{crypto_helper::tests_setup::setup_message, test_utils::MithrilFixtureBuilder}; #[test] fn single_signatures_should_convert_to_protocol_signatures() { diff --git a/mithril-common/src/entities/supported_era.rs b/mithril-common/src/entities/supported_era.rs index 60a42ac024a..e6d6f1fd746 100644 --- a/mithril-common/src/entities/supported_era.rs +++ b/mithril-common/src/entities/supported_era.rs @@ -23,7 +23,7 @@ impl SupportedEra { mod tests { use std::str::FromStr; - use crate::test_utils::double::Dummy; + use crate::test::double::Dummy; use super::*; diff --git a/mithril-common/src/lib.rs b/mithril-common/src/lib.rs index a8a7ebe3c04..b1973536571 100644 --- a/mithril-common/src/lib.rs +++ b/mithril-common/src/lib.rs @@ -9,16 +9,6 @@ //! - [certificate chain][certificate_chain] used to validate the Certificate Chain created by an aggregator //! - The [entities] used by, and exchanged between, the aggregator, signers and client. -macro_rules! cfg_test_tools { - ($($item:item)*) => { - $( - #[cfg(any(test, feature = "test_tools"))] - #[cfg_attr(docsrs, doc(cfg(feature = "test_tools")))] - $item - )* - } -} - pub mod api_version; pub mod certificate_chain; pub mod crypto_helper; @@ -28,9 +18,9 @@ pub mod messages; pub mod protocol; pub mod signable_builder; -cfg_test_tools! { - pub mod test_utils; -} +#[cfg(any(test, feature = "test_tools"))] +#[cfg_attr(docsrs, doc(cfg(feature = "test_tools")))] +pub mod test; pub use entities::{CardanoNetwork, MagicId}; diff --git a/mithril-common/src/logging.rs b/mithril-common/src/logging.rs index 3f74170fff7..69ead26deb3 100644 --- a/mithril-common/src/logging.rs +++ b/mithril-common/src/logging.rs @@ -36,7 +36,7 @@ fn component_name() -> &'static str { #[cfg(test)] mod tests { use super::*; - use crate::test_utils::TestLogger; + use crate::test::TestLogger; use slog::info; struct TestStruct; diff --git a/mithril-common/src/messages/cardano_transactions_proof.rs b/mithril-common/src/messages/cardano_transactions_proof.rs index a3b926b87bb..13e3d01389f 100644 --- a/mithril-common/src/messages/cardano_transactions_proof.rs +++ b/mithril-common/src/messages/cardano_transactions_proof.rs @@ -189,7 +189,9 @@ mod tests { CardanoTransactionsSignableBuilder, MockBlockRangeRootRetriever, MockTransactionsImporter, SignableBuilder, }; - use crate::test_utils::double::Dummy; + use crate::test::crypto_helper::MKProofTestExtension; + use crate::test::double::Dummy; + use crate::test::entities_extensions::CardanoTransactionsSetProofTestExtension; use super::*; diff --git a/mithril-common/src/messages/mithril_stake_distribution.rs b/mithril-common/src/messages/mithril_stake_distribution.rs index 7ba53c0f314..51d97f79659 100644 --- a/mithril-common/src/messages/mithril_stake_distribution.rs +++ b/mithril-common/src/messages/mithril_stake_distribution.rs @@ -31,7 +31,7 @@ pub struct MithrilStakeDistributionMessage { #[cfg(test)] mod tests { - use crate::test_utils::fake_data; + use crate::test::double::fake_data; use super::*; diff --git a/mithril-common/src/messages/snapshot.rs b/mithril-common/src/messages/snapshot.rs index ff6ba8abcaa..065656e4881 100644 --- a/mithril-common/src/messages/snapshot.rs +++ b/mithril-common/src/messages/snapshot.rs @@ -52,7 +52,7 @@ impl SnapshotMessage { #[cfg(test)] mod tests { use crate::entities::Epoch; - use crate::test_utils::double::Dummy; + use crate::test::double::Dummy; use super::*; diff --git a/mithril-common/src/protocol/multi_signer.rs b/mithril-common/src/protocol/multi_signer.rs index 1965edd2b70..913b5d6caf7 100644 --- a/mithril-common/src/protocol/multi_signer.rs +++ b/mithril-common/src/protocol/multi_signer.rs @@ -94,8 +94,10 @@ mod test { use crate::{ entities::{ProtocolMessage, ProtocolMessagePartKey, ProtocolParameters}, protocol::SignerBuilder, - test_utils::fake_keys, - test_utils::{MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod}, + test::{ + builder::{MithrilFixture, MithrilFixtureBuilder, StakeDistributionGenerationMethod}, + double::fake_keys, + }, }; use super::*; diff --git a/mithril-common/src/protocol/signer_builder.rs b/mithril-common/src/protocol/signer_builder.rs index 1eece99c56d..e6c9c9f448d 100644 --- a/mithril-common/src/protocol/signer_builder.rs +++ b/mithril-common/src/protocol/signer_builder.rs @@ -178,7 +178,7 @@ mod test { use crate::{ crypto_helper::{KesSignerStandard, ProtocolRegistrationErrorWrapper}, - test_utils::{MithrilFixtureBuilder, fake_data}, + test::{builder::MithrilFixtureBuilder, double::fake_data}, }; use super::*; @@ -207,7 +207,7 @@ mod test { let fixture_with_another_stake_distribution = MithrilFixtureBuilder::default() .with_signers(1) .with_stake_distribution( - crate::test_utils::StakeDistributionGenerationMethod::RandomDistribution { + crate::test::builder::StakeDistributionGenerationMethod::RandomDistribution { seed: [4u8; 32], min_stake: 1, }, diff --git a/mithril-common/src/protocol/single_signer.rs b/mithril-common/src/protocol/single_signer.rs index f02be138e18..fd7d48711bf 100644 --- a/mithril-common/src/protocol/single_signer.rs +++ b/mithril-common/src/protocol/single_signer.rs @@ -53,7 +53,7 @@ mod test { crypto_helper::{KesSigner, KesSignerStandard}, entities::ProtocolMessage, protocol::SignerBuilder, - test_utils::MithrilFixtureBuilder, + test::builder::MithrilFixtureBuilder, }; #[test] diff --git a/mithril-common/src/signable_builder/cardano_transactions.rs b/mithril-common/src/signable_builder/cardano_transactions.rs index d7289169712..44fe538d676 100644 --- a/mithril-common/src/signable_builder/cardano_transactions.rs +++ b/mithril-common/src/signable_builder/cardano_transactions.rs @@ -96,7 +96,7 @@ mod tests { use crate::{ crypto_helper::MKTreeStoreInMemory, entities::CardanoTransaction, - test_utils::CardanoTransactionsBuilder, + test::builder::CardanoTransactionsBuilder, }; use super::*; diff --git a/mithril-common/src/signable_builder/signable_builder_service.rs b/mithril-common/src/signable_builder/signable_builder_service.rs index 8170689f619..2513f960cc4 100644 --- a/mithril-common/src/signable_builder/signable_builder_service.rs +++ b/mithril-common/src/signable_builder/signable_builder_service.rs @@ -181,7 +181,7 @@ mod tests { StdResult, entities::{BlockNumber, Epoch, ProtocolMessage}, signable_builder::{Beacon as Beaconnable, MockSignableSeedBuilder, SignableBuilder}, - test_utils::TestLogger, + test::TestLogger, }; use async_trait::async_trait; diff --git a/mithril-common/src/test_utils/dir_eq.rs b/mithril-common/src/test/assert/dir_eq.rs similarity index 96% rename from mithril-common/src/test_utils/dir_eq.rs rename to mithril-common/src/test/assert/dir_eq.rs index ea1c91d5278..59bb852bda8 100644 --- a/mithril-common/src/test_utils/dir_eq.rs +++ b/mithril-common/src/test/assert/dir_eq.rs @@ -139,7 +139,7 @@ impl From<&str> for DirStructure { /// /// Example: /// ```no_run -/// # use mithril_common::test_utils::assert_dir_eq; +/// # use mithril_common::test::assert_dir_eq; /// # use std::path::PathBuf; /// # let path = PathBuf::new(); /// assert_dir_eq!( @@ -155,11 +155,11 @@ impl From<&str> for DirStructure { #[macro_export] macro_rules! assert_dir_eq { ($dir: expr, $expected_structure: expr) => { - $crate::test_utils::assert_dir_eq!($dir, $expected_structure, ""); + $crate::test::assert_dir_eq!($dir, $expected_structure, ""); }; ($dir: expr, $expected_structure: expr, $($arg:tt)+) => { - let actual = $crate::test_utils::DirStructure::from_path($dir); - let expected = $crate::test_utils::DirStructure::from($expected_structure); + let actual = $crate::test::DirStructure::from_path($dir); + let expected = $crate::test::DirStructure::from($expected_structure); let comment = format!($($arg)+); assert!( actual == expected, @@ -177,7 +177,7 @@ pub use assert_dir_eq; mod tests { use std::fs::{File, create_dir}; - use crate::test_utils::temp_dir_create; + use crate::test::temp_dir_create; use super::*; diff --git a/mithril-common/src/test/assert/iters_equivalent.rs b/mithril-common/src/test/assert/iters_equivalent.rs new file mode 100644 index 00000000000..749d4325198 --- /dev/null +++ b/mithril-common/src/test/assert/iters_equivalent.rs @@ -0,0 +1,62 @@ +/// Compare two iterators ignoring the order +pub fn equivalent_to(a: I1, b: I2) -> bool +where + T: PartialEq + Ord, + I1: IntoIterator + Clone, + I2: IntoIterator + Clone, +{ + let a = as_sorted_vec(a); + let b = as_sorted_vec(b); + a == b +} + +/// Assert that two iterators are equivalent +#[macro_export] +macro_rules! assert_equivalent { + ($expected:expr, $actual:expr $(,)?) => {{ + let expected = $expected; + let actual = $actual; + assert_eq!( + $crate::test::as_sorted_vec(expected), + $crate::test::as_sorted_vec(actual) + ); + }}; +} +pub use assert_equivalent; + +/// Create a sorted clone of an iterable. +pub fn as_sorted_vec + Clone>(iter: I) -> Vec { + let mut list: Vec = iter.clone().into_iter().collect(); + list.sort(); + list +} + +#[cfg(test)] +mod tests { + use std::collections::HashSet; + + use super::*; + + #[test] + fn test_equivalent_to() { + assert!(equivalent_to(vec![1, 2, 3], vec![3, 2, 1])); + assert!(equivalent_to(vec![1, 2, 3], vec![2, 1, 3])); + assert!(!equivalent_to(vec![1, 2, 3], vec![3, 2, 1, 4])); + assert!(!equivalent_to(vec![1, 2, 3], vec![3, 2])); + + assert!(equivalent_to([1, 2, 3], vec![3, 2, 1])); + assert!(equivalent_to(&[1, 2, 3], &vec![3, 2, 1])); + assert!(equivalent_to([1, 2, 3], HashSet::from([3, 2, 1]))); + assert!(equivalent_to(vec![1, 2, 3], HashSet::from([3, 2, 1]))); + assert!(equivalent_to(&vec![1, 2, 3], &HashSet::from([3, 2, 1]))); + + assert_equivalent!(vec![1, 2, 3], vec![3, 2, 1]); + assert_equivalent!(vec![1, 2, 3], vec![2, 1, 3]); + + assert_equivalent!([1, 2, 3], vec![3, 2, 1]); + assert_equivalent!(&[1, 2, 3], &vec![3, 2, 1]); + assert_equivalent!([1, 2, 3], HashSet::from([3, 2, 1])); + assert_equivalent!(vec![1, 2, 3], HashSet::from([3, 2, 1])); + assert_equivalent!(&vec![1, 2, 3], &HashSet::from([3, 2, 1])); + } +} diff --git a/mithril-common/src/test/assert/json.rs b/mithril-common/src/test/assert/json.rs new file mode 100644 index 00000000000..f3c1f9f43a3 --- /dev/null +++ b/mithril-common/src/test/assert/json.rs @@ -0,0 +1,11 @@ +/// Compare two json strings ignoring keys order +#[macro_export] +macro_rules! assert_same_json { + ( $expected:expr, $actual:expr ) => { + assert_eq!( + serde_json::from_str::($expected).unwrap(), + serde_json::from_str::($actual).unwrap() + ) + }; +} +pub use assert_same_json; diff --git a/mithril-common/src/test/assert/mod.rs b/mithril-common/src/test/assert/mod.rs new file mode 100644 index 00000000000..9aefceb543c --- /dev/null +++ b/mithril-common/src/test/assert/mod.rs @@ -0,0 +1,7 @@ +mod dir_eq; +mod iters_equivalent; +mod json; + +pub use dir_eq::*; +pub use iters_equivalent::*; +pub use json::*; diff --git a/mithril-common/src/test_utils/cardano_transactions_builder.rs b/mithril-common/src/test/builder/cardano_transactions_builder.rs similarity index 98% rename from mithril-common/src/test_utils/cardano_transactions_builder.rs rename to mithril-common/src/test/builder/cardano_transactions_builder.rs index 94216c036b5..d5c6ec8fdcf 100644 --- a/mithril-common/src/test_utils/cardano_transactions_builder.rs +++ b/mithril-common/src/test/builder/cardano_transactions_builder.rs @@ -8,7 +8,7 @@ use crate::entities::{BlockNumber, BlockRange, CardanoTransaction, SlotNumber}; /// /// ``` /// use mithril_common::entities::{BlockNumber, CardanoTransaction, SlotNumber}; -/// use mithril_common::test_utils::CardanoTransactionsBuilder; +/// use mithril_common::test::builder::CardanoTransactionsBuilder; /// /// let txs = CardanoTransactionsBuilder::new() /// .max_transactions_per_block(3) @@ -35,7 +35,7 @@ use crate::entities::{BlockNumber, BlockRange, CardanoTransaction, SlotNumber}; /// /// ``` /// use mithril_common::entities::{BlockNumber, CardanoTransaction, SlotNumber}; -/// use mithril_common::test_utils::CardanoTransactionsBuilder; +/// use mithril_common::test::builder::CardanoTransactionsBuilder; /// /// let txs = CardanoTransactionsBuilder::new() /// .max_transactions_per_block(3) diff --git a/mithril-common/src/test_utils/certificate_chain_builder.rs b/mithril-common/src/test/builder/certificate_chain_builder.rs similarity index 98% rename from mithril-common/src/test_utils/certificate_chain_builder.rs rename to mithril-common/src/test/builder/certificate_chain_builder.rs index 9e121a84538..fcd6f15c8ec 100644 --- a/mithril-common/src/test_utils/certificate_chain_builder.rs +++ b/mithril-common/src/test/builder/certificate_chain_builder.rs @@ -14,7 +14,10 @@ use crate::{ CardanoDbBeacon, Certificate, CertificateMetadata, CertificateSignature, Epoch, ProtocolMessage, ProtocolMessagePartKey, SignedEntityType, }, - test_utils::{MithrilFixture, MithrilFixtureBuilder, SignerFixture, fake_data}, + test::{ + builder::{MithrilFixture, MithrilFixtureBuilder, SignerFixture}, + double::fake_data, + }, }; /// Genesis certificate processor function type. For tests only. @@ -169,7 +172,7 @@ impl CertificateChainFixture { /// /// ``` /// use mithril_common::crypto_helper::ProtocolParameters; -/// use mithril_common::test_utils::CertificateChainBuilder; +/// use mithril_common::test::builder::CertificateChainBuilder; /// /// let certificate_chain_fixture = CertificateChainBuilder::new() /// .with_total_certificates(5) @@ -184,7 +187,7 @@ impl CertificateChainFixture { /// ``` /// use std::cmp::min; /// use mithril_common::crypto_helper::ProtocolParameters; -/// use mithril_common::test_utils::CertificateChainBuilder; +/// use mithril_common::test::builder::CertificateChainBuilder; /// /// let certificate_chain_fixture = CertificateChainBuilder::new() /// .with_total_certificates(5) @@ -205,7 +208,7 @@ impl CertificateChainFixture { /// ``` /// use mithril_common::entities::Epoch; /// use mithril_common::crypto_helper::ProtocolParameters; -/// use mithril_common::test_utils::CertificateChainBuilder; +/// use mithril_common::test::builder::CertificateChainBuilder; /// /// let certificate_chain_fixture = CertificateChainBuilder::new() /// .with_total_certificates(5) @@ -1072,14 +1075,12 @@ mod test { #[test] fn get_latest_certificate() { - let chain_with_only_a_genesis = CertificateChainBuilder::new() - .with_total_certificates(1) - .build(); + let chain_with_only_a_genesis = + CertificateChainBuilder::new().with_total_certificates(1).build(); assert!(chain_with_only_a_genesis.latest_certificate().is_genesis()); - let chain_with_multiple_certificates = CertificateChainBuilder::new() - .with_total_certificates(10) - .build(); + let chain_with_multiple_certificates = + CertificateChainBuilder::new().with_total_certificates(10).build(); assert_eq!( chain_with_multiple_certificates.latest_certificate(), chain_with_multiple_certificates.first().unwrap() diff --git a/mithril-common/src/test_utils/fixture_builder.rs b/mithril-common/src/test/builder/fixture_builder.rs similarity index 97% rename from mithril-common/src/test_utils/fixture_builder.rs rename to mithril-common/src/test/builder/fixture_builder.rs index 715c3a60c3d..cccb8152d59 100644 --- a/mithril-common/src/test_utils/fixture_builder.rs +++ b/mithril-common/src/test/builder/fixture_builder.rs @@ -5,14 +5,15 @@ use rand_core::{RngCore, SeedableRng}; use crate::{ crypto_helper::{ ColdKeyGenerator, OpCert, ProtocolStakeDistribution, SerDeShelleyFileFormat, Sum6KesBytes, - tests_setup, tests_setup::setup_temp_directory_for_signer, }, entities::{PartyId, ProtocolParameters, Stake, StakeDistribution}, - test_utils::{fake_data, mithril_fixture::MithrilFixture}, + test::{ + builder::MithrilFixture, + crypto_helper, + double::{fake_data, precomputed_kes_key}, + }, }; -use super::precomputed_kes_key; - /// A builder of mithril types. pub struct MithrilFixtureBuilder { protocol_parameters: ProtocolParameters, @@ -95,7 +96,7 @@ impl MithrilFixtureBuilder { /// Transform the specified parameters to a [MithrilFixture]. pub fn build(self) -> MithrilFixture { let protocol_stake_distribution = self.generate_stake_distribution(); - let signers = tests_setup::setup_signers_from_stake_distribution( + let signers = crypto_helper::setup_signers_from_stake_distribution( &protocol_stake_distribution, &self.protocol_parameters.clone().into(), ); @@ -207,7 +208,7 @@ impl MithrilFixtureBuilder { let party_id = operational_certificate .compute_protocol_party_id() .expect("compute protocol party id should not fail"); - let temp_dir = setup_temp_directory_for_signer(&party_id, true) + let temp_dir = crypto_helper::setup_temp_directory_for_signer(&party_id, true) .expect("setup temp directory should return a value"); if !temp_dir.join("kes.sk").exists() { kes_bytes diff --git a/mithril-common/src/test_utils/mithril_fixture.rs b/mithril-common/src/test/builder/mithril_fixture.rs similarity index 99% rename from mithril-common/src/test_utils/mithril_fixture.rs rename to mithril-common/src/test/builder/mithril_fixture.rs index d82fbc885ee..e10515d35da 100644 --- a/mithril-common/src/test_utils/mithril_fixture.rs +++ b/mithril-common/src/test/builder/mithril_fixture.rs @@ -19,6 +19,7 @@ use crate::{ Signer, SignerWithStake, SingleSignature, Stake, StakeDistribution, StakeDistributionParty, }, protocol::{SignerBuilder, ToMessage}, + test::crypto_helper::ProtocolInitializerTestExtension, }; /// A fixture of Mithril data types. diff --git a/mithril-common/src/test/builder/mod.rs b/mithril-common/src/test/builder/mod.rs new file mode 100644 index 00000000000..ffe22ac0edf --- /dev/null +++ b/mithril-common/src/test/builder/mod.rs @@ -0,0 +1,16 @@ +//! Builders for test +//! +//! Enable easier creations of complex types for test purpose + +mod cardano_transactions_builder; +mod certificate_chain_builder; +mod fixture_builder; +mod mithril_fixture; + +pub use cardano_transactions_builder::CardanoTransactionsBuilder; +pub use certificate_chain_builder::{ + CertificateChainBuilder, CertificateChainBuilderContext, CertificateChainFixture, + CertificateChainingMethod, +}; +pub use fixture_builder::{MithrilFixtureBuilder, StakeDistributionGenerationMethod}; +pub use mithril_fixture::{MithrilFixture, SignerFixture}; diff --git a/mithril-common/src/test/crypto_helper/cardano/extensions.rs b/mithril-common/src/test/crypto_helper/cardano/extensions.rs new file mode 100644 index 00000000000..030dcbf9a70 --- /dev/null +++ b/mithril-common/src/test/crypto_helper/cardano/extensions.rs @@ -0,0 +1,44 @@ +use anyhow::Context; + +use crate::StdResult; +use crate::crypto_helper::{MKProof, MKTree, MKTreeNode, MKTreeStoreInMemory, ProtocolParameters}; + +/// Extension trait adding test utilities to [ProtocolInitializer][crate::crypto_helper::ProtocolInitializer] +pub trait ProtocolInitializerTestExtension { + /// `TEST ONLY` - Override the protocol parameters of the `Initializer` + fn override_protocol_parameters(&mut self, protocol_parameters: &ProtocolParameters); +} + +/// Extension trait adding test utilities to [MKProof] +pub trait MKProofTestExtension { + /// `TEST ONLY` - Build a [MKProof] based on the given leaves + fn from_leaves + Clone>(leaves: &[T]) -> StdResult; + + /// `TEST ONLY` - Build a [MKProof] based on the given leaves + fn from_subset_of_leaves + Clone>( + leaves: &[T], + leaves_to_verify: &[T], + ) -> StdResult; +} + +impl MKProofTestExtension for MKProof { + fn from_leaves + Clone>(leaves: &[T]) -> StdResult { + Self::from_subset_of_leaves(leaves, leaves) + } + + fn from_subset_of_leaves + Clone>( + leaves: &[T], + leaves_to_verify: &[T], + ) -> StdResult { + fn list_to_mknode + Clone>(hashes: &[T]) -> Vec { + hashes.iter().map(|h| h.clone().into()).collect() + } + + let leaves = list_to_mknode(leaves); + let leaves_to_verify = list_to_mknode(leaves_to_verify); + + let mktree = MKTree::::new(&leaves) + .with_context(|| "MKTree creation should not fail")?; + mktree.compute_proof(&leaves_to_verify) + } +} diff --git a/mithril-common/src/test/crypto_helper/cardano/kes/mod.rs b/mithril-common/src/test/crypto_helper/cardano/kes/mod.rs new file mode 100644 index 00000000000..c285e58225d --- /dev/null +++ b/mithril-common/src/test/crypto_helper/cardano/kes/mod.rs @@ -0,0 +1,5 @@ +mod setup; +mod signer_fake; + +pub(crate) use setup::*; +pub use signer_fake::*; diff --git a/mithril-common/src/crypto_helper/cardano/kes/tests_setup.rs b/mithril-common/src/test/crypto_helper/cardano/kes/setup.rs similarity index 93% rename from mithril-common/src/crypto_helper/cardano/kes/tests_setup.rs rename to mithril-common/src/test/crypto_helper/cardano/kes/setup.rs index a5fad24097b..1e46905d8dc 100644 --- a/mithril-common/src/crypto_helper/cardano/kes/tests_setup.rs +++ b/mithril-common/src/test/crypto_helper/cardano/kes/setup.rs @@ -3,8 +3,9 @@ use std::{fs, path::PathBuf}; use kes_summed_ed25519::kes::Sum6Kes; use kes_summed_ed25519::traits::KesSk; -use crate::crypto_helper::{KesPeriod, ProtocolPartyId, SerDeShelleyFileFormat, Sum6KesBytes}; -use crate::crypto_helper::{OpCert, cardano::ColdKeyGenerator}; +use crate::crypto_helper::{ + ColdKeyGenerator, KesPeriod, OpCert, ProtocolPartyId, SerDeShelleyFileFormat, Sum6KesBytes, +}; /// A type alias for the party index used in KES cryptographic material. pub type KesPartyIndexForTest = u64; diff --git a/mithril-common/src/crypto_helper/cardano/kes/signer_fake.rs b/mithril-common/src/test/crypto_helper/cardano/kes/signer_fake.rs similarity index 91% rename from mithril-common/src/crypto_helper/cardano/kes/signer_fake.rs rename to mithril-common/src/test/crypto_helper/cardano/kes/signer_fake.rs index bc1d0c1c03e..5a76f7c1ad3 100644 --- a/mithril-common/src/crypto_helper/cardano/kes/signer_fake.rs +++ b/mithril-common/src/test/crypto_helper/cardano/kes/signer_fake.rs @@ -5,15 +5,9 @@ use std::sync::Mutex; use crate::{ StdResult, - crypto_helper::{ - KesPeriod, KesSigner, OpCert, - cardano::kes::{ - KesSignerStandard, - tests_setup::{ - KesCryptographicMaterialForTest, KesPartyIndexForTest, - create_kes_cryptographic_material, - }, - }, + crypto_helper::{KesPeriod, KesSigner, KesSignerStandard, OpCert}, + test::crypto_helper::{ + KesCryptographicMaterialForTest, KesPartyIndexForTest, create_kes_cryptographic_material, }, }; diff --git a/mithril-common/src/test/crypto_helper/cardano/mod.rs b/mithril-common/src/test/crypto_helper/cardano/mod.rs new file mode 100644 index 00000000000..2bfee2ee99b --- /dev/null +++ b/mithril-common/src/test/crypto_helper/cardano/mod.rs @@ -0,0 +1,5 @@ +mod extensions; +mod kes; + +pub use extensions::*; +pub use kes::*; diff --git a/mithril-common/src/test/crypto_helper/mod.rs b/mithril-common/src/test/crypto_helper/mod.rs new file mode 100644 index 00000000000..386d3533169 --- /dev/null +++ b/mithril-common/src/test/crypto_helper/mod.rs @@ -0,0 +1,7 @@ +//! Test utilities for Mithril STM types + +mod cardano; +mod setup; + +pub use cardano::*; +pub use setup::*; diff --git a/mithril-common/src/crypto_helper/tests_setup.rs b/mithril-common/src/test/crypto_helper/setup.rs similarity index 94% rename from mithril-common/src/crypto_helper/tests_setup.rs rename to mithril-common/src/test/crypto_helper/setup.rs index a2a8eefb6c7..72450ce5f72 100644 --- a/mithril-common/src/crypto_helper/tests_setup.rs +++ b/mithril-common/src/test/crypto_helper/setup.rs @@ -5,13 +5,18 @@ use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; use crate::{ - crypto_helper::{KesSigner, cardano::KesSignerStandard}, + crypto_helper::{ + KesSigner, KesSignerStandard, OpCert, ProtocolInitializer, ProtocolKeyRegistration, + ProtocolOpCert, ProtocolParameters, ProtocolPartyId, ProtocolStakeDistribution, + SerDeShelleyFileFormat, + }, entities::{ProtocolMessage, ProtocolMessagePartKey, SignerWithStake, Stake}, - test_utils::{CertificateChainBuilder, CertificateChainFixture, SignerFixture, TempDir}, + test::{ + TempDir, + builder::{CertificateChainBuilder, CertificateChainFixture, SignerFixture}, + }, }; -use super::{OpCert, SerDeShelleyFileFormat, types::*}; - /// Create or retrieve a temporary directory for storing cryptographic material for a signer, use this for tests only. pub fn setup_temp_directory_for_signer( party_id: &ProtocolPartyId, diff --git a/mithril-common/src/test/double/api_version.rs b/mithril-common/src/test/double/api_version.rs new file mode 100644 index 00000000000..d1455dfd84f --- /dev/null +++ b/mithril-common/src/test/double/api_version.rs @@ -0,0 +1,29 @@ +use crate::api_version::ApiVersionDiscriminantSource; + +/// A dummy implementation of the `ApiVersionDiscriminantSource` trait for testing purposes. +pub struct DummyApiVersionDiscriminantSource { + discriminant: String, +} + +impl DummyApiVersionDiscriminantSource { + /// Create a new instance of `DummyApiVersionDiscriminantSource` with the given discriminant. + pub fn new>(discrimant: T) -> Self { + Self { + discriminant: discrimant.into(), + } + } +} + +impl Default for DummyApiVersionDiscriminantSource { + fn default() -> Self { + Self { + discriminant: "dummy".to_string(), + } + } +} + +impl ApiVersionDiscriminantSource for DummyApiVersionDiscriminantSource { + fn get_discriminant(&self) -> String { + self.discriminant.clone() + } +} diff --git a/mithril-common/src/certificate_chain/fake_certificate_retriever.rs b/mithril-common/src/test/double/certificate_retriever.rs similarity index 91% rename from mithril-common/src/certificate_chain/fake_certificate_retriever.rs rename to mithril-common/src/test/double/certificate_retriever.rs index e92e74a0654..3e4c6281416 100644 --- a/mithril-common/src/certificate_chain/fake_certificate_retriever.rs +++ b/mithril-common/src/test/double/certificate_retriever.rs @@ -6,10 +6,9 @@ use async_trait::async_trait; use std::collections::HashMap; use tokio::sync::RwLock; +use crate::certificate_chain::{CertificateRetriever, CertificateRetrieverError}; use crate::entities::Certificate; -use super::{CertificateRetriever, CertificateRetrieverError}; - /// A fake [CertificateRetriever] that returns a [Certificate] given its hash pub struct FakeCertificaterRetriever { certificates_map: RwLock>, @@ -28,7 +27,8 @@ impl FakeCertificaterRetriever { } } -#[async_trait] +#[cfg_attr(target_family = "wasm", async_trait(?Send))] +#[cfg_attr(not(target_family = "wasm"), async_trait)] impl CertificateRetriever for FakeCertificaterRetriever { async fn get_certificate_details( &self, @@ -44,7 +44,7 @@ impl CertificateRetriever for FakeCertificaterRetriever { #[cfg(test)] mod tests { - use crate::test_utils::fake_data; + use crate::test::double::fake_data; use super::*; diff --git a/mithril-common/src/test_utils/double/dummies.rs b/mithril-common/src/test/double/dummies.rs similarity index 99% rename from mithril-common/src/test_utils/double/dummies.rs rename to mithril-common/src/test/double/dummies.rs index f4ea1c42fc0..1a3b0ed6733 100644 --- a/mithril-common/src/test_utils/double/dummies.rs +++ b/mithril-common/src/test/double/dummies.rs @@ -1,10 +1,11 @@ use chrono::{DateTime, Utc}; -use crate::test_utils::{double::Dummy, fake_data, fake_keys}; +use crate::test::double::{Dummy, fake_data, fake_keys}; mod entities { use crate::crypto_helper::MKTreeStoreInMemory; use crate::entities::*; + use crate::test::entities_extensions::CardanoTransactionsSetProofTestExtension; use super::*; @@ -477,8 +478,6 @@ mod messages { 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(), diff --git a/mithril-common/src/test_utils/fake_data.rs b/mithril-common/src/test/double/fake_data.rs similarity index 99% rename from mithril-common/src/test_utils/fake_data.rs rename to mithril-common/src/test/double/fake_data.rs index a19084a5950..3bb4cab4e3f 100644 --- a/mithril-common/src/test_utils/fake_data.rs +++ b/mithril-common/src/test/double/fake_data.rs @@ -11,7 +11,7 @@ use crate::entities::{ ImmutablesLocations, LotteryIndex, ProtocolMessage, ProtocolMessagePartKey, SignedEntityType, SingleSignature, SlotNumber, StakeDistribution, StakeDistributionParty, }; -use crate::test_utils::{MithrilFixtureBuilder, double::Dummy}; +use crate::test::{builder::MithrilFixtureBuilder, double::Dummy}; use super::fake_keys; diff --git a/mithril-common/src/test_utils/fake_keys.rs b/mithril-common/src/test/double/fake_keys.rs similarity index 100% rename from mithril-common/src/test_utils/fake_keys.rs rename to mithril-common/src/test/double/fake_keys.rs diff --git a/mithril-common/src/test_utils/double/mod.rs b/mithril-common/src/test/double/mod.rs similarity index 78% rename from mithril-common/src/test_utils/double/mod.rs rename to mithril-common/src/test/double/mod.rs index 4563ec8d91b..31fe8acc671 100644 --- a/mithril-common/src/test_utils/double/mod.rs +++ b/mithril-common/src/test/double/mod.rs @@ -2,7 +2,15 @@ //! //! Enable unit testing with controlled inputs and predictable behavior. +mod api_version; +mod certificate_retriever; mod dummies; +pub mod fake_data; +pub mod fake_keys; +pub(super) mod precomputed_kes_key; + +pub use api_version::DummyApiVersionDiscriminantSource; +pub use certificate_retriever::FakeCertificaterRetriever; /// A trait for giving a type a dummy value. /// @@ -15,7 +23,7 @@ mod dummies; /// /// # Example /// ``` -/// use mithril_common::test_utils::double::Dummy; +/// use mithril_common::test::double::Dummy; /// /// struct MyType(String); /// diff --git a/mithril-common/src/test_utils/precomputed_kes_key.rs b/mithril-common/src/test/double/precomputed_kes_key.rs similarity index 99% rename from mithril-common/src/test_utils/precomputed_kes_key.rs rename to mithril-common/src/test/double/precomputed_kes_key.rs index 5be629dc043..daf56948a97 100644 --- a/mithril-common/src/test_utils/precomputed_kes_key.rs +++ b/mithril-common/src/test/double/precomputed_kes_key.rs @@ -1,5 +1,5 @@ -/// If there is a need to update this data, we can run the `verify_kes_key_cache_content` test in `fixture_builder.rs` -/// which generates the code of this function. +/// If there is a need to update this data, we can run the `verify_kes_key_cache_content` test in +/// `test::builder::fixture_builder.rs` which generates the code of this function. pub fn cached_kes_key(kes_key_seed: &[u8]) -> Option<([u8; 612], [u8; 32])> { let (kes_bytes, kes_verification_key) = match kes_key_seed { [ diff --git a/mithril-common/src/test/entities_extensions.rs b/mithril-common/src/test/entities_extensions.rs new file mode 100644 index 00000000000..898b43b1c7e --- /dev/null +++ b/mithril-common/src/test/entities_extensions.rs @@ -0,0 +1,100 @@ +//! A set of extension traits to add test utilities to this crate `entities` + +use std::collections::HashMap; + +use crate::StdResult; +use crate::crypto_helper::{ + MKMap, MKMapNode, MKTree, MKTreeNode, MKTreeStoreInMemory, MKTreeStorer, +}; +use crate::entities::{ + BlockNumber, BlockRange, CardanoTransactionsSetProof, ProtocolParameters, SingleSignature, + SingleSignatureAuthenticationStatus, TransactionHash, +}; +use crate::test::builder::{MithrilFixtureBuilder, StakeDistributionGenerationMethod}; + +/// Extension trait adding test utilities to [BlockRange] +pub trait BlockRangeTestExtension { + /// `TEST ONLY` - BlockRange factory + fn new(start: u64, end: u64) -> Self; + + /// `TEST ONLY` - Try to add two BlockRanges + fn try_add(&self, other: &BlockRange) -> StdResult; +} + +/// Extension trait adding test utilities to [CardanoTransactionsSetProof] +pub trait CardanoTransactionsSetProofTestExtension { + /// `TEST ONLY` - Helper to create a proof from a list of leaves + fn from_leaves( + leaves: &[(BlockNumber, TransactionHash)], + ) -> StdResult; +} + +impl CardanoTransactionsSetProofTestExtension for CardanoTransactionsSetProof { + fn from_leaves( + leaves: &[(BlockNumber, TransactionHash)], + ) -> StdResult { + let transactions_hashes: Vec = + leaves.iter().map(|(_, t)| t.into()).collect(); + let mut transactions_by_block_ranges: HashMap> = + HashMap::new(); + for (block_number, transaction_hash) in leaves { + let block_range = BlockRange::from_block_number(*block_number); + transactions_by_block_ranges + .entry(block_range) + .or_default() + .push(transaction_hash.to_owned()); + } + let mk_map = MKMap::<_, _, MKTreeStoreInMemory>::new( + transactions_by_block_ranges + .into_iter() + .try_fold( + vec![], + |mut acc, + (block_range, transactions)| + -> StdResult)>> { + acc.push((block_range, MKTree::::new(&transactions)?.into())); + Ok(acc) + }, + )? + .as_slice(), + )?; + let mk_leaves: Vec = + transactions_hashes.iter().map(|h| h.to_owned().into()).collect(); + let mk_proof = mk_map.compute_proof(&mk_leaves)?; + Ok(Self::new(transactions_hashes, mk_proof)) + } +} + +/// Extension trait adding test utilities to [SingleSignature] +pub trait SingleSignatureTestExtension { + /// `TEST ONLY` - Create a fake [SingleSignature] with valid cryptographic data for testing purposes. + fn fake, TMessage: Into>( + party_id: TPartyId, + message: TMessage, + ) -> SingleSignature; +} + +impl SingleSignatureTestExtension for SingleSignature { + fn fake, TMessage: Into>( + party_id: TPartyId, + message: TMessage, + ) -> SingleSignature { + let party_id = party_id.into(); + let message = message.into(); + + let fixture = MithrilFixtureBuilder::default() + .with_stake_distribution(StakeDistributionGenerationMethod::Custom( + std::collections::BTreeMap::from([(party_id.to_string(), 100)]), + )) + .with_protocol_parameters(ProtocolParameters::new(1, 1, 1.0)) + .build(); + let signature = fixture.signers_fixture()[0].sign(&message).unwrap(); + + Self { + party_id, + signature: signature.signature, + won_indexes: vec![10, 15], + authentication_status: SingleSignatureAuthenticationStatus::Unauthenticated, + } + } +} diff --git a/mithril-common/src/test_utils/memory_logger.rs b/mithril-common/src/test/logging/memory_logger.rs similarity index 100% rename from mithril-common/src/test_utils/memory_logger.rs rename to mithril-common/src/test/logging/memory_logger.rs diff --git a/mithril-common/src/test/logging/mod.rs b/mithril-common/src/test/logging/mod.rs new file mode 100644 index 00000000000..ad61344989a --- /dev/null +++ b/mithril-common/src/test/logging/mod.rs @@ -0,0 +1,56 @@ +//! Logging utilities for tests +//! +mod memory_logger; + +pub use memory_logger::*; + +/// Creates a test-specific `TestLogger` struct that can creates preconfigured logger instances. +/// +/// This macro avoids direct `slog_async` and `slog_term` dependencies in library crates +/// by letting dependents add them as `dev-dependencies` only. +/// +/// ## Methods +/// +/// - `TestLogger::stdout()` - Logger that outputs to stdout. +/// - `TestLogger::memory()` - Logger that stores messages in memory for inspection. +/// Returns `(Logger, MemoryDrainForTestInspector)` tuple +/// +/// Requires: `slog`, `slog_async`, `slog_term` +#[macro_export] +macro_rules! define_test_logger { + () => { + #[cfg(test)] + pub(crate) struct TestLogger; + + #[cfg(test)] + mod test_logger_impl { + use std::io; + use std::sync::Arc; + + use slog::{Drain, Logger}; + use slog_async::Async; + use slog_term::{CompactFormat, PlainDecorator}; + + use $crate::test::logging::{MemoryDrainForTest, MemoryDrainForTestInspector}; + + impl super::TestLogger { + fn from_writer(writer: W) -> Logger { + let decorator = PlainDecorator::new(writer); + let drain = CompactFormat::new(decorator).build().fuse(); + let drain = Async::new(drain).build().fuse(); + Logger::root(Arc::new(drain), slog::o!()) + } + + pub(crate) fn stdout() -> Logger { + Self::from_writer(slog_term::TestStdoutWriter) + } + + pub(crate) fn memory() -> (Logger, MemoryDrainForTestInspector) { + let (drain, inspector) = MemoryDrainForTest::new(); + (Logger::root(drain.fuse(), slog::o!()), inspector) + } + } + } + }; +} +pub use define_test_logger; diff --git a/mithril-common/src/test_utils/mock_extensions.rs b/mithril-common/src/test/mock_extensions.rs similarity index 96% rename from mithril-common/src/test_utils/mock_extensions.rs rename to mithril-common/src/test/mock_extensions.rs index 26a858a9208..ce1d72d4d43 100644 --- a/mithril-common/src/test_utils/mock_extensions.rs +++ b/mithril-common/src/test/mock_extensions.rs @@ -17,7 +17,7 @@ impl MockBuilder { /// /// The type must be specified either: /// ``` - /// use mithril_common::test_utils::mock_extensions::MockBuilder; + /// use mithril_common::test::mock_extensions::MockBuilder; /// # #[derive(Default)] struct MockType {}; /// /// // from the builder generic diff --git a/mithril-common/src/test/mod.rs b/mithril-common/src/test/mod.rs new file mode 100644 index 00000000000..922ca2f5779 --- /dev/null +++ b/mithril-common/src/test/mod.rs @@ -0,0 +1,142 @@ +//! Test utilities +//! +//! A collection of testing utilities and helpers: +//! +//! * `assert`: Custom assertions for comparing directory structures, iterables, JSON strings and more +//! * `builder`: Test data builders and fixtures +//! * `crypto_helper`: Cryptographic utilities for testing +//! * `double`: Test doubles (mocks, fakes, dummies, ...) +//! * `entities_extensions`: Extension traits adding test-specific methods for [crate::entities] +//! * `logging`: Test logging infrastructure +//! * `mock_extensions`: Additional mocking utilities +//! * `temp_dir`: Temporary directory management for tests +//! + +pub mod builder; +pub mod crypto_helper; +pub mod double; +pub mod entities_extensions; +pub mod logging; +pub mod mock_extensions; + +mod assert; +mod temp_dir; + +pub use assert::*; +pub use temp_dir::*; + +#[cfg(test)] +logging::define_test_logger!(); + +/// Return the path of the given function. +/// If the last function is `f`, it is removed. +/// The last `{{closure}}` is also removed. +pub fn format_current_function_module(f: T) -> &'static str { + fn type_name_of(_: T) -> &'static str { + std::any::type_name::() + } + + let name = type_name_of(f); + let name = name.strip_suffix("::f").unwrap_or(name); + name.strip_suffix("::{{closure}}").unwrap_or(name) +} + +/// Return a string representing the path of the given function. +pub fn format_current_function_path(f: T) -> String { + let name = format_current_function_module(f); + name.replace("::", "/") +} + +/// Returns the name of the function that called this macro. +#[macro_export] +macro_rules! current_function { + () => {{ + fn f() {} + let name = $crate::test::format_current_function_module(f); + // The index found is the beginning of the '..', this is why we add 2. + let function_name_index = name.rfind("::").map(|index| index + 2).unwrap_or(0); + + &name[function_name_index..] + }}; +} +pub use current_function; + +/// Returns the path of the function that called this macro. +#[macro_export] +macro_rules! current_function_path { + () => {{ + fn f() {} + + std::path::PathBuf::from($crate::test::format_current_function_path(f)) + }}; +} +pub use current_function_path; + +#[cfg(test)] +mod utils { + use std::path::Path; + + use super::*; + + #[test] + fn test_current_function_extract_function_name() { + let name = current_function!(); + + assert_eq!("test_current_function_extract_function_name", name); + } + + #[tokio::test] + async fn test_current_function_extract_async_function_name() { + let name = current_function!(); + + assert_eq!("test_current_function_extract_async_function_name", name); + } + + #[test] + fn test_format_function_path_from_given_function() { + assert_eq!( + "mithril_common/test/utils/test_format_function_path_from_given_function", + format_current_function_path(test_format_function_path_from_given_function) + ); + } + + #[test] + fn test_format_function_path_from_given_pseudo_function_f() { + fn f() {} + assert_eq!( + "mithril_common/test/utils/test_format_function_path_from_given_pseudo_function_f", + format_current_function_path(f) + ); + } + + #[tokio::test] + async fn test_format_function_path_from_given_async_function_f() { + fn f() {} + assert_eq!( + "mithril_common/test/utils/test_format_function_path_from_given_async_function_f", + format_current_function_path(f) + ); + } + + #[test] + fn test_build_current_function_path_using_macros() { + assert_eq!( + Path::new("mithril_common") + .join("test") + .join("utils") + .join("test_build_current_function_path_using_macros"), + current_function_path!() + ); + } + + #[tokio::test] + async fn test_build_current_async_function_path_using_macros() { + assert_eq!( + Path::new("mithril_common") + .join("test") + .join("utils") + .join("test_build_current_async_function_path_using_macros"), + current_function_path!() + ); + } +} diff --git a/mithril-common/src/test_utils/temp_dir.rs b/mithril-common/src/test/temp_dir.rs similarity index 94% rename from mithril-common/src/test_utils/temp_dir.rs rename to mithril-common/src/test/temp_dir.rs index 1f06939c43c..f0f90c5723f 100644 --- a/mithril-common/src/test_utils/temp_dir.rs +++ b/mithril-common/src/test/temp_dir.rs @@ -82,7 +82,7 @@ impl TempDir { /// /// Equivalent to: /// ``` - /// # use crate::mithril_common::test_utils::TempDir; + /// # use crate::mithril_common::test::TempDir; /// TempDir::new("module", "name").build(); /// ``` pub fn create, N: Into>(module: M, name: N) -> PathBuf { @@ -94,7 +94,7 @@ impl TempDir { /// /// Equivalent to: /// ``` - /// # use crate::mithril_common::test_utils::TempDir; + /// # use crate::mithril_common::test::TempDir; /// TempDir::new("module", "name").generate_shorter_path().build(); /// ``` pub fn create_with_short_path, N: Into>(module: M, name: N) -> PathBuf { @@ -117,10 +117,10 @@ impl TempDir { macro_rules! temp_dir { () => {{ fn f() {} - let current_function_path = $crate::test_utils::format_current_function_path(f); + let current_function_path = $crate::test::format_current_function_path(f); let current_function_path = current_function_path.replace("/tests/", "/"); - $crate::test_utils::TempDir::new(current_function_path, "").build_path() + $crate::test::TempDir::new(current_function_path, "").build_path() }}; } pub use temp_dir; @@ -130,10 +130,10 @@ pub use temp_dir; macro_rules! temp_dir_create { () => {{ fn f() {} - let current_function_path = $crate::test_utils::format_current_function_path(f); + let current_function_path = $crate::test::format_current_function_path(f); let current_function_path = current_function_path.replace("/tests/", "/"); - $crate::test_utils::TempDir::new(current_function_path, "").build() + $crate::test::TempDir::new(current_function_path, "").build() }}; } pub use temp_dir_create; @@ -258,7 +258,7 @@ mod tests { std::env::temp_dir() .join(TEMP_DIR_ROOT_NAME) .join("mithril_common") - .join("test_utils") + .join("test") .join("temp_dir") .join("creating_temp_dir_base_on_current_function"), temp_dir!(), @@ -271,7 +271,7 @@ mod tests { std::env::temp_dir() .join(TEMP_DIR_ROOT_NAME) .join("mithril_common") - .join("test_utils") + .join("test") .join("temp_dir") .join("creating_temp_dir_base_on_current_async_function"), temp_dir!(), diff --git a/mithril-common/src/test_utils/mod.rs b/mithril-common/src/test_utils/mod.rs deleted file mode 100644 index ff6e9311610..00000000000 --- a/mithril-common/src/test_utils/mod.rs +++ /dev/null @@ -1,251 +0,0 @@ -//! Test utilities -//! -//! They contains: -//! * A Open Api Spec tester -//! * Some precomputed fake data and keys -//! * 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; - -mod cardano_transactions_builder; -mod certificate_chain_builder; -mod dir_eq; -mod fixture_builder; -mod memory_logger; -mod mithril_fixture; -mod precomputed_kes_key; -mod temp_dir; - -pub use cardano_transactions_builder::CardanoTransactionsBuilder; -pub use certificate_chain_builder::{ - CertificateChainBuilder, CertificateChainBuilderContext, CertificateChainFixture, - CertificateChainingMethod, -}; -pub use dir_eq::*; -pub use fixture_builder::{MithrilFixtureBuilder, StakeDistributionGenerationMethod}; -pub use memory_logger::*; -pub use mithril_fixture::{MithrilFixture, SignerFixture}; -pub use temp_dir::*; -#[cfg(test)] -pub(crate) use utils::*; - -/// Compare two json strings ignoring keys order -#[macro_export] -macro_rules! assert_same_json { - ( $expected:expr, $actual:expr ) => { - assert_eq!( - serde_json::from_str::($expected).unwrap(), - serde_json::from_str::($actual).unwrap() - ) - }; -} -pub use assert_same_json; - -/// Compare two iterators ignoring the order -pub fn equivalent_to(a: I1, b: I2) -> bool -where - T: PartialEq + Ord, - I1: IntoIterator + Clone, - I2: IntoIterator + Clone, -{ - let a = as_sorted_vec(a); - let b = as_sorted_vec(b); - a == b -} - -/// Assert that two iterators are equivalent -pub fn assert_equivalent(a: I1, b: I2) -where - T: PartialEq + Ord + std::fmt::Debug, - I1: IntoIterator + Clone, - I2: IntoIterator + Clone, -{ - let a = as_sorted_vec(a); - let b = as_sorted_vec(b); - assert_eq!(a, b); -} - -/// Assert that two iterators are equivalent -#[macro_export] -macro_rules! assert_equivalent_macro { - ( $expected:expr, $actual:expr ) => {{ - let expected = $crate::test_utils::as_sorted_vec($expected); - let actual = $crate::test_utils::as_sorted_vec($actual); - assert_eq!(expected, actual); - }}; -} -pub use assert_equivalent_macro; - -/// Create a sorted clone af an iterable. -pub fn as_sorted_vec + Clone>(iter: I) -> Vec { - let mut list: Vec = iter.clone().into_iter().collect(); - list.sort(); - list -} - -/// Return the path of the given function. -/// If the last function is `f`, it is removed. -/// The last `{{closure}}` is also removed. -pub fn format_current_function_module(f: T) -> &'static str { - fn type_name_of(_: T) -> &'static str { - std::any::type_name::() - } - - let name = type_name_of(f); - let name = name.strip_suffix("::f").unwrap_or(name); - name.strip_suffix("::{{closure}}").unwrap_or(name) -} - -/// Return a string representing the path of the given function. -pub fn format_current_function_path(f: T) -> String { - let name = format_current_function_module(f); - name.replace("::", "/") -} - -/// Returns the name of the function that called this macro. -#[macro_export] -macro_rules! current_function { - () => {{ - fn f() {} - let name = $crate::test_utils::format_current_function_module(f); - // The index found is the beginning of the '..', this is why we add 2. - let function_name_index = name.rfind("::").map(|index| index + 2).unwrap_or(0); - - &name[function_name_index..] - }}; -} -pub use current_function; - -/// Returns the path of the function that called this macro. -#[macro_export] -macro_rules! current_function_path { - () => {{ - fn f() {} - - std::path::PathBuf::from($crate::test_utils::format_current_function_path(f)) - }}; -} -pub use current_function_path; - -#[cfg(test)] -mod utils { - use std::io; - use std::sync::Arc; - use std::{collections::HashSet, path::Path}; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - use super::*; - - pub struct TestLogger; - - #[cfg(test)] - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - - pub fn memory() -> (Logger, MemoryDrainForTestInspector) { - let (drain, inspector) = MemoryDrainForTest::new(); - (Logger::root(drain.fuse(), slog::o!()), inspector) - } - } - - #[test] - fn test_equivalent_to() { - assert!(equivalent_to(vec![1, 2, 3], vec![3, 2, 1])); - assert!(equivalent_to(vec![1, 2, 3], vec![2, 1, 3])); - assert!(!equivalent_to(vec![1, 2, 3], vec![3, 2, 1, 4])); - assert!(!equivalent_to(vec![1, 2, 3], vec![3, 2])); - - assert!(equivalent_to([1, 2, 3], vec![3, 2, 1])); - assert!(equivalent_to(&[1, 2, 3], &vec![3, 2, 1])); - assert!(equivalent_to([1, 2, 3], HashSet::from([3, 2, 1]))); - assert!(equivalent_to(vec![1, 2, 3], HashSet::from([3, 2, 1]))); - assert!(equivalent_to(&vec![1, 2, 3], &HashSet::from([3, 2, 1]))); - - assert_equivalent(vec![1, 2, 3], vec![3, 2, 1]); - assert_equivalent(vec![1, 2, 3], vec![2, 1, 3]); - - assert_equivalent([1, 2, 3], vec![3, 2, 1]); - assert_equivalent(&[1, 2, 3], &vec![3, 2, 1]); - assert_equivalent([1, 2, 3], HashSet::from([3, 2, 1])); - assert_equivalent(vec![1, 2, 3], HashSet::from([3, 2, 1])); - assert_equivalent(&vec![1, 2, 3], &HashSet::from([3, 2, 1])); - } - - #[test] - fn test_current_function_extract_function_name() { - let name = current_function!(); - - assert_eq!("test_current_function_extract_function_name", name); - } - - #[tokio::test] - async fn test_current_function_extract_async_function_name() { - let name = current_function!(); - - assert_eq!("test_current_function_extract_async_function_name", name); - } - - #[test] - fn test_format_function_path_from_given_function() { - assert_eq!( - "mithril_common/test_utils/utils/test_format_function_path_from_given_function", - format_current_function_path(test_format_function_path_from_given_function) - ); - } - - #[test] - fn test_format_function_path_from_given_pseudo_function_f() { - fn f() {} - assert_eq!( - "mithril_common/test_utils/utils/test_format_function_path_from_given_pseudo_function_f", - format_current_function_path(f) - ); - } - - #[tokio::test] - async fn test_format_function_path_from_given_async_function_f() { - fn f() {} - assert_eq!( - "mithril_common/test_utils/utils/test_format_function_path_from_given_async_function_f", - format_current_function_path(f) - ); - } - - #[test] - fn test_build_current_function_path_using_macros() { - assert_eq!( - Path::new("mithril_common") - .join("test_utils") - .join("utils") - .join("test_build_current_function_path_using_macros"), - current_function_path!() - ); - } - - #[tokio::test] - async fn test_build_current_async_function_path_using_macros() { - assert_eq!( - Path::new("mithril_common") - .join("test_utils") - .join("utils") - .join("test_build_current_async_function_path_using_macros"), - current_function_path!() - ); - } -} diff --git a/mithril-relay/Cargo.toml b/mithril-relay/Cargo.toml index 2cc3ed0e29d..f8cb6c9de05 100644 --- a/mithril-relay/Cargo.toml +++ b/mithril-relay/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-relay" -version = "0.1.48" +version = "0.1.49" description = "A Mithril relay" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-relay/src/lib.rs b/mithril-relay/src/lib.rs index 52e2ecc45e6..af3929eeec0 100644 --- a/mithril-relay/src/lib.rs +++ b/mithril-relay/src/lib.rs @@ -25,25 +25,5 @@ pub mod mithril_p2p_topic { #[cfg(test)] pub(crate) mod test_tools { - use std::io; - use std::sync::Arc; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - pub struct TestLogger; - - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - } + mithril_common::define_test_logger!(); } diff --git a/mithril-relay/src/relay/aggregator.rs b/mithril-relay/src/relay/aggregator.rs index 0d25c4c829f..bc958f67978 100644 --- a/mithril-relay/src/relay/aggregator.rs +++ b/mithril-relay/src/relay/aggregator.rs @@ -154,7 +154,7 @@ impl AggregatorRelay { #[cfg(test)] mod tests { use httpmock::MockServer; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use crate::test_tools::TestLogger; diff --git a/mithril-relay/src/relay/signer.rs b/mithril-relay/src/relay/signer.rs index 8b429ee6cf3..c1bdb20b206 100644 --- a/mithril-relay/src/relay/signer.rs +++ b/mithril-relay/src/relay/signer.rs @@ -398,7 +398,7 @@ mod tests { Method::{GET, POST}, MockServer, }; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::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 7c58670c008..24e4d4d5801 100644 --- a/mithril-relay/tests/register_signer_signature.rs +++ b/mithril-relay/tests/register_signer_signature.rs @@ -2,7 +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_common::test::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 976b825d980..06af998a2ee 100644 --- a/mithril-signer/Cargo.toml +++ b/mithril-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signer" -version = "0.2.261" +version = "0.2.262" description = "A Mithril Signer" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-signer/src/configuration.rs b/mithril-signer/src/configuration.rs index 1ef77077f3f..6ea58008e01 100644 --- a/mithril-signer/src/configuration.rs +++ b/mithril-signer/src/configuration.rs @@ -8,7 +8,6 @@ use mithril_cardano_node_chain::chain_observer::ChainObserver; use mithril_cli_helper::register_config_value; use mithril_common::{ CardanoNetwork, StdResult, - crypto_helper::tests_setup, entities::{BlockNumber, PartyId}, }; use mithril_era::{ @@ -147,7 +146,8 @@ impl Configuration { #[doc(hidden)] pub fn new_sample>(party_id: P) -> Self { let party_id: PartyId = party_id.into(); - let signer_temp_dir = tests_setup::setup_temp_directory_for_signer(&party_id, false); + let signer_temp_dir = + mithril_common::test::crypto_helper::setup_temp_directory_for_signer(&party_id, false); Self { aggregator_endpoint: "http://0.0.0.0:8000".to_string(), relay_endpoint: None, diff --git a/mithril-signer/src/database/repository/signed_beacon_repository.rs b/mithril-signer/src/database/repository/signed_beacon_repository.rs index 8848ef86795..d8e43d877ff 100644 --- a/mithril-signer/src/database/repository/signed_beacon_repository.rs +++ b/mithril-signer/src/database/repository/signed_beacon_repository.rs @@ -90,7 +90,7 @@ mod tests { use mithril_common::entities::{ BlockNumber, Epoch, SignedEntityConfig, SignedEntityTypeDiscriminants, TimePoint, }; - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use mithril_persistence::sqlite::ConnectionExtensions; use crate::database::query::GetSignedBeaconQuery; diff --git a/mithril-signer/src/database/tests/protocol_initializer.rs b/mithril-signer/src/database/tests/protocol_initializer.rs index 46e3231ef28..f41179fe914 100644 --- a/mithril-signer/src/database/tests/protocol_initializer.rs +++ b/mithril-signer/src/database/tests/protocol_initializer.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use mithril_common::test_utils::fake_data; +use mithril_common::test::double::fake_data; use mithril_common::{crypto_helper::ProtocolInitializer, entities::Epoch}; use mithril_persistence::sqlite::{ConnectionBuilder, ConnectionExtensions}; diff --git a/mithril-signer/src/dependency_injection/builder.rs b/mithril-signer/src/dependency_injection/builder.rs index 78ccc696f7b..65980f6cff0 100644 --- a/mithril-signer/src/dependency_injection/builder.rs +++ b/mithril-signer/src/dependency_injection/builder.rs @@ -507,8 +507,8 @@ 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 mithril_common::test::double::Dummy; + use mithril_common::{entities::TimePoint, test::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 1a1df619ce7..c128febf297 100644 --- a/mithril-signer/src/entities/signer_epoch_settings.rs +++ b/mithril-signer/src/entities/signer_epoch_settings.rs @@ -25,10 +25,10 @@ pub struct SignerEpochSettings { } #[cfg(test)] -impl mithril_common::test_utils::double::Dummy for SignerEpochSettings { +impl mithril_common::test::double::Dummy for SignerEpochSettings { /// Create a dummy `SignerEpochSettings` fn dummy() -> SignerEpochSettings { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; // Beacon let beacon = fake_data::beacon(); diff --git a/mithril-signer/src/lib.rs b/mithril-signer/src/lib.rs index cc54072d6e7..5a770109531 100644 --- a/mithril-signer/src/lib.rs +++ b/mithril-signer/src/lib.rs @@ -41,31 +41,5 @@ static GLOBAL: Jemalloc = Jemalloc; #[cfg(test)] pub(crate) mod test_tools { - use std::io; - use std::sync::Arc; - - use slog::{Drain, Logger}; - use slog_async::Async; - use slog_term::{CompactFormat, PlainDecorator}; - - use mithril_common::test_utils::{MemoryDrainForTest, MemoryDrainForTestInspector}; - pub struct TestLogger; - - impl TestLogger { - fn from_writer(writer: W) -> Logger { - let decorator = PlainDecorator::new(writer); - let drain = CompactFormat::new(decorator).build().fuse(); - let drain = Async::new(drain).build().fuse(); - Logger::root(Arc::new(drain), slog::o!()) - } - - pub fn stdout() -> Logger { - Self::from_writer(slog_term::TestStdoutWriter) - } - - pub fn memory() -> (Logger, MemoryDrainForTestInspector) { - let (drain, inspector) = MemoryDrainForTest::new(); - (Logger::root(drain.fuse(), slog::o!()), inspector) - } - } + mithril_common::define_test_logger!(); } diff --git a/mithril-signer/src/message_adapters/from_epoch_settings.rs b/mithril-signer/src/message_adapters/from_epoch_settings.rs index d9cb5a61a5f..5c8d8d764cc 100644 --- a/mithril-signer/src/message_adapters/from_epoch_settings.rs +++ b/mithril-signer/src/message_adapters/from_epoch_settings.rs @@ -29,7 +29,7 @@ impl TryFromMessageAdapter for FromEp #[cfg(test)] mod tests { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use super::*; diff --git a/mithril-signer/src/message_adapters/to_register_signature_message.rs b/mithril-signer/src/message_adapters/to_register_signature_message.rs index d4b0c5528ce..07b4b90840c 100644 --- a/mithril-signer/src/message_adapters/to_register_signature_message.rs +++ b/mithril-signer/src/message_adapters/to_register_signature_message.rs @@ -37,7 +37,7 @@ impl #[cfg(test)] mod tests { use mithril_common::entities::{CardanoDbBeacon, Epoch}; - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-signer/src/message_adapters/to_register_signer_message.rs b/mithril-signer/src/message_adapters/to_register_signer_message.rs index be4c092ae32..87de5b83978 100644 --- a/mithril-signer/src/message_adapters/to_register_signer_message.rs +++ b/mithril-signer/src/message_adapters/to_register_signer_message.rs @@ -46,7 +46,7 @@ impl TryToMessageAdapter<(Epoch, Signer), RegisterSignerMessage> #[cfg(test)] mod tests { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 95021d5acf5..cf40424e685 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -353,7 +353,10 @@ mod tests { CardanoTransactionsSignableBuilder, MithrilSignableBuilderService, MithrilStakeDistributionSignableBuilder, SignableBuilderServiceDependencies, }, - test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}, + test::{ + builder::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 78e86f91b04..fb543e9006c 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::{double::Dummy, fake_data}; + use mithril_common::test::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 d1d2fbeb1ce..d5695a68ba7 100644 --- a/mithril-signer/src/services/aggregator_client.rs +++ b/mithril-signer/src/services/aggregator_client.rs @@ -380,7 +380,7 @@ impl AggregatorClient for AggregatorHTTPClient { #[cfg(test)] pub(crate) mod dumb { - use mithril_common::test_utils::double::Dummy; + use mithril_common::test::double::Dummy; use tokio::sync::RwLock; use super::*; @@ -470,10 +470,12 @@ mod tests { use semver::Version; use serde_json::json; - use mithril_common::api_version::DummyApiVersionDiscriminantSource; use mithril_common::entities::Epoch; use mithril_common::messages::TryFromMessageAdapter; - use mithril_common::test_utils::{MemoryDrainForTestInspector, double::Dummy, fake_data}; + use mithril_common::test::{ + double::{Dummy, DummyApiVersionDiscriminantSource, fake_data}, + logging::MemoryDrainForTestInspector, + }; use crate::test_tools::TestLogger; diff --git a/mithril-signer/src/services/cardano_transactions/importer/importer_with_vacuum.rs b/mithril-signer/src/services/cardano_transactions/importer/importer_with_vacuum.rs index b0a4eac4e05..1b15cbdea04 100644 --- a/mithril-signer/src/services/cardano_transactions/importer/importer_with_vacuum.rs +++ b/mithril-signer/src/services/cardano_transactions/importer/importer_with_vacuum.rs @@ -55,7 +55,7 @@ mod tests { use mockall::mock; use sqlite::Connection; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use mithril_persistence::sqlite::SqliteConnection; 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 cf118cf3fe9..5343eb171ea 100644 --- a/mithril-signer/src/services/cardano_transactions/preloader_checker.rs +++ b/mithril-signer/src/services/cardano_transactions/preloader_checker.rs @@ -43,7 +43,7 @@ mod tests { use mithril_common::{ entities::SignedEntityTypeDiscriminants, messages::AggregatorFeaturesMessage, - test_utils::double::Dummy, + test::double::Dummy, }; use crate::services::{AggregatorClientError, MockAggregatorClient}; diff --git a/mithril-signer/src/services/certifier.rs b/mithril-signer/src/services/certifier.rs index 87a8babbe1c..8d100e4b9aa 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::{double::Dummy, fake_data}; + use mithril_common::test::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 59452f65e16..5222120d46c 100644 --- a/mithril-signer/src/services/epoch_service.rs +++ b/mithril-signer/src/services/epoch_service.rs @@ -340,7 +340,7 @@ impl MithrilEpochService { /// `TEST ONLY` - Set all data to either default values, empty values, or fake values /// if no default/empty can be set. pub fn set_data_to_default_or_fake(mut self, epoch: Epoch) -> Self { - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; let epoch_data = EpochData { epoch, @@ -428,7 +428,10 @@ mod tests { use tokio::sync::RwLock; use mithril_common::entities::{Epoch, StakeDistribution}; - use mithril_common::test_utils::{MithrilFixtureBuilder, double::Dummy, fake_data}; + use mithril_common::test::{ + builder::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/signable_builder/signable_seed_builder.rs b/mithril-signer/src/services/signable_builder/signable_seed_builder.rs index a32315922e6..d3c4fd128b7 100644 --- a/mithril-signer/src/services/signable_builder/signable_seed_builder.rs +++ b/mithril-signer/src/services/signable_builder/signable_seed_builder.rs @@ -107,7 +107,7 @@ impl SignableSeedBuilder for SignerSignableSeedBuilder { mod tests { use mithril_common::{ - entities::Epoch, entities::ProtocolParameters, test_utils::MithrilFixtureBuilder, + entities::Epoch, entities::ProtocolParameters, test::builder::MithrilFixtureBuilder, }; use crate::{ diff --git a/mithril-signer/src/services/signature_publisher/delayer.rs b/mithril-signer/src/services/signature_publisher/delayer.rs index 01dfbdd11db..901cfc91001 100644 --- a/mithril-signer/src/services/signature_publisher/delayer.rs +++ b/mithril-signer/src/services/signature_publisher/delayer.rs @@ -76,7 +76,7 @@ impl SignaturePublisher for SignaturePublisherDelayer { #[cfg(test)] mod tests { - use mithril_common::{entities::Epoch, test_utils::fake_data}; + use mithril_common::{entities::Epoch, test::double::fake_data}; use crate::{services::MockSignaturePublisher, test_tools::TestLogger}; diff --git a/mithril-signer/src/services/signature_publisher/dmq.rs b/mithril-signer/src/services/signature_publisher/dmq.rs index 7d251efb78f..68c8ea5f61b 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::{double::Dummy, fake_data}; + use mithril_common::test::double::{Dummy, fake_data}; use mithril_dmq::test::double::DmqPublisherFake; use super::*; diff --git a/mithril-signer/src/services/signature_publisher/retrier.rs b/mithril-signer/src/services/signature_publisher/retrier.rs index 78d2dc66a86..bd0f47a76fd 100644 --- a/mithril-signer/src/services/signature_publisher/retrier.rs +++ b/mithril-signer/src/services/signature_publisher/retrier.rs @@ -85,7 +85,7 @@ impl SignaturePublisher for SignaturePublisherRetrier { #[cfg(test)] mod tests { - use mithril_common::{entities::Epoch, test_utils::fake_data}; + use mithril_common::{entities::Epoch, test::double::fake_data}; use crate::services::MockSignaturePublisher; diff --git a/mithril-signer/src/services/single_signer.rs b/mithril-signer/src/services/single_signer.rs index f2d3c7a4344..b02b16717bc 100644 --- a/mithril-signer/src/services/single_signer.rs +++ b/mithril-signer/src/services/single_signer.rs @@ -173,7 +173,7 @@ mod tests { use crate::test_tools::TestLogger; use mithril_common::crypto_helper::ProtocolClerk; use mithril_common::entities::{Epoch, ProtocolMessagePartKey}; - use mithril_common::test_utils::MithrilFixtureBuilder; + use mithril_common::test::builder::MithrilFixtureBuilder; use mithril_persistence::store::StakeStorer; use super::*; diff --git a/mithril-signer/src/services/upkeep_service.rs b/mithril-signer/src/services/upkeep_service.rs index aa1f8dd7fc5..958e726a754 100644 --- a/mithril-signer/src/services/upkeep_service.rs +++ b/mithril-signer/src/services/upkeep_service.rs @@ -143,7 +143,7 @@ mod tests { use mockall::predicate::eq; use mithril_common::entities::SignedEntityTypeDiscriminants; - use mithril_common::test_utils::TempDir; + use mithril_common::test::TempDir; use crate::database::test_helper::{ cardano_tx_db_connection, cardano_tx_db_file_connection, main_db_connection, diff --git a/mithril-signer/tests/create_cardano_transaction_single_signature.rs b/mithril-signer/tests/create_cardano_transaction_single_signature.rs index 46489c1ccdc..d87742fac27 100644 --- a/mithril-signer/tests/create_cardano_transaction_single_signature.rs +++ b/mithril-signer/tests/create_cardano_transaction_single_signature.rs @@ -1,7 +1,6 @@ mod test_extensions; use mithril_common::{ - crypto_helper::tests_setup, entities::{ BlockNumber, CardanoDbBeacon, ChainPoint, Epoch, SignedEntityType::{ @@ -9,14 +8,14 @@ use mithril_common::{ }, SignedEntityTypeDiscriminants, SlotNumber, TimePoint, }, - test_utils::MithrilFixtureBuilder, + test::{builder::MithrilFixtureBuilder, crypto_helper}, }; use test_extensions::StateMachineTester; #[rustfmt::skip] #[tokio::test] async fn test_create_cardano_transaction_single_signature() { - let protocol_parameters = tests_setup::setup_protocol_parameters(); + let protocol_parameters = crypto_helper::setup_protocol_parameters(); let fixture = MithrilFixtureBuilder::default() .with_signers(10) .with_protocol_parameters(protocol_parameters.into()) diff --git a/mithril-signer/tests/create_immutable_files_full_single_signature.rs b/mithril-signer/tests/create_immutable_files_full_single_signature.rs index 047ceeb0c3a..811da67976b 100644 --- a/mithril-signer/tests/create_immutable_files_full_single_signature.rs +++ b/mithril-signer/tests/create_immutable_files_full_single_signature.rs @@ -5,16 +5,15 @@ use mithril_common::entities::SignedEntityType::{ }; use mithril_common::entities::{CardanoDbBeacon, SignedEntityTypeDiscriminants}; use mithril_common::{ - crypto_helper::tests_setup, entities::{BlockNumber, ChainPoint, Epoch, SlotNumber, TimePoint}, - test_utils::MithrilFixtureBuilder, + test::{builder::MithrilFixtureBuilder, crypto_helper}, }; use test_extensions::StateMachineTester; #[rustfmt::skip] #[tokio::test] async fn test_create_immutable_files_full_single_signature() { - let protocol_parameters = tests_setup::setup_protocol_parameters(); + let protocol_parameters = crypto_helper::setup_protocol_parameters(); let fixture = MithrilFixtureBuilder::default().with_signers(10).with_protocol_parameters(protocol_parameters.into()).build(); let signers_with_stake = fixture.signers_with_stake(); let initial_time_point = TimePoint { diff --git a/mithril-signer/tests/era_switch.rs b/mithril-signer/tests/era_switch.rs index 70578005649..e2d636ada15 100644 --- a/mithril-signer/tests/era_switch.rs +++ b/mithril-signer/tests/era_switch.rs @@ -1,9 +1,8 @@ mod test_extensions; use mithril_common::{ - crypto_helper::tests_setup, entities::{BlockNumber, ChainPoint, Epoch, SlotNumber, SupportedEra, TimePoint}, - test_utils::{MithrilFixtureBuilder, double::Dummy}, + test::{builder::MithrilFixtureBuilder, crypto_helper, double::Dummy}, }; use mithril_era::EraMarker; use test_extensions::StateMachineTester; @@ -11,7 +10,7 @@ use test_extensions::StateMachineTester; #[rustfmt::skip] #[tokio::test] async fn era_fail_at_startup() { - let protocol_parameters = tests_setup::setup_protocol_parameters(); + let protocol_parameters = crypto_helper::setup_protocol_parameters(); let fixture = MithrilFixtureBuilder::default().with_signers(10).with_protocol_parameters(protocol_parameters.into()).build(); let signers_with_stake = fixture.signers_with_stake(); let initial_time_point = TimePoint { diff --git a/mithril-signer/tests/test_extensions/certificate_handler.rs b/mithril-signer/tests/test_extensions/certificate_handler.rs index fb5a54903d5..377d1eda16f 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::{double::Dummy, fake_data}, + test::double::{Dummy, fake_data}, }; use mithril_ticker::{MithrilTickerService, TickerService}; @@ -170,7 +170,7 @@ mod tests { use mithril_cardano_node_chain::test::double::FakeChainObserver; use mithril_cardano_node_internal_database::test::double::DumbImmutableFileObserver; use mithril_common::entities::{BlockNumber, ChainPoint}; - use mithril_common::test_utils::fake_data; + use mithril_common::test::double::fake_data; use super::*; diff --git a/mithril-signer/tests/test_extensions/state_machine_tester.rs b/mithril-signer/tests/test_extensions/state_machine_tester.rs index a755eb716bd..43dd22662b4 100644 --- a/mithril-signer/tests/test_extensions/state_machine_tester.rs +++ b/mithril-signer/tests/test_extensions/state_machine_tester.rs @@ -39,7 +39,7 @@ use mithril_common::{ MithrilSignableBuilderService, MithrilStakeDistributionSignableBuilder, SignableBuilderServiceDependencies, }, - test_utils::double::Dummy, + test::double::Dummy, }; use mithril_era::{EraChecker, EraMarker, EraReader, adapters::EraReaderDummyAdapter}; use mithril_persistence::{ diff --git a/mithril-test-lab/mithril-end-to-end/Cargo.toml b/mithril-test-lab/mithril-end-to-end/Cargo.toml index 0070989f12b..8f2c6c36041 100644 --- a/mithril-test-lab/mithril-end-to-end/Cargo.toml +++ b/mithril-test-lab/mithril-end-to-end/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-end-to-end" -version = "0.4.97" +version = "0.4.98" authors = { workspace = true } edition = { workspace = true } documentation = { workspace = true } diff --git a/mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs b/mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs index f3277bfe435..1c381218349 100644 --- a/mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs +++ b/mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs @@ -7,7 +7,7 @@ use mithril_cardano_node_internal_database::test::{DummyCardanoDb, DummyCardanoD use mithril_common::{ StdResult, entities::{Epoch, ProtocolParameters}, - test_utils::MithrilFixture, + test::builder::MithrilFixture, }; use mithril_end_to_end::{ diff --git a/mithril-test-lab/mithril-end-to-end/src/stress_test/aggregator_helpers.rs b/mithril-test-lab/mithril-end-to-end/src/stress_test/aggregator_helpers.rs index 09a4de4a38b..25a99ae522f 100644 --- a/mithril-test-lab/mithril-end-to-end/src/stress_test/aggregator_helpers.rs +++ b/mithril-test-lab/mithril-end-to-end/src/stress_test/aggregator_helpers.rs @@ -1,7 +1,7 @@ use slog_scope::info; use std::time::Duration; -use mithril_common::{StdResult, entities::Epoch, test_utils::MithrilFixture}; +use mithril_common::{StdResult, entities::Epoch, test::builder::MithrilFixture}; use crate::{ Aggregator, AggregatorConfig, diff --git a/mithril-test-lab/mithril-end-to-end/src/stress_test/fake_chain.rs b/mithril-test-lab/mithril-end-to-end/src/stress_test/fake_chain.rs index f7abcae034b..c1058a76193 100644 --- a/mithril-test-lab/mithril-end-to-end/src/stress_test/fake_chain.rs +++ b/mithril-test-lab/mithril-end-to-end/src/stress_test/fake_chain.rs @@ -1,7 +1,7 @@ use slog_scope::debug; use std::{fs::File, io::Write, path::Path}; -use mithril_common::{entities::Epoch, test_utils::MithrilFixture}; +use mithril_common::{entities::Epoch, test::builder::MithrilFixture}; pub fn set_stake_distribution( mock_stake_distribution_file_path: &Path, diff --git a/mithril-test-lab/mithril-end-to-end/src/stress_test/payload_builder.rs b/mithril-test-lab/mithril-end-to-end/src/stress_test/payload_builder.rs index e620f2a2c91..8994d29e354 100644 --- a/mithril-test-lab/mithril-end-to-end/src/stress_test/payload_builder.rs +++ b/mithril-test-lab/mithril-end-to-end/src/stress_test/payload_builder.rs @@ -14,7 +14,7 @@ use mithril_common::{ }, messages::{RegisterSignatureMessageHttp, RegisterSignerMessage}, protocol::ToMessage, - test_utils::{MithrilFixture, MithrilFixtureBuilder}, + test::builder::{MithrilFixture, MithrilFixtureBuilder}, }; /// Generate signer data diff --git a/mithril-test-lab/mithril-end-to-end/src/utils/file_utils.rs b/mithril-test-lab/mithril-end-to-end/src/utils/file_utils.rs index 1de1afa855f..c1efc7dd20a 100644 --- a/mithril-test-lab/mithril-end-to-end/src/utils/file_utils.rs +++ b/mithril-test-lab/mithril-end-to-end/src/utils/file_utils.rs @@ -66,7 +66,7 @@ pub async fn last_errors(file_path: &Path, number_of_error: u64) -> StdResult