Skip to content

Commit

Permalink
Add MintApiAuthority
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed Apr 30, 2024
1 parent 3ba2c5d commit d6c3ff5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/types/enums.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};

use super::*;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub enum Interface {
#[serde(rename = "V1_NFT")]
Expand Down Expand Up @@ -131,3 +133,20 @@ pub enum TokenType {
RegularNft,
All,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MintApiAuthority {
Mainnet(&'static str),
Devnet(&'static str),
}

impl MintApiAuthority {
pub fn from_cluster(cluster: Cluster) -> Result<Self, &'static str> {
match cluster {
Cluster::Devnet => Ok(MintApiAuthority::Devnet("2LbAtCJSaHqTnP9M5QSjvAMXk79RNLusFspFN5Ew67TC")),
Cluster::MainnetBeta => Ok(MintApiAuthority::Mainnet(
"HnT5KVAywGgQDhmh6Usk4bxRg4RwKxCK4jmECyaDth5R",
)),
}
}
}
40 changes: 40 additions & 0 deletions tests/test_mint_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,43 @@ async fn test_get_asset_proof_failure() {
let result: Result<MintResponse, HeliusError> = helius.mint_compressed_nft(request).await;
assert!(result.is_err(), "Expected an error but got success");
}

#[tokio::test]
async fn test_mint_api_authority_from_cluster_success() {
let devnet_cluster: Cluster = Cluster::Devnet;
let mainnet_cluster: Cluster = Cluster::MainnetBeta;

let devnet_authority: Result<MintApiAuthority, &str> = MintApiAuthority::from_cluster(devnet_cluster);
let mainnet_authority: Result<MintApiAuthority, &str> = MintApiAuthority::from_cluster(mainnet_cluster);

assert_eq!(
devnet_authority.unwrap(),
MintApiAuthority::Devnet("2LbAtCJSaHqTnP9M5QSjvAMXk79RNLusFspFN5Ew67TC"),
"Devnet authority did not match expected value"
);
assert_eq!(
mainnet_authority.unwrap(),
MintApiAuthority::Mainnet("HnT5KVAywGgQDhmh6Usk4bxRg4RwKxCK4jmECyaDth5R"),
"Mainnet authority did not match expected value"
);
}

#[tokio::test]
async fn test_mint_api_authority_from_cluster_failure() {
let devnet_cluster: Cluster = Cluster::Devnet;
let mainnet_cluster: Cluster = Cluster::MainnetBeta;

let devnet_authority: Result<MintApiAuthority, &str> = MintApiAuthority::from_cluster(devnet_cluster);
let mainnet_authority: Result<MintApiAuthority, &str> = MintApiAuthority::from_cluster(mainnet_cluster);

assert_ne!(
devnet_authority.unwrap(),
MintApiAuthority::Devnet("Blade"),
"Devnet authority did not match expected value"
);
assert_ne!(
mainnet_authority.unwrap(),
MintApiAuthority::Mainnet("Deacon Frost"),
"Mainnet authority did not match expected value"
);
}

0 comments on commit d6c3ff5

Please sign in to comment.