use dotenv::from_filename; use solana_sdk::pubkey::Pubkey; use spiderswap::{Providers, Spiderswap}; use std::{ env::{self, VarError}, error::Error, }; struct TestSpiderParams { api_key: String, owner: Pubkey, from_mint: Pubkey, to_mint: Pubkey, amount: u64, slippage: u16, provider: Providers, } impl TestSpiderParams { pub fn new() -> Result { const ENV_TEST: &str = ".test.env"; from_filename(ENV_TEST).ok(); let api_key = env::var("API_KEY").unwrap_or_else(|_| panic!("API key not found")); let owner = env::var("OWNER").unwrap_or_else(|_| panic!("Owner not found")); let from_mint = env::var("FROM_MINT").unwrap_or_else(|_| panic!("From mint not found")); let to_mint = env::var("TO_MINT").unwrap_or_else(|_| panic!("To mint not found")); let amount: u64 = 1_000_000_000; let slippage: u16 = 100; let provider = Providers::Raydium; Ok(TestSpiderParams { api_key, owner: Pubkey::from_str_const(&owner), from_mint: Pubkey::from_str_const(&from_mint), to_mint: Pubkey::from_str_const(&to_mint), amount, slippage, provider, }) } } fn spider_init() -> Result<(Spiderswap, TestSpiderParams), Box> { let test_spider_params = TestSpiderParams::new()?; let spiderswap = Spiderswap::new(test_spider_params.api_key.to_owned())?; Ok((spiderswap, test_spider_params)) } #[tokio::test] async fn get_swap() -> Result<(), Box> { let (spiderswap, test_spider_params) = spider_init()?; let response = spiderswap .get_swap( test_spider_params.owner, test_spider_params.from_mint, test_spider_params.to_mint, test_spider_params.amount, test_spider_params.slippage, test_spider_params.provider, None, ) .await; assert!(response.is_ok(), "Failed to get swap"); Ok(()) } #[tokio::test] async fn get_quote() -> Result<(), Box> { let (spiderswap, test_spider_params) = spider_init()?; let response = spiderswap .get_quote( test_spider_params.from_mint, test_spider_params.to_mint, test_spider_params.amount, test_spider_params.slippage, test_spider_params.provider, None, ) .await; assert!(response.is_ok(), "Failed to get quote"); Ok(()) } #[tokio::test] async fn get_all_quotes() -> Result<(), Box> { let (spiderswap, test_spider_params) = spider_init()?; let response = spiderswap .get_all_quotes( test_spider_params.from_mint, test_spider_params.to_mint, test_spider_params.amount, test_spider_params.slippage, ) .await; assert!(response.is_ok(), "Failed to get all quotes"); Ok(()) }