// file: crates/ksp-onchain-transport-lib/unit_tests/ws_lifecycle.rs // version: 1 fn non_zero(value: u64) -> std::num::NonZeroU64 { return std::num::NonZeroU64::new(value).expect("test ID must be non-zero"); } #[test] fn websocket_local_ids_preserve_ordering_and_numeric_identity() { let first_session = crate::WsSessionId::new(non_zero(1)); let second_session = crate::WsSessionId::new(non_zero(2)); let subscription = crate::WsSubscriptionId::new(non_zero(7)); assert!(first_session < second_session); assert_eq!(subscription.get(), 7); } #[test] fn websocket_state_models_expose_concurrent_lifecycle_states() { assert_eq!(crate::WsSessionState::Reconnecting { attempt: 3 }, crate::WsSessionState::Reconnecting { attempt: 3 }); assert_eq!(crate::WsSubscriptionState::Resubscribing, crate::WsSubscriptionState::Resubscribing); assert_ne!(crate::WsSubscriptionState::Cancelling, crate::WsSubscriptionState::Closed); } #[test] fn websocket_subscription_kinds_cover_all_nine_standard_families() { let kinds = [ crate::WsSubscriptionKind::Account, crate::WsSubscriptionKind::Block, crate::WsSubscriptionKind::Logs, crate::WsSubscriptionKind::Program, crate::WsSubscriptionKind::Root, crate::WsSubscriptionKind::Signature, crate::WsSubscriptionKind::Slot, crate::WsSubscriptionKind::SlotsUpdates, crate::WsSubscriptionKind::Vote, ]; assert_eq!(kinds.len(), 9); assert_eq!(kinds[7].as_str(), "slots_updates"); } #[test] fn websocket_snapshots_expose_safe_metadata_without_remote_ids_or_urls() { let subscription = crate::WsSubscriptionSnapshot::new( crate::WsSubscriptionId::new(non_zero(9)), crate::WsSubscriptionKind::Slot, crate::WsSubscriptionState::Active, true, ); let snapshot = crate::WsSessionSnapshot::new( crate::WsSessionId::new(non_zero(3)), "devnet_public", crate::WsProviderName::new("solana-public"), crate::WsClusterName::new("devnet"), crate::WsProtocolKind::SolanaStandard, crate::WsSessionState::Active, 2, 1, 0, std::vec![subscription], ); assert_eq!(snapshot.id().get(), 3); assert_eq!(snapshot.endpoint_name(), "devnet_public"); assert_eq!(snapshot.pending_request_count(), 2); assert_eq!(snapshot.continuity_gap_count(), 1); assert_eq!(snapshot.subscription_count(), 1); assert!(snapshot.subscriptions()[0].remote_bound()); let rendered = format!("{snapshot:?}"); assert!(!rendered.contains("wss://")); assert!(!rendered.contains("remote_subscription_id")); }