1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use solana_client::rpc_client::RpcClient; use solana_sdk::{clock::DEFAULT_MS_PER_SLOT, commitment_config::CommitmentConfig, pubkey::Pubkey}; use std::{thread::sleep, time::Duration}; pub fn check_recent_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) { (0..5).for_each(|tries| { let balance = client .get_balance_with_commitment(pubkey, CommitmentConfig::processed()) .unwrap() .value; if balance == expected_balance { return; } if tries == 4 { assert_eq!(balance, expected_balance); } sleep(Duration::from_millis(500)); }); } pub fn check_ready(rpc_client: &RpcClient) { while rpc_client .get_slot_with_commitment(CommitmentConfig::processed()) .unwrap() < 5 { sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT)); } }