From f8302c4a3ab7a42e158748ea78ceba1dcb69b402 Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Wed, 17 Apr 2024 20:35:34 -0400 Subject: [PATCH] General Updates n Add test_client.rs --- src/client.rs | 4 ++-- src/config.rs | 1 - src/error.rs | 1 - tests/test_client.rs | 15 +++++++++++++++ tests/test_config.rs | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tests/test_client.rs diff --git a/src/client.rs b/src/client.rs index 8f092ef..737a6ec 100644 --- a/src/client.rs +++ b/src/client.rs @@ -7,8 +7,8 @@ use crate::types::Cluster; use reqwest::Client; pub struct Helius { - config: Config, - client: Client, + pub config: Config, + pub client: Client, } impl Helius { diff --git a/src/config.rs b/src/config.rs index db4d327..986c500 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,7 +13,6 @@ impl Config { return Err(HeliusError::InvalidInput("API key must not be empty".to_string())); } - let endpoints: HeliusEndpoints = match cluster { Cluster::Devnet => HeliusEndpoints { api: "https://api-devnet.helius-rpc.com".to_string(), diff --git a/src/error.rs b/src/error.rs index c6a463c..64f9eca 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,7 +22,6 @@ pub enum HeliusError { #[error("Unknown error has occurred: HTTP {code} - {text}")] Unknown { code: StatusCode, text: String }, } - // Handy type alias pub type Result = std::result::Result; \ No newline at end of file diff --git a/tests/test_client.rs b/tests/test_client.rs new file mode 100644 index 0000000..52c60b8 --- /dev/null +++ b/tests/test_client.rs @@ -0,0 +1,15 @@ +use helius_rust_sdk::client::Helius; +use helius_rust_sdk::error::HeliusError; +use helius_rust_sdk::types::Cluster; + +#[test] +fn test_creating_new_client_success() { + let api_key: &str = "valid-api-key"; + let cluster: Cluster = Cluster::Devnet; + + let result: Result = Helius::new(api_key, cluster); + assert!(result.is_ok()); + + let helius: Helius = result.unwrap(); + assert_eq!(helius.config.api_key, api_key); +} \ No newline at end of file diff --git a/tests/test_config.rs b/tests/test_config.rs index 93aecb4..0dd3631 100644 --- a/tests/test_config.rs +++ b/tests/test_config.rs @@ -13,7 +13,7 @@ fn test_config_new_with_valid_api_key() { let result: Result = Config::new("valid-api-key", Cluster::Devnet); assert!(result.is_ok()); - let config = result.unwrap(); + let config: Config = result.unwrap(); assert_eq!(config.api_key, "valid-api-key"); assert_eq!(config.endpoints.api, "https://api-devnet.helius-rpc.com"); assert_eq!(config.endpoints.rpc, "https://devnet.helius-rpc.com");