63 lines
2.9 KiB
Rust
63 lines
2.9 KiB
Rust
// file: crates/ksp-onchain-transport-lib/unit_tests/http_client.rs
|
|
// version: 4
|
|
|
|
fn endpoint(enabled: bool, url_text: &str) -> crate::HttpEndpointSettings {
|
|
let url = crate::HttpEndpointUrl::parse(url_text).expect("test endpoint URL must parse");
|
|
let role = crate::HttpEndpointRoleSettings::new(
|
|
crate::HttpRoleName::new("default"),
|
|
true,
|
|
std::vec![crate::HttpRequestKind::wildcard()],
|
|
10,
|
|
crate::HttpRoleLimits::new(std::option::Option::None, std::option::Option::None, std::option::Option::None, std::option::Option::None),
|
|
);
|
|
return crate::HttpEndpointSettings::new(
|
|
"endpoint",
|
|
enabled,
|
|
crate::HttpProviderName::new("provider"),
|
|
crate::HttpClusterName::new("devnet"),
|
|
url,
|
|
std::time::Duration::from_secs(1),
|
|
std::time::Duration::from_secs(2),
|
|
std::option::Option::Some(4),
|
|
std::vec![role],
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn endpoint_client_snapshot_never_contains_url_or_secret_material() {
|
|
let client = crate::HttpEndpointClient::new(endpoint(true, "https://provider.invalid/rpc?api-key=SECRET-CANARY")).expect("client must build");
|
|
let snapshot = client.snapshot();
|
|
let rendered = format!("{snapshot:?} {client:?}");
|
|
assert_eq!(snapshot.availability(), crate::HttpEndpointAvailability::Available);
|
|
assert!(!rendered.contains("SECRET-CANARY"));
|
|
assert!(!rendered.contains("provider.invalid"));
|
|
assert!(!rendered.contains("https://"));
|
|
}
|
|
|
|
#[test]
|
|
fn disabled_endpoint_client_is_visible_but_not_selectable() {
|
|
let client = crate::HttpEndpointClient::new(endpoint(false, "https://api.devnet.solana.com")).expect("disabled client must still build");
|
|
assert_eq!(client.snapshot().availability(), crate::HttpEndpointAvailability::Disabled);
|
|
assert!(!client.supports(&crate::HttpRoleName::new("default"), &crate::HttpRequestKind::new("get_balance")));
|
|
}
|
|
|
|
#[test]
|
|
fn endpoint_client_matches_exact_and_wildcard_capabilities() {
|
|
let client = crate::HttpEndpointClient::new(endpoint(true, "https://api.devnet.solana.com")).expect("client must build");
|
|
assert!(client.supports(&crate::HttpRoleName::new("default"), &crate::HttpRequestKind::new("get_balance")));
|
|
assert!(!client.supports(&crate::HttpRoleName::new("write"), &crate::HttpRequestKind::new("get_balance")));
|
|
}
|
|
|
|
#[test]
|
|
fn endpoint_role_snapshot_exposes_safe_resilience_state() {
|
|
let client = crate::HttpEndpointClient::new(endpoint(true, "https://api.devnet.solana.com")).expect("client must build");
|
|
let snapshot = client.snapshot();
|
|
let role = &snapshot.roles()[0];
|
|
assert_eq!(role.availability(), crate::HttpEndpointAvailability::Available);
|
|
assert_eq!(role.in_flight_requests(), std::option::Option::None);
|
|
assert_eq!(role.cooldown_remaining(), std::option::Option::None);
|
|
assert_eq!(role.success_count(), 0);
|
|
assert_eq!(role.failure_count(), 0);
|
|
assert_eq!(role.rate_limit_count(), 0);
|
|
}
|