diff --git a/Cargo.lock b/Cargo.lock index d4f918d..898c6f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1239,7 +1239,7 @@ dependencies = [ [[package]] name = "geyser-grpc-connector" -version = "0.7.1+yellowstone.1.11" +version = "0.7.2+yellowstone.1.11" dependencies = [ "anyhow", "async-stream", diff --git a/src/grpc_subscription_autoreconnect.rs b/src/grpc_subscription_autoreconnect.rs index 2914748..57a593f 100644 --- a/src/grpc_subscription_autoreconnect.rs +++ b/src/grpc_subscription_autoreconnect.rs @@ -3,7 +3,7 @@ use futures::{Stream, StreamExt}; use log::{debug, info, log, trace, warn, Level}; use solana_sdk::commitment_config::CommitmentConfig; use std::collections::HashMap; -use std::fmt::Display; +use std::fmt::{Debug, Display}; use std::time::Duration; use tokio::task::JoinHandle; use tokio::time::{sleep, timeout}; @@ -22,7 +22,7 @@ pub struct GrpcConnectionTimeouts { pub subscribe_timeout: Duration, } -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct GrpcSourceConfig { grpc_addr: String, grpc_x_token: Option, @@ -40,6 +40,12 @@ impl Display for GrpcSourceConfig { } } +impl Debug for GrpcSourceConfig { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self, f) + } +} + impl GrpcSourceConfig { /// Create a grpc source without tls and timeouts pub fn new_simple(grpc_addr: String) -> Self { @@ -257,3 +263,50 @@ pub fn create_geyser_reconnecting_stream( the_stream } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn test_debug_no_secrets() { + let timeout_config = GrpcConnectionTimeouts { + connect_timeout: Duration::from_secs(1), + request_timeout: Duration::from_secs(2), + subscribe_timeout: Duration::from_secs(3), + }; + assert_eq!( + format!( + "{:?}", + GrpcSourceConfig::new( + "http://localhost:1234".to_string(), + Some("my-secret".to_string()), + None, + timeout_config + ) + ), + "grpc_addr http://localhost:1234" + ); + } + + #[tokio::test] + async fn test_display_no_secrets() { + let timeout_config = GrpcConnectionTimeouts { + connect_timeout: Duration::from_secs(1), + request_timeout: Duration::from_secs(2), + subscribe_timeout: Duration::from_secs(3), + }; + assert_eq!( + format!( + "{}", + GrpcSourceConfig::new( + "http://localhost:1234".to_string(), + Some("my-secret".to_string()), + None, + timeout_config + ) + ), + "grpc_addr http://localhost:1234" + ); + } +}