// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_method.rs // version: 2 #[test] fn audited_registry_has_expected_current_and_historical_counts() { assert_eq!(super::current_http_rpc_methods().len(), 52); assert_eq!(super::historical_http_rpc_methods().len(), 14); } #[test] fn audited_registry_method_names_are_unique() { let mut names = std::collections::BTreeSet::<&str>::new(); for descriptor in super::current_http_rpc_methods() { assert!(names.insert(descriptor.method()), "duplicate current method {}", descriptor.method()); } for descriptor in super::historical_http_rpc_methods() { assert!(names.insert(descriptor.method()), "duplicate historical method {}", descriptor.method()); } assert_eq!(names.len(), 66); } #[test] fn coverage_release_counts_match_recalibrated_matrix() { let mut foundation = 0_usize; let mut accounts_tokens_cluster = 0_usize; let mut transactions = 0_usize; let mut blocks_economics = 0_usize; let mut historical = 0_usize; for descriptor in super::current_http_rpc_methods() { match descriptor.coverage_release() { super::HttpRpcCoverageRelease::V0_2_1 => foundation += 1, super::HttpRpcCoverageRelease::V0_2_2 => accounts_tokens_cluster += 1, super::HttpRpcCoverageRelease::V0_2_3 => transactions += 1, super::HttpRpcCoverageRelease::V0_2_4 => blocks_economics += 1, super::HttpRpcCoverageRelease::Historical => historical += 1, } } assert_eq!(historical, 0); assert_eq!(foundation, 4); assert_eq!(accounts_tokens_cluster, 22); assert_eq!(transactions, 11); assert_eq!(blocks_economics, 15); } #[test] fn foundation_canary_assignment_is_exact() { let mut names = std::vec::Vec::<&str>::new(); for descriptor in super::current_http_rpc_methods() { if descriptor.coverage_release() == super::HttpRpcCoverageRelease::V0_2_1 { names.push(descriptor.method()); } } names.sort_unstable(); assert_eq!(names, std::vec!["getBalance", "getGenesisHash", "getHealth", "getVersion"]); } #[test] fn historical_methods_are_deprecated_removed_and_not_retryable() { for descriptor in super::historical_http_rpc_methods() { assert_eq!(descriptor.documentation_status(), super::RpcDocumentationStatus::Deprecated); assert_eq!(descriptor.runtime_status(), super::RpcRuntimeStatus::Removed); assert_eq!(descriptor.transport_retry_class(), super::TransportRetryClass::NotApplicable); assert_eq!(descriptor.coverage_release(), super::HttpRpcCoverageRelease::Historical); } } #[test] fn get_transaction_and_get_block_track_deprecated_legacy_request_form() { let get_transaction = super::find_http_rpc_method("getTransaction").expect("getTransaction descriptor must exist"); let get_block = super::find_http_rpc_method("getBlock").expect("getBlock descriptor must exist"); assert!(get_transaction.request_form_status().has_deprecated_legacy()); assert!(get_block.request_form_status().has_deprecated_legacy()); let get_balance = super::find_http_rpc_method("getBalance").expect("getBalance descriptor must exist"); assert!(!get_balance.request_form_status().has_deprecated_legacy()); } #[test] fn write_submission_methods_are_never_retry_after_ambiguous_dispatch() { for method in ["sendTransaction", "requestAirdrop"] { let descriptor = super::find_http_rpc_method(method).expect("write descriptor must exist"); assert_eq!(descriptor.operation_kind(), super::RpcOperationKind::WriteSubmission); assert_eq!(descriptor.transport_retry_class(), super::TransportRetryClass::NeverAfterDispatch); } let simulation = super::find_http_rpc_method("simulateTransaction").expect("simulation descriptor must exist"); assert_eq!(simulation.operation_kind(), super::RpcOperationKind::Simulation); assert_eq!(simulation.transport_retry_class(), super::TransportRetryClass::RetrySafe); } #[test] fn removed_method_support_check_returns_method_removed_error() { let descriptor = super::find_http_rpc_method("confirmTransaction").expect("historical descriptor must exist"); let error = descriptor.ensure_runtime_supported().expect_err("removed method must not be callable"); assert_eq!(error.code(), crate::ERROR_CODE_METHOD_REMOVED); } #[test] fn stable_supported_method_passes_runtime_support_check() { let descriptor = super::find_http_rpc_method("getHealth").expect("current descriptor must exist"); assert!(descriptor.ensure_runtime_supported().is_ok()); } #[test] fn supported_unstable_descriptor_executes_central_warning_path() { let descriptor = super::HttpRpcMethodDescriptor::new( "experimentalMethod", super::HttpRpcCategory::Cluster, "experimental_method", super::RpcDocumentationStatus::Unstable, super::RpcRuntimeStatus::Supported, super::RpcRequestFormStatus::Stable, super::RpcOperationKind::Read, super::TransportRetryClass::RetrySafe, std::option::Option::None, super::HttpRpcCoverageRelease::V0_2_1, ); assert!(descriptor.requires_method_usage_warning()); assert!(descriptor.ensure_runtime_supported().is_ok()); } #[test] fn lookup_rejects_unknown_method_without_affecting_raw_provider_extensions() { assert!(super::find_http_rpc_method("providerCustomMethod").is_none()); }