diff --git a/crates/cdk-mintd/src/config.rs b/crates/cdk-mintd/src/config.rs index 701ca52c..5919b697 100644 --- a/crates/cdk-mintd/src/config.rs +++ b/crates/cdk-mintd/src/config.rs @@ -26,14 +26,17 @@ pub struct Info { impl std::fmt::Debug for Info { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mnemonic_hash = sha256::Hash::from_slice(&self.mnemonic.clone().into_bytes()) - .map_err(|_| std::fmt::Error)?; + // Use a fallback approach that won't panic + let mnemonic_display = { + let hash = sha256::Hash::hash(self.mnemonic.clone().into_bytes().as_ref()); + format!("", hash) + }; f.debug_struct("Info") .field("url", &self.url) .field("listen_host", &self.listen_host) .field("listen_port", &self.listen_port) - .field("mnemonic", &format!("", mnemonic_hash)) + .field("mnemonic", &mnemonic_display) .field("input_fee_ppk", &self.input_fee_ppk) .field("http_cache", &self.http_cache) .field("enable_swagger_ui", &self.enable_swagger_ui) @@ -361,3 +364,74 @@ impl Settings { Ok(settings) } } + +#[cfg(test)] +mod tests { + + use super::*; + + #[test] + fn test_info_debug_impl() { + // Create a sample Info struct with test data + let info = Info { + url: "http://example.com".to_string(), + listen_host: "127.0.0.1".to_string(), + listen_port: 8080, + mnemonic: "test secret mnemonic phrase".to_string(), + input_fee_ppk: Some(100), + ..Default::default() + }; + + // Convert the Info struct to a debug string + let debug_output = format!("{:?}", info); + + // Verify the debug output contains expected fields + assert!(debug_output.contains("url: \"http://example.com\"")); + assert!(debug_output.contains("listen_host: \"127.0.0.1\"")); + assert!(debug_output.contains("listen_port: 8080")); + + // The mnemonic should be hashed, not displayed in plaintext + assert!(!debug_output.contains("test secret mnemonic phrase")); + assert!(debug_output.contains("