From 9d6c861791a359e2c950b27f6b6b1da253bb05ba Mon Sep 17 00:00:00 2001 From: Anam Ansari Date: Thu, 29 Aug 2024 00:43:25 +0530 Subject: [PATCH 1/2] fix: support for staked endpoint rpc --- Cargo.toml | 12 ++++++------ src/types/enums.rs | 3 +++ src/types/types.rs | 11 ++++++++--- tests/test_client.rs | 4 ++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 742811f..70994f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,12 +24,12 @@ semver = "1.0.23" serde = "1.0.198" serde-enum-str = "0.4.0" serde_json = "1.0.116" -solana-account-decoder = "=1.18.12" -solana-client = "=1.18.12" -solana-program = "=1.18.12" -solana-rpc-client-api = "=1.18.12" -solana-sdk = "=1.18.12" -solana-transaction-status = "=1.18.12" +solana-account-decoder = "=2.0.7" +solana-client = "=2.0.7" +solana-program = "=2.0.7" +solana-rpc-client-api = "=2.0.7" +solana-sdk = "=2.0.7" +solana-transaction-status = "=2.0.7" thiserror = "1.0.58" tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread", "net"] } tokio-stream = "0.1.15" diff --git a/src/types/enums.rs b/src/types/enums.rs index 8600745..88365ce 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -149,6 +149,9 @@ impl MintApiAuthority { Cluster::MainnetBeta => Ok(MintApiAuthority::Mainnet( "HnT5KVAywGgQDhmh6Usk4bxRg4RwKxCK4jmECyaDth5R", )), + Cluster::StakedMainnetBeta => Ok(MintApiAuthority::Mainnet( + "HnT5KVAywGgQDhmh6Usk4bxRg4RwKxCK4jmECyaDth5R", + )) } } } diff --git a/src/types/types.rs b/src/types/types.rs index 3bd1a0f..c4eddc6 100644 --- a/src/types/types.rs +++ b/src/types/types.rs @@ -16,13 +16,14 @@ use solana_sdk::{address_lookup_table::AddressLookupTableAccount, instruction::I pub enum Cluster { Devnet, MainnetBeta, + StakedMainnetBeta } /// Stores the API and RPC endpoint URLs for a specific Helius cluster #[derive(Debug, Clone)] pub struct HeliusEndpoints { pub api: String, - pub rpc: String, + pub rpc: String } impl HeliusEndpoints { @@ -30,12 +31,16 @@ impl HeliusEndpoints { match cluster { Cluster::Devnet => HeliusEndpoints { api: "https://api-devnet.helius-rpc.com/".to_string(), - rpc: "https://devnet.helius-rpc.com/".to_string(), + rpc: "https://devnet.helius-rpc.com/".to_string() }, Cluster::MainnetBeta => HeliusEndpoints { api: "https://api-mainnet.helius-rpc.com/".to_string(), - rpc: "https://mainnet.helius-rpc.com/".to_string(), + rpc: "https://mainnet.helius-rpc.com/".to_string() }, + Cluster::StakedMainnetBeta => HeliusEndpoints { + api: "https://api-mainnet.helius-rpc.com/".to_string(), + rpc: "https://staked.helius-rpc.com/".to_string() + } } } } diff --git a/tests/test_client.rs b/tests/test_client.rs index bc8b2e9..e7e9104 100644 --- a/tests/test_client.rs +++ b/tests/test_client.rs @@ -5,7 +5,7 @@ use helius::types::Cluster; #[test] fn test_creating_new_client_success() { let api_key: &str = "valid-api-key"; - let cluster: Cluster = Cluster::Devnet; + let cluster: Cluster = Cluster::StakedMainnetBeta; let result: Result = Helius::new(api_key, cluster); assert!(result.is_ok()); @@ -17,7 +17,7 @@ fn test_creating_new_client_success() { #[test] fn test_creating_new_async_client_success() { let api_key: &str = "valid-api-key"; - let cluster: Cluster = Cluster::Devnet; + let cluster: Cluster = Cluster::StakedMainnetBeta; let result: Result = Helius::new_with_async_solana(api_key, cluster); assert!(result.is_ok()); From 1897624513c610b467e420637140905426c362db Mon Sep 17 00:00:00 2001 From: Anam Ansari Date: Fri, 30 Aug 2024 13:07:20 +0530 Subject: [PATCH 2/2] chore: client test for staked connection --- src/types/enums.rs | 2 +- src/types/types.rs | 12 ++++++------ tests/test_client.rs | 4 ++-- tests/test_client_staked.rs | 28 ++++++++++++++++++++++++++++ tests/test_factory.rs | 10 ++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 tests/test_client_staked.rs diff --git a/src/types/enums.rs b/src/types/enums.rs index 88365ce..bed9b46 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -151,7 +151,7 @@ impl MintApiAuthority { )), Cluster::StakedMainnetBeta => Ok(MintApiAuthority::Mainnet( "HnT5KVAywGgQDhmh6Usk4bxRg4RwKxCK4jmECyaDth5R", - )) + )), } } } diff --git a/src/types/types.rs b/src/types/types.rs index c4eddc6..002b4fa 100644 --- a/src/types/types.rs +++ b/src/types/types.rs @@ -16,14 +16,14 @@ use solana_sdk::{address_lookup_table::AddressLookupTableAccount, instruction::I pub enum Cluster { Devnet, MainnetBeta, - StakedMainnetBeta + StakedMainnetBeta, } /// Stores the API and RPC endpoint URLs for a specific Helius cluster #[derive(Debug, Clone)] pub struct HeliusEndpoints { pub api: String, - pub rpc: String + pub rpc: String, } impl HeliusEndpoints { @@ -31,16 +31,16 @@ impl HeliusEndpoints { match cluster { Cluster::Devnet => HeliusEndpoints { api: "https://api-devnet.helius-rpc.com/".to_string(), - rpc: "https://devnet.helius-rpc.com/".to_string() + rpc: "https://devnet.helius-rpc.com/".to_string(), }, Cluster::MainnetBeta => HeliusEndpoints { api: "https://api-mainnet.helius-rpc.com/".to_string(), - rpc: "https://mainnet.helius-rpc.com/".to_string() + rpc: "https://mainnet.helius-rpc.com/".to_string(), }, Cluster::StakedMainnetBeta => HeliusEndpoints { api: "https://api-mainnet.helius-rpc.com/".to_string(), - rpc: "https://staked.helius-rpc.com/".to_string() - } + rpc: "https://staked.helius-rpc.com/".to_string(), + }, } } } diff --git a/tests/test_client.rs b/tests/test_client.rs index e7e9104..bc8b2e9 100644 --- a/tests/test_client.rs +++ b/tests/test_client.rs @@ -5,7 +5,7 @@ use helius::types::Cluster; #[test] fn test_creating_new_client_success() { let api_key: &str = "valid-api-key"; - let cluster: Cluster = Cluster::StakedMainnetBeta; + let cluster: Cluster = Cluster::Devnet; let result: Result = Helius::new(api_key, cluster); assert!(result.is_ok()); @@ -17,7 +17,7 @@ fn test_creating_new_client_success() { #[test] fn test_creating_new_async_client_success() { let api_key: &str = "valid-api-key"; - let cluster: Cluster = Cluster::StakedMainnetBeta; + let cluster: Cluster = Cluster::Devnet; let result: Result = Helius::new_with_async_solana(api_key, cluster); assert!(result.is_ok()); diff --git a/tests/test_client_staked.rs b/tests/test_client_staked.rs new file mode 100644 index 0000000..f529799 --- /dev/null +++ b/tests/test_client_staked.rs @@ -0,0 +1,28 @@ +use helius::client::Helius; +use helius::error::Result; +use helius::types::Cluster; + +#[test] +fn test_creating_new_client_staked_success() { + let api_key: &str = "valid-api-key"; + let cluster: Cluster = Cluster::StakedMainnetBeta; + + 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); +} + +#[test] +fn test_creating_new_async_client_staked_success() { + let api_key: &str = "valid-api-key"; + let cluster: Cluster = Cluster::StakedMainnetBeta; + + let result: Result = Helius::new_with_async_solana(api_key, cluster); + assert!(result.is_ok()); + + let helius: Helius = result.unwrap(); + assert_eq!(helius.config.api_key, api_key); + assert!(helius.async_rpc_client.is_some()); +} diff --git a/tests/test_factory.rs b/tests/test_factory.rs index 92c6787..55826eb 100644 --- a/tests/test_factory.rs +++ b/tests/test_factory.rs @@ -21,6 +21,16 @@ fn test_factory_create_mainnet_instance() { assert_eq!(helius.config.endpoints.rpc, "https://mainnet.helius-rpc.com/"); } +#[test] +fn test_factory_create_staked_mainnet_instance() { + let factory: HeliusFactory = HeliusFactory::new("valid_api_key"); + let helius: Helius = factory.create(Cluster::StakedMainnetBeta).unwrap(); + + assert_eq!(helius.config.api_key, "valid_api_key"); + assert_eq!(helius.config.endpoints.api, "https://api-mainnet.helius-rpc.com/"); + assert_eq!(helius.config.endpoints.rpc, "https://staked.helius-rpc.com/"); +} + #[test] fn test_factory_create_with_reqwest() { let mut factory = HeliusFactory::new("valid_api_key");