Add ability to clone accounts from an RPC endpoint (#14784)

(cherry picked from commit cbb9ac19b9)

Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2021-01-22 22:47:29 +00:00
committed by GitHub
parent 2d246581ed
commit e127631f8d
3 changed files with 82 additions and 9 deletions

View File

@@ -84,6 +84,30 @@ impl TestValidatorGenesis {
self
}
pub fn add_accounts<T>(&mut self, accounts: T) -> &mut Self
where
T: IntoIterator<Item = (Pubkey, Account)>,
{
for (address, account) in accounts {
self.add_account(address, account);
}
self
}
pub fn clone_accounts<T>(&mut self, addresses: T, rpc_client: &RpcClient) -> &mut Self
where
T: IntoIterator<Item = Pubkey>,
{
for address in addresses {
info!("Fetching {}...", address);
let account = rpc_client.get_account(&address).unwrap_or_else(|err| {
panic!("Failed to fetch {}: {}", address, err);
});
self.add_account(address, account);
}
self
}
/// Add an account to the test environment with the account data in the provided `filename`
pub fn add_account_with_file_data(
&mut self,