cluster_query.rs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use {
  2. solana_cli::{
  3. check_balance,
  4. cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
  5. test_utils::check_ready,
  6. },
  7. solana_commitment_config::CommitmentConfig,
  8. solana_faucet::faucet::run_local_faucet,
  9. solana_fee_structure::FeeStructure,
  10. solana_keypair::Keypair,
  11. solana_native_token::LAMPORTS_PER_SOL,
  12. solana_rpc_client::rpc_client::RpcClient,
  13. solana_signer::Signer,
  14. solana_streamer::socket::SocketAddrSpace,
  15. solana_test_validator::TestValidator,
  16. std::time::Duration,
  17. test_case::test_case,
  18. };
  19. #[test_case(None; "base")]
  20. #[test_case(Some(1_000_000); "with_compute_unit_price")]
  21. fn test_ping(compute_unit_price: Option<u64>) {
  22. solana_logger::setup();
  23. let fee = FeeStructure::default().get_max_fee(1, 0);
  24. let mint_keypair = Keypair::new();
  25. let mint_pubkey = mint_keypair.pubkey();
  26. let faucet_addr = run_local_faucet(mint_keypair, None);
  27. let test_validator = TestValidator::with_custom_fees(
  28. mint_pubkey,
  29. fee,
  30. Some(faucet_addr),
  31. SocketAddrSpace::Unspecified,
  32. );
  33. let rpc_client =
  34. RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed());
  35. let default_signer = Keypair::new();
  36. let signer_pubkey = default_signer.pubkey();
  37. let mut config = CliConfig::recent_for_tests();
  38. config.json_rpc_url = test_validator.rpc_url();
  39. config.signers = vec![&default_signer];
  40. request_and_confirm_airdrop(&rpc_client, &config, &signer_pubkey, LAMPORTS_PER_SOL).unwrap();
  41. check_balance!(LAMPORTS_PER_SOL, &rpc_client, &signer_pubkey);
  42. check_ready(&rpc_client);
  43. let count = 5;
  44. config.command = CliCommand::Ping {
  45. interval: Duration::from_secs(0),
  46. count: Some(count),
  47. timeout: Duration::from_secs(15),
  48. blockhash: None,
  49. print_timestamp: false,
  50. compute_unit_price,
  51. };
  52. process_command(&config).unwrap();
  53. }