Files
khadhroony-solana-project/crates/ksp-app-raw-transaction-ingest-desk/unit_tests/dto_route.rs
2026-09-14 11:38:55 +02:00

94 lines
3.6 KiB
Rust

// file: crates/ksp-app-raw-transaction-ingest-desk/unit_tests/dto_route.rs
// version: 4
#[test]
fn pre_005_route_ids_are_exact_and_stably_ordered() {
let foundation = crate::RawIngestRouteFoundationDto::scaffold();
assert_eq!(foundation.route_ids.len(), 5);
let value = serde_json::to_value(foundation.route_ids);
assert!(value.is_ok());
if let std::result::Result::Ok(value) = value {
assert_eq!(
value,
serde_json::json!(["yellowstone-hydrated", "standard-logs-hydrated", "standard-block-direct", "helius-transaction-hydrated", "http-block-polling"])
);
}
}
#[test]
fn pre_005_route_states_are_exact_without_runtime_claims() {
let foundation = crate::RawIngestRouteFoundationDto::scaffold();
assert_eq!(foundation.states.len(), 7);
let value = serde_json::to_value(foundation.states);
assert!(value.is_ok());
if let std::result::Result::Ok(value) = value {
assert_eq!(value, serde_json::json!(["unavailable", "configured", "starting", "running", "stopping", "stopped", "faulted"]));
}
}
#[test]
fn pre_006_unavailable_reason_codes_are_exact_and_safe() {
let values = [
crate::RawIngestRouteUnavailableReason::ProfileUnresolved,
crate::RawIngestRouteUnavailableReason::NetworkMismatch,
crate::RawIngestRouteUnavailableReason::MissingHttpGetBlock,
crate::RawIngestRouteUnavailableReason::MissingHttpGetTransaction,
crate::RawIngestRouteUnavailableReason::MissingHttpBlockScan,
crate::RawIngestRouteUnavailableReason::MissingWsLogsCapability,
crate::RawIngestRouteUnavailableReason::MissingWsBlockCapability,
crate::RawIngestRouteUnavailableReason::MissingHeliusTransactionCapability,
crate::RawIngestRouteUnavailableReason::MissingYellowstoneGrpc,
crate::RawIngestRouteUnavailableReason::MissingRequiredSecret,
];
let serialized = serde_json::to_value(values);
assert!(serialized.is_ok());
if let std::result::Result::Ok(serialized) = serialized {
assert_eq!(
serialized,
serde_json::json!([
"profile_unresolved",
"network_mismatch",
"missing_http_get_block",
"missing_http_get_transaction",
"missing_http_block_scan",
"missing_ws_logs_capability",
"missing_ws_block_capability",
"missing_helius_transaction_capability",
"missing_yellowstone_grpc",
"missing_required_secret"
])
);
}
}
#[test]
fn pre_008_runtime_acknowledgement_serializes_only_safe_logical_identity_and_state() {
let dto = crate::RawIngestRouteRuntimeDto {
commitment: crate::RawIngestCommitment::Confirmed,
inventory_generation: 7,
network: "mainnet".to_owned(),
profile_id: "mainnet".to_owned(),
route_id: crate::RawIngestRouteId::StandardBlockDirect,
state: crate::RawIngestRouteState::Running,
};
let value = serde_json::to_value(dto);
assert!(value.is_ok());
if let std::result::Result::Ok(value) = value {
assert_eq!(
value,
serde_json::json!({
"commitment": "confirmed",
"inventoryGeneration": 7,
"network": "mainnet",
"profileId": "mainnet",
"routeId": "standard-block-direct",
"state": "running"
})
);
let encoded = value.to_string();
for forbidden in ["endpoint", "provider", "connectionUri", "sourceKey", "workerId", "payload"] {
assert!(!encoded.contains(forbidden));
}
}
}