// file: crates/ksp-offchain-transport-lib/tests/public_api.rs // version: 1 #![warn(missing_docs)] #![deny(unreachable_pub)] #![forbid(unsafe_code)] #[test] fn public_pre_002_price_foundation_is_available_from_crate_root() -> ksp_core_lib::Result<()> { assert_eq!(ksp_offchain_transport_lib::PricePair::SolUsd.code(), "SOL/USD"); assert_eq!(ksp_offchain_transport_lib::PRICE_DECIMAL_MAX_SCALE, 18); let price = match ksp_offchain_transport_lib::PriceDecimal::parse("201.2500") { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; assert_eq!(price.to_canonical_string(), "201.25"); let id = match ksp_offchain_transport_lib::PriceProviderId::new("provider-canary") { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let common = ksp_offchain_transport_lib::PriceProviderCommonSettings::new(id.clone(), true); assert_eq!(common.provider_id(), &id); let rate_limit = match ksp_offchain_transport_lib::PriceProviderRateLimit::fixed( 1, 1, std::option::Option::None, ksp_offchain_transport_lib::PriceProviderRateLimitScope::Ip, ) { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let descriptor = match ksp_offchain_transport_lib::PriceProviderDescriptor::new( id.clone(), "Provider Canary", ksp_offchain_transport_lib::PriceSemantics::AggregatedMarket, ksp_offchain_transport_lib::PriceProviderAuthMode::None, rate_limit, std::option::Option::None, true, ) { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; assert!(descriptor.supports_sol_usd()); let provenance = match ksp_offchain_transport_lib::PriceProvenance::new("canary") { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let timestamp = ksp_offchain_transport_lib::PriceTimestamp::from_unix_millis(1); let observation = match ksp_offchain_transport_lib::SolUsdPriceObservation::new( id, price, ksp_offchain_transport_lib::PriceSemantics::AggregatedMarket, timestamp, timestamp, std::option::Option::None, provenance, ) { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; assert_eq!(observation.price(), price); return std::result::Result::Ok(()); } #[test] fn offchain_error_codes_use_owned_domain() { let codes = [ ksp_offchain_transport_lib::ERROR_CODE_PRICE_DECIMAL_INVALID, ksp_offchain_transport_lib::ERROR_CODE_PROVIDER_DESCRIPTOR_INVALID, ksp_offchain_transport_lib::ERROR_CODE_PROVIDER_ID_INVALID, ksp_offchain_transport_lib::ERROR_CODE_PROVIDER_OBSERVATION_INVALID, ksp_offchain_transport_lib::ERROR_CODE_PROVIDER_SETTINGS_INVALID, ]; for code in codes { assert_eq!(code.domain(), "offchain_transport"); } }