// file: crates/ksp-onchain-transport-lib/unit_tests/grpc_channel.rs // version: 3 fn endpoint(enabled: bool, value: &str) -> crate::YellowstoneGrpcEndpointSettings { let parsed = crate::YellowstoneGrpcEndpointUrl::parse(value).expect("fixture Yellowstone gRPC URL must parse"); return crate::YellowstoneGrpcEndpointSettings::new( "fixture", enabled, crate::YellowstoneGrpcProviderName::new("fixture-provider"), crate::YellowstoneGrpcClusterName::new("devnet"), parsed, crate::YellowstoneGrpcSessionSettings::default(), ); } #[tokio::test(flavor = "current_thread")] async fn grpc_channel_prepare_is_lazy_safe_and_keeps_tonic_private() { let endpoint = endpoint(true, "http://127.0.0.1:10000/GRPC-SECRET-CANARY"); let channel = crate::YellowstoneGrpcChannel::prepare(&endpoint); assert!(channel.is_ok()); let channel = match channel { std::result::Result::Ok(value) => value, std::result::Result::Err(_) => return, }; assert_eq!(channel.endpoint_name(), "fixture"); assert_eq!(channel.provider().as_str(), "fixture-provider"); assert_eq!(channel.cluster().as_str(), "devnet"); let rendered = format!("{channel:?}"); assert!(!rendered.contains("GRPC-SECRET-CANARY")); assert!(!rendered.contains("127.0.0.1")); let _client = channel.standard_unary_client(); let _wire_type = std::any::type_name::(); } #[test] fn grpc_channel_prepare_requires_active_tokio_runtime_without_panicking() { let endpoint = endpoint(true, "http://127.0.0.1:10000/GRPC-SECRET-CANARY"); let result = crate::YellowstoneGrpcChannel::prepare(&endpoint); assert!(result.is_err()); let rendered = format!("{result:?}"); assert!(!rendered.contains("GRPC-SECRET-CANARY")); assert!(!rendered.contains("127.0.0.1")); } #[test] fn grpc_channel_prepare_rejects_disabled_endpoint_before_network_io() { let endpoint = endpoint(false, "http://127.0.0.1:10000"); let result = crate::YellowstoneGrpcChannel::prepare(&endpoint); assert!(result.is_err()); } #[tokio::test(flavor = "current_thread")] async fn grpc_channel_prepare_configures_https_without_exposing_url() { let endpoint = endpoint(true, "https://example.invalid:443/GRPC-SECRET-CANARY"); let result = crate::YellowstoneGrpcChannel::prepare(&endpoint); assert!(result.is_ok()); let rendered = format!("{result:?}"); assert!(!rendered.contains("GRPC-SECRET-CANARY")); assert!(!rendered.contains("example.invalid")); }