2019-10-04 15:13:21 -07: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 13:05:17 -08: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},
|
|
|
|
};
|
2019-01-13 23:10:03 -08:00
|
|
|
|
|
|
|
#[test]
|
2019-10-04 15:13:21 -07: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
|
|
|
|
2021-01-28 12:11:53 -08:00
|
|
|
let faucet_addr = run_local_faucet(mint_keypair, None);
|
2019-01-13 23:10:03 -08:00
|
|
|
|
2020-06-17 11:18:48 -07: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 15:13:21 -07:00
|
|
|
bob_config.command = CliCommand::Airdrop {
|
2019-12-16 13:05:17 -08:00
|
|
|
faucet_host: None,
|
|
|
|
faucet_port: faucet_addr.port(),
|
2020-02-16 10:41:00 -08:00
|
|
|
pubkey: None,
|
2019-08-29 20:45:53 -07:00
|
|
|
lamports: 50,
|
|
|
|
};
|
2020-02-24 16:03:30 -08:00
|
|
|
let keypair = Keypair::new();
|
|
|
|
bob_config.signers = vec![&keypair];
|
2019-01-13 23:10:03 -08:00
|
|
|
|
|
|
|
let sig_response = process_command(&bob_config);
|
2019-01-28 14:52:35 -08:00
|
|
|
sig_response.unwrap();
|
2019-01-13 23:10:03 -08:00
|
|
|
|
2021-01-19 14:33:03 -08:00
|
|
|
let rpc_client =
|
2021-01-26 11:23:07 -08:00
|
|
|
RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
|
2019-01-13 23:10:03 -08:00
|
|
|
|
|
|
|
let balance = rpc_client
|
2021-01-19 14:33:03 -08:00
|
|
|
.get_balance(&bob_config.signers[0].pubkey())
|
|
|
|
.unwrap();
|
2019-01-13 23:10:03 -08:00
|
|
|
assert_eq!(balance, 50);
|
|
|
|
}
|