41 lines
1.7 KiB
Rust
41 lines
1.7 KiB
Rust
// file: crates/ksp-onchain-transport-lib/unit_tests/grpc_channel.rs
|
|
// version: 1
|
|
|
|
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(),
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
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 _channel_type = std::any::type_name_of_val(&channel.channel);
|
|
let _wire_type = std::any::type_name::<yellowstone_grpc_proto::geyser::SubscribeRequest>();
|
|
}
|
|
|
|
#[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());
|
|
}
|