2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
solana_faucet::faucet::{request_airdrop_transaction, run_local_faucet},
|
|
|
|
solana_sdk::{
|
|
|
|
hash::Hash,
|
|
|
|
message::Message,
|
|
|
|
signature::{Keypair, Signer},
|
|
|
|
system_instruction,
|
|
|
|
transaction::Transaction,
|
|
|
|
},
|
2019-12-16 13:05:17 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_local_faucet() {
|
|
|
|
let keypair = Keypair::new();
|
2020-10-19 12:12:08 -07:00
|
|
|
let to = solana_sdk::pubkey::new_rand();
|
2019-12-16 13:05:17 -08:00
|
|
|
let lamports = 50;
|
2021-06-18 06:34:46 -07:00
|
|
|
let blockhash = Hash::new(to.as_ref());
|
2019-12-16 13:05:17 -08:00
|
|
|
let create_instruction = system_instruction::transfer(&keypair.pubkey(), &to, lamports);
|
2020-06-24 13:52:38 -07:00
|
|
|
let message = Message::new(&[create_instruction], Some(&keypair.pubkey()));
|
2019-12-16 13:05:17 -08:00
|
|
|
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
|
|
|
|
2021-01-28 12:11:53 -08:00
|
|
|
let faucet_addr = run_local_faucet(keypair, None);
|
2019-12-16 13:05:17 -08:00
|
|
|
|
|
|
|
let result = request_airdrop_transaction(&faucet_addr, &to, lamports, blockhash);
|
|
|
|
assert_eq!(expected_tx, result.unwrap());
|
|
|
|
}
|