@@ -2,26 +2,27 @@ use solana_client::nonblocking::rpc_client::RpcClient;
22use solana_sdk:: {
33 commitment_config:: CommitmentConfig ,
44 pubkey:: Pubkey ,
5+ signer:: { keypair:: Keypair , Signer } ,
56} ;
67
78#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
8- async fn test_blockchain_operations ( ) {
9+ async fn test_solana_operations ( ) {
910 // Connect to Solana devnet
11+ // Use Solana's devnet endpoint
12+ // Use official devnet with longer timeout
1013 let rpc_url = "https://api.opensvm.com" . to_string ( ) ;
11- let client = RpcClient :: new_with_commitment ( rpc_url. clone ( ) , CommitmentConfig :: confirmed ( ) ) ;
14+ let timeout = std:: time:: Duration :: from_secs ( 60 ) ;
15+ let commitment = CommitmentConfig :: finalized ( ) ;
16+ let client = RpcClient :: new_with_timeout_and_commitment ( rpc_url. clone ( ) , timeout, commitment) ;
1217
13- // Configure RPC client to support latest transaction versions
14- let config = solana_client:: rpc_config:: RpcBlockConfig {
15- encoding : None ,
16- transaction_details : None ,
17- rewards : None ,
18- commitment : None ,
19- max_supported_transaction_version : Some ( 0 ) ,
20- } ;
21-
2218 println ! ( "\n Testing health check:" ) ;
23- let health = client. get_health ( ) . await . unwrap ( ) ;
24- println ! ( "Health status: {:?}" , health) ;
19+ match client. get_health ( ) . await {
20+ Ok ( health) => println ! ( "Health status: {:?}" , health) ,
21+ Err ( err) => {
22+ println ! ( "Error details: {:?}" , err) ;
23+ panic ! ( "Health check failed: {}" , err) ;
24+ }
25+ }
2526
2627 println ! ( "\n Testing version info:" ) ;
2728 let version = client. get_version ( ) . await . unwrap ( ) ;
@@ -56,13 +57,39 @@ async fn test_blockchain_operations() {
5657 }
5758 }
5859
59- // Get block data using a slot we know exists from recent transactions
60- if let Some ( first_sig) = signatures. first ( ) {
61- println ! ( "\n Testing block data for slot {}:" , first_sig. slot) ;
62- let block = client. get_block_with_config ( first_sig. slot , config) . await ;
63- match block {
64- Ok ( block) => println ! ( "Block data: {:#?}" , block) ,
65- Err ( e) => println ! ( "Could not fetch block: {}" , e) ,
66- }
60+ // Test creating a new keypair and getting its info
61+ println ! ( "\n Testing keypair operations:" ) ;
62+ let keypair = Keypair :: new ( ) ;
63+ let pubkey = keypair. pubkey ( ) ;
64+ println ! ( "Generated keypair with pubkey: {}" , pubkey) ;
65+
66+ // Get account info (should be empty/not found)
67+ match client. get_account ( & pubkey) . await {
68+ Ok ( account) => println ! ( "Account exists with {} lamports" , account. lamports) ,
69+ Err ( e) => println ! ( "Account not found as expected: {}" , e) ,
70+ }
71+
72+ // Get minimum rent
73+ println ! ( "\n Testing rent calculation:" ) ;
74+ let rent = client. get_minimum_balance_for_rent_exemption ( 0 ) . await . unwrap ( ) ;
75+ println ! ( "Minimum balance for rent exemption: {} lamports" , rent) ;
76+
77+ // Get recent block
78+ println ! ( "\n Testing block info:" ) ;
79+ let slot = client. get_slot ( ) . await . unwrap ( ) ;
80+ println ! ( "Current slot: {}" , slot) ;
81+
82+ // Get block production
83+ println ! ( "\n Testing block production:" ) ;
84+ let production = client. get_block_production ( ) . await . unwrap ( ) ;
85+ println ! ( "Block production: {:?}" , production) ;
86+
87+ // Get cluster nodes
88+ println ! ( "\n Testing cluster info:" ) ;
89+ let nodes = client. get_cluster_nodes ( ) . await . unwrap ( ) ;
90+ println ! ( "Found {} cluster nodes" , nodes. len( ) ) ;
91+ for node in nodes. iter ( ) . take ( 3 ) {
92+ let version = node. version . as_ref ( ) . map_or ( "unknown" , |v| v. as_str ( ) ) ;
93+ println ! ( " {}: {}" , node. pubkey, version) ;
6794 }
6895}
0 commit comments