Skip to content

Commit ac80bdd

Browse files
committed
refactor: replace fn dummy() with Dummy trait impl
and, when applicable, move the `Dummy` impl to a `test::double::dummies` module.
1 parent 33d2a33 commit ac80bdd

File tree

28 files changed

+178
-133
lines changed

28 files changed

+178
-133
lines changed

internal/mithril-dmq/src/publisher/pallas.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl<M: TryToBytes + Debug + Sync + Send> DmqPublisher<M> for DmqPublisherPallas
8282

8383
#[cfg(all(test, unix))]
8484
mod tests {
85-
8685
use std::{fs, sync::Arc};
8786

8887
use pallas_network::miniprotocols::{
@@ -91,7 +90,11 @@ mod tests {
9190
use tokio::{net::UnixListener, task::JoinHandle};
9291

9392
use mithril_cardano_node_chain::test::double::FakeChainObserver;
94-
use mithril_common::{crypto_helper::KesSignerFake, current_function, test_utils::TempDir};
93+
use mithril_common::{
94+
crypto_helper::KesSignerFake,
95+
current_function,
96+
test_utils::{TempDir, double::Dummy},
97+
};
9598

9699
use crate::{test::payload::DmqMessageTestPayload, test_tools::TestLogger};
97100

internal/mithril-dmq/src/test/payload.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Debug;
33
use mithril_common::{
44
StdResult,
55
crypto_helper::{TryFromBytes, TryToBytes},
6+
test_utils::double::Dummy,
67
};
78

89
/// A test message payload for the DMQ.
@@ -18,9 +19,11 @@ impl DmqMessageTestPayload {
1819
message: bytes.to_vec(),
1920
}
2021
}
22+
}
2123

24+
impl Dummy for DmqMessageTestPayload {
2225
/// Creates a dummy `DmqMessageTestPayload` with a predefined message.
23-
pub fn dummy() -> Self {
26+
fn dummy() -> Self {
2427
Self {
2528
message: b"dummy message".to_vec(),
2629
}

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl AncillaryArtifactBuilder {
206206
mod tests {
207207
use std::path::PathBuf;
208208

209-
use mithril_common::test_utils::{TempDir, assert_equivalent};
209+
use mithril_common::test_utils::{TempDir, assert_equivalent, double::Dummy};
210210

211211
use crate::services::{DumbSnapshotter, MockSnapshotter};
212212
use crate::test_tools::TestLogger;

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ mod tests {
299299
current_function,
300300
entities::{CardanoDbBeacon, CompressionAlgorithm},
301301
messages::{CardanoDatabaseDigestListItemMessage, CardanoDatabaseDigestListMessage},
302-
test_utils::{TempDir, assert_equivalent},
302+
test_utils::{TempDir, assert_equivalent, double::Dummy},
303303
};
304304

305305
use crate::{

mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl ArtifactBuilder<Epoch, MithrilStakeDistribution> for MithrilStakeDistributi
3838

3939
#[cfg(test)]
4040
mod tests {
41-
use mithril_common::{crypto_helper::ProtocolParameters, test_utils::fake_data};
41+
use mithril_common::{
42+
crypto_helper::ProtocolParameters,
43+
test_utils::{double::Dummy, fake_data},
44+
};
4245
use std::sync::Arc;
4346
use tokio::sync::RwLock;
4447

mithril-aggregator/src/database/query/open_message/insert_or_replace_open_message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl Query for InsertOrReplaceOpenMessageQuery {
3434

3535
#[cfg(test)]
3636
mod tests {
37+
use mithril_common::test_utils::double::Dummy;
3738
use mithril_persistence::sqlite::ConnectionExtensions;
3839

3940
use crate::database::query::GetOpenMessageQuery;

mithril-aggregator/src/database/record/immutable_file_digest.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ impl ImmutableFileDigestRecord {
1919
let aliases = SourceAlias::new(&[("{:immutable_file_digest:}", table)]);
2020
Self::get_projection().expand(aliases)
2121
}
22-
23-
#[cfg(test)]
24-
/// Create a dumb ImmutableFileDigestRecord instance mainly for test purposes
25-
pub fn dummy() -> Self {
26-
Self {
27-
immutable_file_name: "123.chunk".to_string(),
28-
digest: "dummy_digest".to_string(),
29-
}
30-
}
3122
}
3223

3324
impl SqLiteEntity for ImmutableFileDigestRecord {

mithril-aggregator/src/database/record/open_message.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,6 @@ impl OpenMessageRecord {
4343
pub fn new_id() -> Uuid {
4444
Uuid::new_v4()
4545
}
46-
47-
#[cfg(test)]
48-
/// Create a dumb OpenMessage instance mainly for test purposes
49-
pub fn dummy() -> Self {
50-
let beacon = mithril_common::test_utils::fake_data::beacon();
51-
let epoch = beacon.epoch;
52-
let signed_entity_type = SignedEntityType::CardanoImmutableFilesFull(beacon);
53-
54-
Self {
55-
open_message_id: Uuid::parse_str("193d1442-e89b-43cf-9519-04d8db9a12ff").unwrap(),
56-
epoch,
57-
signed_entity_type,
58-
protocol_message: ProtocolMessage::new(),
59-
is_certified: false,
60-
is_expired: false,
61-
created_at: Utc::now(),
62-
expires_at: None,
63-
}
64-
}
6546
}
6647

6748
impl SqLiteEntity for OpenMessageRecord {

mithril-aggregator/src/database/repository/epoch_settings_store.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ impl EpochPruningTask for EpochSettingsStore {
9292

9393
#[cfg(test)]
9494
mod tests {
95+
use mithril_common::test_utils::double::Dummy;
96+
9597
use crate::database::test_helper::{insert_epoch_settings, main_db_connection};
9698

9799
use super::*;

mithril-aggregator/src/database/repository/open_message_repository.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl OpenMessageStorer for OpenMessageRepository {
140140
#[cfg(test)]
141141
mod tests {
142142
use mithril_common::entities::{BlockNumber, CardanoDbBeacon};
143+
use mithril_common::test_utils::double::Dummy;
143144

144145
use crate::database::record::SingleSignatureRecord;
145146
use crate::database::test_helper::{

0 commit comments

Comments
 (0)