Skip to content

Commit b76f911

Browse files
authored
Merge pull request #2647 from input-output-hk/djo/2580/refactor-common-dummies
refactor: rethink dummies test doubles
2 parents 890801c + dd5d4b8 commit b76f911

File tree

144 files changed

+1044
-844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1044
-844
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DEV-ADR.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@ To complete
2323
To complete
2424
-->
2525

26+
### 3. Guidelines for Dummy Test Doubles
27+
28+
**Date:** 2025-07-22
29+
**Status:** Accepted
30+
31+
#### Context
32+
33+
The use of `dummy()` functions for creating test doubles is widespread across the codebase. However, inconsistencies
34+
in their placement and visibility have led to maintenance challenges and reduced code clarity.
35+
36+
#### Decision
37+
38+
A `Dummy` trait will be introduced, functioning similarly to Rust's `Default` trait.
39+
40+
The following guidelines will be adopted for implementing the `Dummy` trait:
41+
42+
1. Most implementations should reside in a `test::double::dummies` module within the crate where the type is defined.
43+
2. For types with non-public fields, the `Dummy` trait should be implemented directly below the type's definition.
44+
45+
#### Consequences
46+
47+
- Enhanced consistency in code organization.
48+
- Improved discoverability of test doubles.
49+
- Clearer distinction between production and test code.
50+
- Simplified maintenance of test implementations.
51+
52+
---
53+
2654
## 2. Remove Artifacts serialization support when compiling to WebAssembly
2755

2856
date: 2025-02-26

internal/cardano-node/mithril-cardano-node-chain/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-cardano-node-chain"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
authors.workspace = true
55
documentation.workspace = true
66
edition.workspace = true

internal/cardano-node/mithril-cardano-node-chain/src/test/double/chain_observer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl ChainObserver for FakeChainObserver {
212212

213213
#[cfg(test)]
214214
mod tests {
215-
use mithril_common::test_utils::fake_data;
215+
use mithril_common::test_utils::{double::Dummy, fake_data};
216216

217217
use super::*;
218218

internal/mithril-dmq/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mithril-dmq"
33
description = "Mechanisms to publish and consume messages of a 'Decentralized Message Queue network' through a DMQ node"
4-
version = "0.1.4"
4+
version = "0.1.5"
55
authors.workspace = true
66
documentation.workspace = true
77
edition.workspace = true

internal/mithril-dmq/src/message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ mod tests {
9494
use mithril_common::{
9595
crypto_helper::{KesSignerFake, TryToBytes},
9696
entities::{BlockNumber, ChainPoint, TimePoint},
97+
test_utils::double::Dummy,
9798
};
9899

99100
use super::*;

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
}

internal/mithril-era/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-era"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
authors.workspace = true
55
documentation.workspace = true
66
edition.workspace = true

internal/mithril-era/src/adapters/bootstrap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ impl EraReaderAdapter for BootstrapAdapter {
2222

2323
#[cfg(test)]
2424
mod tests {
25+
use mithril_common::test_utils::double::Dummy;
26+
2527
use super::*;
2628

2729
#[tokio::test]

0 commit comments

Comments
 (0)