2019-01-17 14:18:27 -08:00
|
|
|
use solana_drone::drone::{request_airdrop_transaction, run_local_drone};
|
|
|
|
use solana_sdk::hash::Hash;
|
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
|
|
|
use solana_sdk::system_instruction::SystemInstruction;
|
|
|
|
use solana_sdk::system_program;
|
|
|
|
use solana_sdk::transaction::Transaction;
|
|
|
|
use std::sync::mpsc::channel;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_local_drone() {
|
|
|
|
let keypair = Keypair::new();
|
|
|
|
let to = Keypair::new().pubkey();
|
|
|
|
let tokens = 50;
|
2019-03-02 10:25:16 -08:00
|
|
|
let blockhash = Hash::new(&to.as_ref());
|
2019-01-17 14:18:27 -08:00
|
|
|
let expected_instruction = SystemInstruction::CreateAccount {
|
|
|
|
tokens,
|
|
|
|
space: 0,
|
|
|
|
program_id: system_program::id(),
|
|
|
|
};
|
|
|
|
let mut expected_tx = Transaction::new(
|
|
|
|
&keypair,
|
|
|
|
&[to],
|
|
|
|
system_program::id(),
|
|
|
|
&expected_instruction,
|
2019-03-02 10:25:16 -08:00
|
|
|
blockhash,
|
2019-01-17 14:18:27 -08:00
|
|
|
0,
|
|
|
|
);
|
2019-03-02 10:25:16 -08:00
|
|
|
expected_tx.sign(&[&keypair], blockhash);
|
2019-01-17 14:18:27 -08:00
|
|
|
|
|
|
|
let (sender, receiver) = channel();
|
|
|
|
run_local_drone(keypair, sender);
|
|
|
|
let drone_addr = receiver.recv().unwrap();
|
|
|
|
|
2019-03-02 10:25:16 -08:00
|
|
|
let result = request_airdrop_transaction(&drone_addr, &to, tokens, blockhash);
|
2019-01-17 14:18:27 -08:00
|
|
|
assert_eq!(expected_tx, result.unwrap());
|
|
|
|
}
|