use std::sync::Arc;
use helius::client::Helius;
use helius::config::Config;
use helius::rpc_client::RpcClient;
use helius::types::*;
use mockito::Server;
use reqwest::Client;
pub async fn setup_mock() -> (Server, Helius) {
let server = Server::new_with_opts_async(mockito::ServerOpts::default()).await;
let url = server.url();
let config = Arc::new(Config {
api_key: Some(ApiKey::new("fake_api_key").unwrap()),
cluster: Cluster::Devnet,
endpoints: HeliusEndpoints {
api: url.to_string(),
rpc: url.to_string(),
},
custom_url: None,
});
let client = Client::new();
let rpc_client = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap());
let helius = Helius {
config,
client,
rpc_client,
async_rpc_client: None,
ws_client: None,
};
(server, helius)
}
pub fn mock_latest_blockhash(server: &mut Server) {
server
.mock("POST", mockito::Matcher::Any)
.match_body(mockito::Matcher::Regex("getLatestBlockhash".to_string()))
.with_status(200)
.with_header("Content-Type", "application/json")
.with_body(
r#"{"jsonrpc":"2.0","result":{"context":{"slot":1},"value":{"blockhash":"EkSnNWid2cvwEVnVx9aBqawnmiCNiDgp3gUdkDPTKN1N","lastValidBlockHeight":100}},"id":1}"#,
)
.create();
}
pub fn mock_rent_exempt(server: &mut Server) {
server
.mock("POST", mockito::Matcher::Any)
.match_body(mockito::Matcher::Regex("getMinimumBalanceForRentExemption".to_string()))
.with_status(200)
.with_header("Content-Type", "application/json")
.with_body(r#"{"jsonrpc":"2.0","result":2282880,"id":1}"#)
.create();
}