From 51c85af529669d14a4a5d842b64f136414759ce3 Mon Sep 17 00:00:00 2001 From: David Kathoh Date: Tue, 21 May 2024 07:23:30 +0200 Subject: [PATCH] Run cargo fmt to follow Rust conventions --- tests/test_enhanced_transactions.rs | 145 ++++++++++-------- tests/tests.rs | 7 +- .../test_append_addresses_to_webhook.rs | 94 +++++++----- tests/webhook/test_create_webhook.rs | 70 ++++----- tests/webhook/test_delete_webhook.rs | 51 +++--- tests/webhook/test_edit_webhook.rs | 66 ++++---- tests/webhook/test_get_all_webhooks.rs | 28 ++-- tests/webhook/test_get_webhook_by_id.rs | 61 ++++---- .../test_remove_addresses_from_webhook.rs | 116 ++++++++------ 9 files changed, 342 insertions(+), 296 deletions(-) diff --git a/tests/test_enhanced_transactions.rs b/tests/test_enhanced_transactions.rs index 3419c0f..2b4fab6 100644 --- a/tests/test_enhanced_transactions.rs +++ b/tests/test_enhanced_transactions.rs @@ -1,19 +1,23 @@ -use std::sync::Arc; +use helius::config::Config; +use helius::rpc_client::RpcClient; +use helius::types::{ + AccountData, Cluster, EnhancedTransaction, HeliusEndpoints, InnerInstruction, Instruction, + ParseTransactionsRequest, ParsedTransactionHistoryRequest, Source, TokenStandard, TokenTransfer, TransactionEvent, + TransactionType, TransferUserAccounts, +}; +use helius::Helius; use mockito::Server; use reqwest::Client; use serde_json::Number; -use helius::config::Config; -use helius::Helius; -use helius::rpc_client::RpcClient; -use helius::types::{AccountData, Cluster, EnhancedTransaction, HeliusEndpoints, InnerInstruction, Instruction, ParsedTransactionHistoryRequest, ParseTransactionsRequest, Source, TokenStandard, TokenTransfer, TransactionEvent, TransactionType, TransferUserAccounts}; +use std::sync::Arc; #[tokio::test] -async fn test_parse_transactions_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_parse_transactions_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_response = vec![EnhancedTransaction{ - account_data: vec![AccountData{ + let mock_response = vec![EnhancedTransaction { + account_data: vec![AccountData { account: "".to_string(), native_token_balance: Some(Number::from(10)), token_balance_changes: None, @@ -23,10 +27,11 @@ async fn test_parse_transactions_success(){ source: Source::Jupiter, fee: 5000, fee_payer: "8cRrU1NzNpjL3k2BwjW3VixAcX6VFc29KHr4KZg8cs2Y".to_string(), - signature: "yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK".to_string(), + signature: "yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK" + .to_string(), slot: 148277128, native_transfers: None, - token_transfers: Some(vec![TokenTransfer{ + token_transfers: Some(vec![TokenTransfer { user_accounts: TransferUserAccounts { from_user_account: Some("2iK5FbRZcJHAfhUNYmYdKTzSLnZE9NGAECurPoxDA3o7".to_string()), to_user_account: Some("DCAKxn5PFNN1mBREPWGdk1RXg5aVH9rPErLfBFEi2Emb".to_string()), @@ -38,11 +43,11 @@ async fn test_parse_transactions_success(){ mint: "6oCioNHNTh4Xoz33mQSoTW4mxxmnyWVBNgv7zHjUuBkK".to_string(), }]), transaction_error: None, - instructions: vec![Instruction{ + instructions: vec![Instruction { accounts: vec![], data: "kdL8HQJrbbvQRGXmoadaja1Qvs".to_string(), program_id: "MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8".to_string(), - inner_instructions: vec![InnerInstruction{ + inner_instructions: vec![InnerInstruction { accounts: vec![], data: "Dd1k91cWt84qJoQr3F".to_string(), program_id: "Dd1k91cWt84qJoQr3FT7EXQpSaMtZtwPwdho7RbMWtEV".to_string(), @@ -52,7 +57,8 @@ async fn test_parse_transactions_success(){ timestamp: 1656442333, }]; - server.mock("POST","/v0/transactions?api-key=fake_api_key") + server + .mock("POST", "/v0/transactions?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -68,30 +74,34 @@ async fn test_parse_transactions_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let request = ParseTransactionsRequest{ - transactions: vec!["DiG7v24AXRQqGagDx8pcVxRgVrgFoXUpJgp7xb62ycG9".to_string(), - "46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi".to_string()], + let request = ParseTransactionsRequest { + transactions: vec![ + "DiG7v24AXRQqGagDx8pcVxRgVrgFoXUpJgp7xb62ycG9".to_string(), + "46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi".to_string(), + ], }; let response = helius.parse_transactions(request).await; - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let tx_response = response.unwrap(); - assert_eq!(tx_response[0].signature,"yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK".to_string()); - assert_eq!(tx_response[0].transaction_type,TransactionType::Any); - + assert_eq!( + tx_response[0].signature, + "yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK".to_string() + ); + assert_eq!(tx_response[0].transaction_type, TransactionType::Any); } #[tokio::test] -async fn test_parse_transactions_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_parse_transactions_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); let config: Arc = Arc::new(Config { api_key: "fake_api_key".to_string(), @@ -102,32 +112,35 @@ async fn test_parse_transactions_failure(){ }, }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let request = ParseTransactionsRequest{ - transactions: vec!["DiG7v24AXRQqGagDx8pcVxRgVrgFoXUpJgp7xb62ycG9".to_string(), - "46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi".to_string()], + let request = ParseTransactionsRequest { + transactions: vec![ + "DiG7v24AXRQqGagDx8pcVxRgVrgFoXUpJgp7xb62ycG9".to_string(), + "46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi".to_string(), + ], }; - server.mock("POST","/v0/transactions?api-key=fake_api_key") + server + .mock("POST", "/v0/transactions?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) .create(); let response = helius.parse_transactions(request).await; - assert!(response.is_err(),"Expected an error due to server failure"); + assert!(response.is_err(), "Expected an error due to server failure"); } #[tokio::test] -async fn test_parse_transaction_history_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_parse_transaction_history_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_response = vec![EnhancedTransaction{ - account_data: vec![AccountData{ + let mock_response = vec![EnhancedTransaction { + account_data: vec![AccountData { account: "".to_string(), native_token_balance: Some(Number::from(10)), token_balance_changes: None, @@ -137,10 +150,11 @@ async fn test_parse_transaction_history_success(){ source: Source::Jupiter, fee: 5000, fee_payer: "8cRrU1NzNpjL3k2BwjW3VixAcX6VFc29KHr4KZg8cs2Y".to_string(), - signature: "yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK".to_string(), + signature: "yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK" + .to_string(), slot: 148277128, native_transfers: None, - token_transfers: Some(vec![TokenTransfer{ + token_transfers: Some(vec![TokenTransfer { user_accounts: TransferUserAccounts { from_user_account: Some("2iK5FbRZcJHAfhUNYmYdKTzSLnZE9NGAECurPoxDA3o7".to_string()), to_user_account: Some("DCAKxn5PFNN1mBREPWGdk1RXg5aVH9rPErLfBFEi2Emb".to_string()), @@ -152,11 +166,11 @@ async fn test_parse_transaction_history_success(){ mint: "6oCioNHNTh4Xoz33mQSoTW4mxxmnyWVBNgv7zHjUuBkK".to_string(), }]), transaction_error: None, - instructions: vec![Instruction{ + instructions: vec![Instruction { accounts: vec![], data: "kdL8HQJrbbvQRGXmoadaja1Qvs".to_string(), program_id: "MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8".to_string(), - inner_instructions: vec![InnerInstruction{ + inner_instructions: vec![InnerInstruction { accounts: vec![], data: "Dd1k91cWt84qJoQr3F".to_string(), program_id: "Dd1k91cWt84qJoQr3FT7EXQpSaMtZtwPwdho7RbMWtEV".to_string(), @@ -166,7 +180,11 @@ async fn test_parse_transaction_history_success(){ timestamp: 1656442333, }]; - let mock = server.mock("GET","/v0/addresses/46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi/transactions?api-key=fake_api_key") + let mock = server + .mock( + "GET", + "/v0/addresses/46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi/transactions?api-key=fake_api_key", + ) .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -182,32 +200,33 @@ async fn test_parse_transaction_history_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let request = ParsedTransactionHistoryRequest{ + let request = ParsedTransactionHistoryRequest { address: "46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi".to_string(), before: None, }; let response = helius.parsed_transaction_history(request).await; - - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let tx_response = response.unwrap(); - assert_eq!(tx_response[0].signature,"yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK".to_string()); - assert_eq!(tx_response[0].transaction_type,TransactionType::Any); - + assert_eq!( + tx_response[0].signature, + "yy5BT9benHhx8fGCvhcAfTtLEHAtRJ3hRTzVL16bdrTCWm63t2vapfrZQZLJC3RcuagekaXjSs2zUGQvbcto8DK".to_string() + ); + assert_eq!(tx_response[0].transaction_type, TransactionType::Any); } #[tokio::test] -async fn test_parse_transaction_history_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_parse_transaction_history_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); let config: Arc = Arc::new(Config { api_key: "fake_api_key".to_string(), @@ -218,22 +237,26 @@ async fn test_parse_transaction_history_failure(){ }, }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let request = ParsedTransactionHistoryRequest{ + let request = ParsedTransactionHistoryRequest { address: "46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi".to_string(), before: None, }; - server.mock("GET","/v0/addresses/46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi/transactions?api-key=fake_api_key") + server + .mock( + "GET", + "/v0/addresses/46tC8n6GyWvUjFxpTE9juG5WZ72RXADpPhY4S1d6wvTi/transactions?api-key=fake_api_key", + ) .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) .create(); let response = helius.parsed_transaction_history(request).await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + assert!(response.is_err(), "Expected an error due to server failure"); +} diff --git a/tests/tests.rs b/tests/tests.rs index bcbe7ac..fba8dbc 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -20,14 +20,13 @@ mod rpc { mod test_get_token_accounts; mod test_search_assets; } -mod webhook{ +mod webhook { mod test_create_webhook; mod test_edit_webhook; mod test_get_webhook_by_id; - mod test_get_all_webhooks; - mod test_delete_webhook; mod test_append_addresses_to_webhook; + mod test_delete_webhook; + mod test_get_all_webhooks; mod test_remove_addresses_from_webhook; - } diff --git a/tests/webhook/test_append_addresses_to_webhook.rs b/tests/webhook/test_append_addresses_to_webhook.rs index 2bc4f19..bb12d11 100644 --- a/tests/webhook/test_append_addresses_to_webhook.rs +++ b/tests/webhook/test_append_addresses_to_webhook.rs @@ -1,50 +1,48 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; use helius::error::HeliusError; -use helius::Helius; use helius::rpc_client::RpcClient; -use helius::types::{ Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; - - +use helius::types::{Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] -async fn test_append_addresses_to_webhook_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_append_addresses_to_webhook_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_get_webhook_by_id_response:Webhook = Webhook{ + let mock_get_webhook_by_id_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec![], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("GET","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_get_webhook_by_id_response).unwrap()) .create(); - let mock_response:Webhook = Webhook{ + let mock_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec!["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("PUT","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("PUT", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -60,52 +58,62 @@ async fn test_append_addresses_to_webhook_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; + let response = helius + .append_addresses_to_webhook( + "0e8250a1-ceec-4757-ad69", + &["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()], + ) + .await; - let response = helius.append_addresses_to_webhook("0e8250a1-ceec-4757-ad69",&["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()]).await; - - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let webhook_response = response.unwrap(); - assert_eq!(webhook_response.webhook_id,"0e8250a1-ceec-4757-ad69"); - assert_eq!(webhook_response.webhook_url,"https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc"); - assert_eq!(webhook_response.account_addresses,["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()]) + assert_eq!(webhook_response.webhook_id, "0e8250a1-ceec-4757-ad69"); + assert_eq!( + webhook_response.webhook_url, + "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc" + ); + assert_eq!( + webhook_response.account_addresses, + ["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()] + ) } #[tokio::test] -async fn test_append_addresses_to_webhook_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); - let mock_get_webhook_by_id_response:Webhook = Webhook{ +async fn test_append_addresses_to_webhook_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); + let mock_get_webhook_by_id_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec![], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("GET","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_get_webhook_by_id_response).unwrap()) .create(); - server.mock("PUT","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("PUT", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) .create(); - let config: Arc = Arc::new(Config { api_key: "fake_api_key".to_string(), cluster: Cluster::Devnet, @@ -115,14 +123,18 @@ async fn test_append_addresses_to_webhook_failure(){ }, }); - let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response:Result = helius.append_addresses_to_webhook("0e8250a1-ceec-4757-ad69",&["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()]).await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + let response: Result = helius + .append_addresses_to_webhook( + "0e8250a1-ceec-4757-ad69", + &["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()], + ) + .await; + assert!(response.is_err(), "Expected an error due to server failure"); +} diff --git a/tests/webhook/test_create_webhook.rs b/tests/webhook/test_create_webhook.rs index ad10324..7e495b1 100644 --- a/tests/webhook/test_create_webhook.rs +++ b/tests/webhook/test_create_webhook.rs @@ -1,33 +1,31 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; use helius::error::HeliusError; -use helius::Helius; use helius::rpc_client::RpcClient; -use helius::types::{ Cluster, CreateWebhookRequest, HeliusEndpoints, TransactionType, Webhook, WebhookType}; - - +use helius::types::{Cluster, CreateWebhookRequest, HeliusEndpoints, TransactionType, Webhook, WebhookType}; +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] -async fn test_create_webhook_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_create_webhook_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_response:Webhook = Webhook{ + let mock_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec![], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), project: "Mockito".to_string(), ..Default::default() }; - - server.mock("POST","/v0/webhooks/?api-key=fake_api_key") + server + .mock("POST", "/v0/webhooks/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -43,38 +41,39 @@ async fn test_create_webhook_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let request = CreateWebhookRequest{ + let request = CreateWebhookRequest { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec![], webhook_type: WebhookType::Enhanced, auth_header: None, - .. Default::default() - + ..Default::default() }; - let response = helius.create_webhook(request).await; + let response = helius.create_webhook(request).await; - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let webhook_response = response.unwrap(); - assert_eq!(webhook_response.webhook_id,"0e8250a1-ceec-4757-ad69"); - assert_eq!(webhook_response.webhook_url,"https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc") + assert_eq!(webhook_response.webhook_id, "0e8250a1-ceec-4757-ad69"); + assert_eq!( + webhook_response.webhook_url, + "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc" + ) } #[tokio::test] -async fn test_create_webhook_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); - +async fn test_create_webhook_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); server - .mock("POST","/v0/webhooks/?api-key=fake_api_key") + .mock("POST", "/v0/webhooks/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) @@ -87,23 +86,22 @@ async fn test_create_webhook_failure(){ rpc: url.to_string(), }, }); - let request = CreateWebhookRequest{ + let request = CreateWebhookRequest { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec![], webhook_type: WebhookType::Enhanced, auth_header: None, - .. Default::default() - + ..Default::default() }; let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response:Result = helius.create_webhook(request).await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + let response: Result = helius.create_webhook(request).await; + assert!(response.is_err(), "Expected an error due to server failure"); +} diff --git a/tests/webhook/test_delete_webhook.rs b/tests/webhook/test_delete_webhook.rs index 3641b17..2a23548 100644 --- a/tests/webhook/test_delete_webhook.rs +++ b/tests/webhook/test_delete_webhook.rs @@ -1,20 +1,18 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; -use helius::Helius; use helius::rpc_client::RpcClient; -use helius::types::{ Cluster, HeliusEndpoints}; - - +use helius::types::{Cluster, HeliusEndpoints}; +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] -async fn test_delete_webhook_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_delete_webhook_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - - server.mock("DELETE","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("DELETE", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .create(); @@ -29,27 +27,25 @@ async fn test_delete_webhook_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response = helius.delete_webhook("0e8250a1-ceec-4757-ad69").await; - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); - + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); } #[tokio::test] -async fn test_delete_webhook_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); - +async fn test_delete_webhook_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - server.mock("DELETE","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("DELETE", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) @@ -64,14 +60,13 @@ async fn test_delete_webhook_failure(){ }, }); - let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response= helius.delete_webhook("0e8250a1-ceec-4757-ad69").await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + let response = helius.delete_webhook("0e8250a1-ceec-4757-ad69").await; + assert!(response.is_err(), "Expected an error due to server failure"); +} diff --git a/tests/webhook/test_edit_webhook.rs b/tests/webhook/test_edit_webhook.rs index 5037ecc..29ebee8 100644 --- a/tests/webhook/test_edit_webhook.rs +++ b/tests/webhook/test_edit_webhook.rs @@ -1,33 +1,31 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; use helius::error::HeliusError; -use helius::Helius; use helius::rpc_client::RpcClient; use helius::types::{Cluster, EditWebhookRequest, HeliusEndpoints, TransactionType, Webhook, WebhookType}; - - +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] -async fn test_edit_webhook_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_edit_webhook_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_response:Webhook = Webhook{ + let mock_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec!["9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string()], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), project: "Mockito".to_string(), ..Default::default() }; - - server.mock("PUT","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("PUT", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -43,14 +41,14 @@ async fn test_edit_webhook_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let request = EditWebhookRequest{ + let request = EditWebhookRequest { webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], @@ -62,22 +60,26 @@ async fn test_edit_webhook_success(){ }; let response = helius.edit_webhook(request).await; - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let webhook_response = response.unwrap(); - assert_eq!(webhook_response.webhook_id,"0e8250a1-ceec-4757-ad69"); - assert_eq!(webhook_response.webhook_url,"https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc"); - assert_eq!(webhook_response.account_addresses,vec!["9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string()]); - + assert_eq!(webhook_response.webhook_id, "0e8250a1-ceec-4757-ad69"); + assert_eq!( + webhook_response.webhook_url, + "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc" + ); + assert_eq!( + webhook_response.account_addresses, + vec!["9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string()] + ); } #[tokio::test] -async fn test_edit_webhook_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); - +async fn test_edit_webhook_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); server - .mock("PUT","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + .mock("PUT", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) @@ -90,7 +92,7 @@ async fn test_edit_webhook_failure(){ rpc: url.to_string(), }, }); - let request = EditWebhookRequest{ + let request = EditWebhookRequest { webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], @@ -102,12 +104,12 @@ async fn test_edit_webhook_failure(){ }; let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response:Result = helius.edit_webhook(request).await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + let response: Result = helius.edit_webhook(request).await; + assert!(response.is_err(), "Expected an error due to server failure"); +} diff --git a/tests/webhook/test_get_all_webhooks.rs b/tests/webhook/test_get_all_webhooks.rs index 326798a..b472d23 100644 --- a/tests/webhook/test_get_all_webhooks.rs +++ b/tests/webhook/test_get_all_webhooks.rs @@ -1,12 +1,11 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; use helius::error::HeliusError; -use helius::Helius; use helius::rpc_client::RpcClient; use helius::types::{Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; - +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] async fn test_get_all_webhooks_success() { @@ -23,8 +22,8 @@ async fn test_get_all_webhooks_success() { ..Default::default() }]; - - server.mock("GET", "/v0/webhooks/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -47,14 +46,16 @@ async fn test_get_all_webhooks_success() { rpc_client, }; - let response = helius.get_all_webhooks().await; assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let webhook_response = response.unwrap(); - assert_eq!(webhook_response.len(),1); + assert_eq!(webhook_response.len(), 1); assert_eq!(webhook_response[0].webhook_id, "0e8250a1-ceec-4757-ad69"); - assert_eq!(webhook_response[0].webhook_url, "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc") + assert_eq!( + webhook_response[0].webhook_url, + "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc" + ) } #[tokio::test] @@ -62,8 +63,8 @@ async fn test_get_all_webhooks_failure() { let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; let url: String = format!("{}/", server.url()); - - server.mock("GET", "/v0/webhooks/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) @@ -78,7 +79,6 @@ async fn test_get_all_webhooks_failure() { }, }); - let client: Client = Client::new(); let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); let helius = Helius { @@ -88,4 +88,4 @@ async fn test_get_all_webhooks_failure() { }; let response: Result, HeliusError> = helius.get_all_webhooks().await; assert!(response.is_err(), "Expected an error due to server failure"); -} \ No newline at end of file +} diff --git a/tests/webhook/test_get_webhook_by_id.rs b/tests/webhook/test_get_webhook_by_id.rs index 51d7ae3..2d88478 100644 --- a/tests/webhook/test_get_webhook_by_id.rs +++ b/tests/webhook/test_get_webhook_by_id.rs @@ -1,32 +1,30 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; use helius::error::HeliusError; -use helius::Helius; use helius::rpc_client::RpcClient; -use helius::types::{ Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; - - +use helius::types::{Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] -async fn test_get_webhook_by_id_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_get_webhook_by_id_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_response:Webhook = Webhook{ + let mock_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec![], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("GET","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -42,29 +40,31 @@ async fn test_get_webhook_by_id_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response = helius.get_webhook_by_id("0e8250a1-ceec-4757-ad69").await; - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let webhook_response = response.unwrap(); - assert_eq!(webhook_response.webhook_id,"0e8250a1-ceec-4757-ad69"); - assert_eq!(webhook_response.webhook_url,"https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc") + assert_eq!(webhook_response.webhook_id, "0e8250a1-ceec-4757-ad69"); + assert_eq!( + webhook_response.webhook_url, + "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc" + ) } #[tokio::test] -async fn test_get_webhook_by_id_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_get_webhook_by_id_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - - server.mock("GET","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) @@ -79,14 +79,13 @@ async fn test_get_webhook_by_id_failure(){ }, }); - let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response:Result = helius.get_webhook_by_id("0e8250a1-ceec-4757-ad69").await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + let response: Result = helius.get_webhook_by_id("0e8250a1-ceec-4757-ad69").await; + assert!(response.is_err(), "Expected an error due to server failure"); +} diff --git a/tests/webhook/test_remove_addresses_from_webhook.rs b/tests/webhook/test_remove_addresses_from_webhook.rs index bfb0318..722d4cd 100644 --- a/tests/webhook/test_remove_addresses_from_webhook.rs +++ b/tests/webhook/test_remove_addresses_from_webhook.rs @@ -1,52 +1,52 @@ -use std::sync::Arc; -use mockito::Server; -use reqwest::{Client}; use helius::config::Config; use helius::error::HeliusError; -use helius::Helius; use helius::rpc_client::RpcClient; -use helius::types::{ Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; - - +use helius::types::{Cluster, HeliusEndpoints, TransactionType, Webhook, WebhookType}; +use helius::Helius; +use mockito::Server; +use reqwest::Client; +use std::sync::Arc; #[tokio::test] -async fn test_remove_addresses_from_webhook_success(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); +async fn test_remove_addresses_from_webhook_success() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); - let mock_get_webhook_by_id_response:Webhook = Webhook{ + let mock_get_webhook_by_id_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], - account_addresses: vec!["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string(), - "43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), - "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string()], + account_addresses: vec![ + "71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string(), + "43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), + "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string(), + ], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("GET","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_get_webhook_by_id_response).unwrap()) .create(); - let mock_response:Webhook = Webhook{ + let mock_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], account_addresses: vec!["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("PUT","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("PUT", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_response).unwrap()) @@ -62,56 +62,69 @@ async fn test_remove_addresses_from_webhook_success(){ }); let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - - let response = helius.remove_addresses_from_webhook("0e8250a1-ceec-4757-ad69",&["43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), - "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string()]) + let response = helius + .remove_addresses_from_webhook( + "0e8250a1-ceec-4757-ad69", + &[ + "43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), + "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string(), + ], + ) .await; - assert!(response.is_ok(),"The API call failed: {:?}",response.err()); + assert!(response.is_ok(), "The API call failed: {:?}", response.err()); let webhook_response = response.unwrap(); - assert_eq!(webhook_response.webhook_id,"0e8250a1-ceec-4757-ad69"); - assert_eq!(webhook_response.webhook_url,"https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc"); - assert_eq!(webhook_response.account_addresses,["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()]) + assert_eq!(webhook_response.webhook_id, "0e8250a1-ceec-4757-ad69"); + assert_eq!( + webhook_response.webhook_url, + "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc" + ); + assert_eq!( + webhook_response.account_addresses, + ["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string()] + ) } #[tokio::test] -async fn test_remove_addresses_from_webhook_failure(){ - let mut server:Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; - let url:String = format!("{}/",server.url()); - let mock_get_webhook_by_id_response:Webhook = Webhook{ +async fn test_remove_addresses_from_webhook_failure() { + let mut server: Server = Server::new_with_opts_async(mockito::ServerOpts::default()).await; + let url: String = format!("{}/", server.url()); + let mock_get_webhook_by_id_response: Webhook = Webhook { webhook_url: "https://webhook.site/0e8250a1-ceec-4757-ad69-cc6473085bfc".to_string(), transaction_types: vec![TransactionType::Any], - account_addresses: vec!["71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string(), - "43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), - "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string()], + account_addresses: vec![ + "71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6".to_string(), + "43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), + "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string(), + ], webhook_type: WebhookType::Enhanced, auth_header: None, - webhook_id:"0e8250a1-ceec-4757-ad69".to_string(), + webhook_id: "0e8250a1-ceec-4757-ad69".to_string(), wallet: "9Jt8mC9HXvh2g5s3PbTsNU71RS9MXUbhEMEmLTixYirb".to_string(), ..Default::default() }; - - server.mock("GET","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("GET", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(200) .with_header("Content-Type", "application/json") .with_body(serde_json::to_string(&mock_get_webhook_by_id_response).unwrap()) .create(); - server.mock("PUT","/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") + server + .mock("PUT", "/v0/webhooks/0e8250a1-ceec-4757-ad69/?api-key=fake_api_key") .with_status(500) .with_header("Content-Type", "application/json") .with_body(r#"{"error":"Internal Server Error"}"#) .create(); - let config: Arc = Arc::new(Config { api_key: "fake_api_key".to_string(), cluster: Cluster::Devnet, @@ -121,16 +134,21 @@ async fn test_remove_addresses_from_webhook_failure(){ }, }); - let client: Client = Client::new(); - let rpc_client:Arc = Arc::new(RpcClient::new(Arc::new(client.clone()),Arc::clone(&config)).unwrap()); - let helius = Helius{ + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + let helius = Helius { config, client, rpc_client, }; - let response:Result = helius.remove_addresses_from_webhook("0e8250a1-ceec-4757-ad69",&["43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), - "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string()]) + let response: Result = helius + .remove_addresses_from_webhook( + "0e8250a1-ceec-4757-ad69", + &[ + "43oydK3fgeJ6AphxyKkK7h73JfF6CQvWx8Cg9gKe3tLu".to_string(), + "5ZGeSwv1KjUwhatJB5v4nwwQJqXN5odzHALRftLqZ6SM".to_string(), + ], + ) .await; - assert!(response.is_err(),"Expected an error due to server failure"); -} \ No newline at end of file + assert!(response.is_err(), "Expected an error due to server failure"); +}