2020-04-09 18:05:56 -07:00
|
|
|
use solana_client::rpc_client::RpcClient;
|
2020-06-17 12:18:48 -06:00
|
|
|
use solana_sdk::{clock::DEFAULT_MS_PER_SLOT, commitment_config::CommitmentConfig, pubkey::Pubkey};
|
2020-04-09 18:05:56 -07:00
|
|
|
use std::{thread::sleep, time::Duration};
|
|
|
|
|
2020-06-17 12:18:48 -06:00
|
|
|
pub fn check_recent_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) {
|
2020-04-09 18:05:56 -07:00
|
|
|
(0..5).for_each(|tries| {
|
2020-06-17 12:18:48 -06:00
|
|
|
let balance = client
|
|
|
|
.get_balance_with_commitment(pubkey, CommitmentConfig::recent())
|
|
|
|
.unwrap()
|
|
|
|
.value;
|
2020-04-09 18:05:56 -07:00
|
|
|
if balance == expected_balance {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if tries == 4 {
|
|
|
|
assert_eq!(balance, expected_balance);
|
|
|
|
}
|
|
|
|
sleep(Duration::from_millis(500));
|
|
|
|
});
|
|
|
|
}
|
2020-06-17 12:18:48 -06:00
|
|
|
|
|
|
|
pub fn check_ready(rpc_client: &RpcClient) {
|
|
|
|
while rpc_client
|
|
|
|
.get_slot_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap()
|
|
|
|
< 5
|
|
|
|
{
|
|
|
|
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
|
|
|
|
}
|
|
|
|
}
|