Skip to main content

wallet_adapter_common/
lib.rs

1#![forbid(unsafe_code)]
2#![forbid(missing_docs)]
3
4//! Common utilities to identify features and chains in the `wallet-adapter` standard.
5
6mod errors;
7pub use errors::*;
8
9mod wallet_account;
10pub use wallet_account::*;
11
12mod wallet;
13pub use wallet::*;
14
15mod version;
16pub use version::*;
17
18mod utils;
19pub use utils::*;
20
21/// Feature support struct
22pub mod feature_support;
23
24/// The Solana identifiers for standardized events of the `wallet-adapter`
25pub mod standardized_events;
26
27/// The Solana signin standard `solana:signIn` the `wallet-adapter`
28pub mod signin_standard;
29
30/// Supported `chains` of the Solana `wallet-adapter` standard
31pub mod chains;
32
33/// Cluster identifiers for Solana `wallet-adapter` standard
34pub mod clusters;
35
36#[cfg(test)]
37mod chain_tests {
38    use super::clusters::*;
39
40    #[test]
41    fn is_valid_uri() {
42        assert_eq!(MAINNET_ENDPOINT, "https://api.mainnet-beta.solana.com");
43        assert_eq!(DEVNET_ENDPOINT, "https://api.devnet.solana.com");
44        assert_eq!(TESTNET_ENDPOINT, "https://api.testnet.solana.com");
45        assert_eq!(LOCALNET_ENDPOINT, "http://localhost:8899");
46
47        assert_eq!(MAINNET_IDENTIFIER, "solana:mainnet");
48        assert_eq!(DEVNET_IDENTIFIER, "solana:devnet");
49        assert_eq!(TESTNET_IDENTIFIER, "solana:testnet");
50        assert_eq!(LOCALNET_IDENTIFIER, "solana:localnet");
51    }
52
53    #[test]
54    fn valid_chain() {
55        assert_eq!(Cluster::MainNet, "solana:mainnet".into());
56        assert_eq!(Cluster::DevNet, "solana:devnet".into());
57        assert_eq!(Cluster::TestNet, "solana:testnet".into());
58        assert_eq!(Cluster::LocalNet, "solana:localnet".into());
59        assert!(Cluster::DevNet == "solana:localnet2".into());
60
61        assert_eq!(
62            Cluster::MainNet,
63            "https://api.mainnet-beta.solana.com".into()
64        );
65        assert_eq!(Cluster::DevNet, "https://api.devnet.solana.com".into());
66        assert_eq!(Cluster::TestNet, "https://api.testnet.solana.com".into());
67        assert_eq!(Cluster::LocalNet, "http://localhost:8899".into());
68        assert!(Cluster::DevNet == "https://localhost:8899".into());
69        assert!(Cluster::DevNet == "https://cluster.foo".into());
70    }
71
72    #[test]
73    fn validate_endpoint() {
74        assert_eq!(
75            Cluster::MainNet.endpoint(),
76            "https://api.mainnet-beta.solana.com"
77        );
78        assert_eq!(Cluster::DevNet.endpoint(), "https://api.devnet.solana.com");
79        assert_eq!(
80            Cluster::TestNet.endpoint(),
81            "https://api.testnet.solana.com"
82        );
83        assert_eq!(Cluster::LocalNet.endpoint(), "http://localhost:8899");
84    }
85}