#[cfg(test)]
mod tests {
use crate::core::RpcEndpoint;
use crate::rpc::{ConnectionPool, ConnectionPoolTrait};
#[tokio::test]
async fn test_connection_pool_creation() {
let endpoints = vec![
RpcEndpoint {
url: "https://api.mainnet-beta.solana.com".to_string(),
priority: 0,
rate_limit_rps: 100,
timeout_ms: 5000,
healthy: true,
}
];
let pool = ConnectionPool::new(endpoints.clone(), 5);
let client = pool.get_client().await;
assert!(client.is_ok());
}
#[tokio::test]
async fn test_connection_pool_multiple_endpoints() {
let endpoints = vec![
RpcEndpoint {
url: "https://api.mainnet-beta.solana.com".to_string(),
priority: 0,
rate_limit_rps: 100,
timeout_ms: 5000,
healthy: true,
},
RpcEndpoint {
url: "https://solana-api.projectserum.com".to_string(),
priority: 1,
rate_limit_rps: 100,
timeout_ms: 5000,
healthy: true,
}
];
let pool = ConnectionPool::new(endpoints, 3);
let client = pool.get_client().await;
assert!(client.is_ok());
}
#[test]
fn test_rpc_endpoint_creation() {
let endpoint = RpcEndpoint {
url: "https://api.mainnet-beta.solana.com".to_string(),
priority: 1,
rate_limit_rps: 100,
timeout_ms: 5000,
healthy: true,
};
assert_eq!(endpoint.priority, 1);
assert_eq!(endpoint.rate_limit_rps, 100);
assert_eq!(endpoint.timeout_ms, 5000);
assert!(endpoint.healthy);
}
#[test]
fn test_rpc_endpoint_serialization() {
let endpoint = RpcEndpoint {
url: "https://api.mainnet-beta.solana.com".to_string(),
priority: 0,
rate_limit_rps: 100,
timeout_ms: 5000,
healthy: true,
};
let json = serde_json::to_string(&endpoint);
assert!(json.is_ok());
let deserialized: RpcEndpoint = serde_json::from_str(&json.unwrap()).expect("Failed to deserialize RpcEndpoint");
assert_eq!(deserialized.url, endpoint.url);
assert_eq!(deserialized.priority, endpoint.priority);
assert_eq!(deserialized.rate_limit_rps, endpoint.rate_limit_rps);
}
}