Files
khadhroony-solana-project/crates/ksp-app-raw-transaction-ingest-desk/unit_tests/route_inventory.rs
2026-09-13 11:30:56 +02:00

113 lines
4.8 KiB
Rust

// file: crates/ksp-app-raw-transaction-ingest-desk/unit_tests/route_inventory.rs
// version: 1
#[test]
fn pre_006_route_requirement_projection_is_fail_closed_and_ordered() {
let route = super::route_with_requirements(
crate::RawIngestRouteId::StandardLogsHydrated,
"devnet",
&[
(false, crate::RawIngestRouteUnavailableReason::MissingWsLogsCapability),
(false, crate::RawIngestRouteUnavailableReason::MissingHttpGetTransaction),
],
);
assert!(!route.selectable);
assert_eq!(route.state, crate::RawIngestRouteState::Unavailable);
assert_eq!(route.reason, std::option::Option::Some(crate::RawIngestRouteUnavailableReason::MissingWsLogsCapability));
assert_eq!(route.network.as_deref(), std::option::Option::Some("devnet"));
let configured = super::route_with_requirements(
crate::RawIngestRouteId::HttpBlockPolling,
"mainnet",
&[(true, crate::RawIngestRouteUnavailableReason::MissingHttpBlockScan)],
);
assert!(configured.selectable);
assert_eq!(configured.state, crate::RawIngestRouteState::Configured);
assert_eq!(configured.reason, std::option::Option::None);
}
#[test]
fn pre_006_unavailable_profile_projects_all_five_routes_without_physical_material() {
let profile = super::unavailable_profile(
"provider_profile",
false,
std::option::Option::Some("testnet"),
crate::RawIngestRouteUnavailableReason::MissingRequiredSecret,
);
assert_eq!(profile.routes.len(), 5);
assert_eq!(profile.network.as_deref(), std::option::Option::Some("testnet"));
for route in profile.routes {
assert!(!route.selectable);
assert_eq!(route.reason, std::option::Option::Some(crate::RawIngestRouteUnavailableReason::MissingRequiredSecret));
}
}
#[test]
fn pre_006_committed_devnet_public_inventory_proves_only_config_composability() {
let arguments = std::vec::Vec::<std::ffi::OsString>::new();
let management = crate::config_management(arguments.as_slice());
assert!(management.is_ok());
let management = match management {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
let inventory = crate::build_route_inventory(&management, 7);
assert!(inventory.is_ok());
let inventory = match inventory {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
assert_eq!(inventory.generation, 7);
assert_eq!(inventory.default_profile, "devnet_public");
let profile = inventory.profiles.iter().find(|profile| return profile.profile_id == "devnet_public");
assert!(profile.is_some());
let profile = match profile {
std::option::Option::Some(value) => value,
std::option::Option::None => return,
};
assert!(profile.is_default);
assert_eq!(profile.network.as_deref(), std::option::Option::Some("devnet"));
assert_eq!(profile.routes.len(), 5);
assert_route(
profile,
crate::RawIngestRouteId::YellowstoneHydrated,
false,
std::option::Option::Some(crate::RawIngestRouteUnavailableReason::MissingYellowstoneGrpc),
);
assert_route(profile, crate::RawIngestRouteId::StandardLogsHydrated, true, std::option::Option::None);
assert_route(
profile,
crate::RawIngestRouteId::StandardBlockDirect,
false,
std::option::Option::Some(crate::RawIngestRouteUnavailableReason::MissingWsBlockCapability),
);
assert_route(
profile,
crate::RawIngestRouteId::HeliusTransactionHydrated,
false,
std::option::Option::Some(crate::RawIngestRouteUnavailableReason::MissingHeliusTransactionCapability),
);
assert_route(profile, crate::RawIngestRouteId::HttpBlockPolling, true, std::option::Option::None);
let serialized = serde_json::to_string(&inventory);
assert!(serialized.is_ok());
if let std::result::Result::Ok(serialized) = serialized {
for forbidden in ["http://", "https://", "ws://", "wss://", "api-key", "x-token", "connection_uri", "source_key", "endpoint_name"] {
assert!(!serialized.contains(forbidden), "safe inventory leaked forbidden marker {forbidden}");
}
}
}
fn assert_route(
profile: &crate::RawIngestProfileInventoryDto,
route_id: crate::RawIngestRouteId,
selectable: bool,
reason: std::option::Option<crate::RawIngestRouteUnavailableReason>,
) {
let route = profile.routes.iter().find(|route| return route.route_id == route_id);
assert!(route.is_some());
if let std::option::Option::Some(route) = route {
assert_eq!(route.selectable, selectable);
assert_eq!(route.reason, reason);
assert_eq!(route.state, if selectable { crate::RawIngestRouteState::Configured } else { crate::RawIngestRouteState::Unavailable });
}
}