2019-10-04 16:13:21 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_cli::cli::{process_command, CliCommand, CliConfig};
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-16 22:37:20 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_client::rpc_client::RpcClient;
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-18 22:21:44 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_core::test_validator::TestValidator;
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-16 14:05:17 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_faucet::faucet::run_local_faucet;
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-08 23:18:27 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana_sdk::{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    commitment_config::CommitmentConfig,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    signature::{Keypair, Signer},
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use std::sync::mpsc::channel;
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[test]
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 16:13:21 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								fn test_cli_request_airdrop() {
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-08 23:18:27 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mint_keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let (sender, receiver) = channel();
							 | 
						
					
						
							
								
									
										
										
										
											2020-12-08 23:18:27 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    run_local_faucet(mint_keypair, sender, None);
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-16 14:05:17 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let faucet_addr = receiver.recv().unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut bob_config = CliConfig::recent_for_tests();
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bob_config.json_rpc_url = test_validator.rpc_url();
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-04 16:13:21 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bob_config.command = CliCommand::Airdrop {
							 | 
						
					
						
							
								
									
										
										
										
											2019-12-16 14:05:17 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        faucet_host: None,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        faucet_port: faucet_addr.port(),
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-16 11:41:00 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        pubkey: None,
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-29 20:45:53 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lamports: 50,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    };
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-24 17:03:30 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let keypair = Keypair::new();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bob_config.signers = vec![&keypair];
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let sig_response = process_command(&bob_config);
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-28 14:52:35 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sig_response.unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-25 17:00:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let rpc_client = RpcClient::new(test_validator.rpc_url());
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let balance = rpc_client
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-17 12:18:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .get_balance_with_commitment(&bob_config.signers[0].pubkey(), CommitmentConfig::recent())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .unwrap()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .value;
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-14 00:10:03 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    assert_eq!(balance, 50);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |