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-02-25 20:23:54 -08:00
|
|
|
use solana_core::validator::TestValidator;
|
2019-12-16 13:05:17 -08:00
|
|
|
use solana_faucet::faucet::run_local_faucet;
|
2020-02-24 16:03:30 -08:00
|
|
|
use solana_sdk::signature::Keypair;
|
|
|
|
use std::{fs::remove_dir_all, sync::mpsc::channel};
|
2019-01-13 23:10:03 -08:00
|
|
|
|
|
|
|
#[test]
|
2019-10-04 15:13:21 -07:00
|
|
|
fn test_cli_request_airdrop() {
|
2020-02-25 20:23:54 -08:00
|
|
|
let TestValidator {
|
|
|
|
server,
|
|
|
|
leader_data,
|
|
|
|
alice,
|
|
|
|
ledger_path,
|
|
|
|
..
|
|
|
|
} = TestValidator::run();
|
2019-01-13 23:10:03 -08:00
|
|
|
let (sender, receiver) = channel();
|
2019-12-16 13:05:17 -08:00
|
|
|
run_local_faucet(alice, sender, None);
|
|
|
|
let faucet_addr = receiver.recv().unwrap();
|
2019-01-13 23:10:03 -08:00
|
|
|
|
2019-10-04 15:13:21 -07:00
|
|
|
let mut bob_config = CliConfig::default();
|
2019-05-06 07:38:26 -07:00
|
|
|
bob_config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
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
|
|
|
|
2019-03-15 22:42:36 -07:00
|
|
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
2019-01-13 23:10:03 -08:00
|
|
|
|
|
|
|
let balance = rpc_client
|
2020-05-14 11:24:14 -07:00
|
|
|
.get_balance(&bob_config.signers[0].pubkey())
|
2019-01-13 23:10:03 -08:00
|
|
|
.unwrap();
|
|
|
|
assert_eq!(balance, 50);
|
|
|
|
|
2019-03-03 16:44:06 -08:00
|
|
|
server.close().unwrap();
|
2019-01-13 23:10:03 -08:00
|
|
|
remove_dir_all(ledger_path).unwrap();
|
|
|
|
}
|