Skip to content

Commit

Permalink
Fix Config and Endpoints Update Breaking Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed Apr 24, 2024
1 parent 053499b commit 93b9ec3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::Result;
use crate::error::{ HeliusError, Result };
use crate::types::{Cluster, HeliusEndpoints};

#[derive(Clone)]
Expand All @@ -10,7 +10,12 @@ pub struct Config {

impl Config {
pub fn new(api_key: &str, cluster: Cluster) -> Result<Self> {
if api_key.is_empty() {
return Err(HeliusError::InvalidInput("API key cannot be empty".to_string()));
}

let endpoints: HeliusEndpoints = HeliusEndpoints::for_cluster(&cluster);

Ok(Config {
api_key: api_key.to_string(),
cluster,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fn test_config_new_with_valid_api_key() {

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");
assert_eq!(config.endpoints.api, "https://api-devnet.helius-rpc.com/");
assert_eq!(config.endpoints.rpc, "https://devnet.helius-rpc.com/");
}
8 changes: 4 additions & 4 deletions tests/test_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fn test_factory_create_devnet_instance() {
let helius: Helius = factory.create(Cluster::Devnet).unwrap();

assert_eq!(helius.config.api_key, "valid_api_key");
assert_eq!(helius.config.endpoints.api, "https://api-devnet.helius-rpc.com");
assert_eq!(helius.config.endpoints.rpc, "https://devnet.helius-rpc.com");
assert_eq!(helius.config.endpoints.api, "https://api-devnet.helius-rpc.com/");
assert_eq!(helius.config.endpoints.rpc, "https://devnet.helius-rpc.com/");
}

#[test]
Expand All @@ -17,6 +17,6 @@ fn test_factory_create_mainnet_instance() {
let helius: Helius = factory.create(Cluster::MainnetBeta).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://mainnet.helius-rpc.com");
assert_eq!(helius.config.endpoints.api, "https://api-mainnet.helius-rpc.com/");
assert_eq!(helius.config.endpoints.rpc, "https://mainnet.helius-rpc.com/");
}

0 comments on commit 93b9ec3

Please sign in to comment.