request_airdrop.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #![allow(clippy::arithmetic_side_effects)]
  2. use {
  3. solana_cli::cli::{process_command, CliCommand, CliConfig},
  4. solana_commitment_config::CommitmentConfig,
  5. solana_faucet::faucet::run_local_faucet_with_unique_port_for_tests,
  6. solana_keypair::Keypair,
  7. solana_native_token::LAMPORTS_PER_SOL,
  8. solana_net_utils::SocketAddrSpace,
  9. solana_rpc_client::rpc_client::RpcClient,
  10. solana_signer::Signer,
  11. solana_test_validator::TestValidator,
  12. };
  13. #[test]
  14. fn test_cli_request_airdrop() {
  15. let mint_keypair = Keypair::new();
  16. let mint_pubkey = mint_keypair.pubkey();
  17. let faucet_addr = run_local_faucet_with_unique_port_for_tests(mint_keypair);
  18. let test_validator =
  19. TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified);
  20. let mut bob_config = CliConfig::recent_for_tests();
  21. bob_config.json_rpc_url = test_validator.rpc_url();
  22. bob_config.command = CliCommand::Airdrop {
  23. pubkey: None,
  24. lamports: 50 * LAMPORTS_PER_SOL,
  25. };
  26. let keypair = Keypair::new();
  27. bob_config.signers = vec![&keypair];
  28. let sig_response = process_command(&bob_config);
  29. sig_response.unwrap();
  30. let rpc_client =
  31. RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
  32. let balance = rpc_client
  33. .get_balance(&bob_config.signers[0].pubkey())
  34. .unwrap();
  35. assert_eq!(balance, 50 * LAMPORTS_PER_SOL);
  36. }