/ tests / src / lib.rs
lib.rs
 1  use solana_client::rpc_client::RpcClient;
 2  use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};
 3  use solana_system_interface::{instruction as system_instruction, program as system_program};
 4  
 5  #[cfg(test)]
 6  mod test_initialize;
 7  
 8  #[cfg(test)]
 9  mod test_suggest_persona;
10  
11  #[cfg(test)]
12  mod test_flag_node;
13  
14  pub(crate) fn create_account(payer: &Keypair, rpc: &RpcClient, lamports: u64) -> Keypair {
15      let user = Keypair::new();
16  
17      let rent = rpc.get_minimum_balance_for_rent_exemption(0).unwrap();
18      let instr = system_instruction::create_account(
19          &payer.pubkey(),
20          &user.pubkey(),
21          rent + lamports,
22          0,
23          &system_program::ID,
24      );
25  
26      let blockhash = rpc.get_latest_blockhash().unwrap();
27      let tx = Transaction::new_signed_with_payer(
28          &[instr],
29          Some(&payer.pubkey()),
30          &[payer, &user],
31          blockhash,
32      );
33  
34      let _sig = rpc.send_and_confirm_transaction(&tx).unwrap();
35  
36      user
37  }