solana/cli/tests/request_airdrop.rs

44 lines
1.3 KiB
Rust
Raw Normal View History

use solana_cli::cli::{process_command, CliCommand, CliConfig};
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;
use solana_sdk::{
commitment_config::CommitmentConfig,
signature::{Keypair, Signer},
};
2020-11-25 17:00:47 -08:00
use std::sync::mpsc::channel;
#[test]
fn test_cli_request_airdrop() {
let mint_keypair = Keypair::new();
let test_validator = TestValidator::with_no_fees(mint_keypair.pubkey());
2020-11-25 17:00:47 -08:00
let (sender, receiver) = channel();
run_local_faucet(mint_keypair, sender, None);
2019-12-16 13:05:17 -08:00
let faucet_addr = receiver.recv().unwrap();
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();
bob_config.command = CliCommand::Airdrop {
2019-12-16 13:05:17 -08:00
faucet_host: None,
faucet_port: faucet_addr.port(),
pubkey: None,
lamports: 50,
};
let keypair = Keypair::new();
bob_config.signers = vec![&keypair];
let sig_response = process_command(&bob_config);
sig_response.unwrap();
2020-11-25 17:00:47 -08:00
let rpc_client = RpcClient::new(test_validator.rpc_url());
let balance = rpc_client
.get_balance_with_commitment(&bob_config.signers[0].pubkey(), CommitmentConfig::recent())
.unwrap()
.value;
assert_eq!(balance, 50);
2020-11-25 17:00:47 -08:00
test_validator.close();
}