Add method to inspect account data in tests

Change-Id: I23ee5b351bcd1cb6fb998384ff87f7bfaf61b885
This commit is contained in:
Reisen 2021-07-05 10:44:14 +00:00
parent 6aa5788354
commit fd7b53a2a5
1 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,9 @@
#![allow(warnings)]
use borsh::BorshSerialize;
use borsh::{
BorshDeserialize,
BorshSerialize,
};
use byteorder::{
BigEndian,
WriteBytesExt,
@ -63,6 +66,8 @@ use bridge::{
GuardianSet,
GuardianSetDerivationData,
MessageDerivationData,
Sequence,
SequenceDerivationData,
SignatureSet,
SignatureSetDerivationData,
},
@ -127,6 +132,17 @@ mod helpers {
(payer, rpc, program)
}
/// Fetch account data, the loop is there to re-attempt until data is available.
pub fn get_account_data<T: BorshDeserialize>(client: &RpcClient, account: &Pubkey) -> Option<T> {
for _ in 0..5 {
if let Ok(account) = client.get_account(account) {
return Some(T::try_from_slice(&account.data).unwrap());
}
std::thread::sleep(std::time::Duration::from_millis(2000));
}
None
}
/// Generate `count` secp256k1 private keys, along with their ethereum-styled public key
/// encoding: 0x0123456789ABCDEF01234
pub fn generate_keys(count: u8) -> (Vec<[u8; 20]>, Vec<SecretKey>) {