program-test: Remove special case for Rent sysvar (bp #13434) (#13435)

* Revert "Include Rent in ProgramTest::start() output"

This reverts commit c3d2d2134c.

(cherry picked from commit 920cd5285a)

* Add get_rent()

(cherry picked from commit 9a1c1fbab8)

Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2020-11-06 05:24:44 +00:00
committed by GitHub
parent 70985f82f1
commit 70f74174e8
2 changed files with 28 additions and 20 deletions

View File

@ -10,9 +10,17 @@ use futures::future::join_all;
pub use solana_banks_interface::{BanksClient, TransactionStatus};
use solana_banks_interface::{BanksRequest, BanksResponse};
use solana_sdk::{
account::Account, clock::Slot, commitment_config::CommitmentLevel,
fee_calculator::FeeCalculator, hash::Hash, pubkey::Pubkey, signature::Signature,
transaction::Transaction, transport,
account::{from_account, Account},
clock::Slot,
commitment_config::CommitmentLevel,
fee_calculator::FeeCalculator,
hash::Hash,
pubkey::Pubkey,
rent::Rent,
signature::Signature,
sysvar,
transaction::Transaction,
transport,
};
use std::io::{self, Error, ErrorKind};
use tarpc::{
@ -40,6 +48,9 @@ pub trait BanksClientExt {
/// use them to calculate the transaction fee.
async fn get_fees(&mut self) -> io::Result<(FeeCalculator, Hash, Slot)>;
/// Return the cluster rent
async fn get_rent(&mut self) -> io::Result<Rent>;
/// Send a transaction and return after the transaction has been rejected or
/// reached the given level of commitment.
async fn process_transaction_with_commitment(
@ -108,6 +119,17 @@ impl BanksClientExt for BanksClient {
.await
}
async fn get_rent(&mut self) -> io::Result<Rent> {
let rent_sysvar = self
.get_account(sysvar::rent::id())
.await?
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Rent sysvar not present"))?;
from_account::<Rent>(&rent_sysvar).ok_or_else(|| {
io::Error::new(io::ErrorKind::Other, "Failed to deserialize Rent sysvar")
})
}
async fn get_recent_blockhash(&mut self) -> io::Result<Hash> {
Ok(self.get_fees().await?.1)
}

View File

@ -395,14 +395,6 @@ impl Default for ProgramTest {
}
}
// Values returned by `ProgramTest::start`
pub struct StartOutputs {
pub banks_client: BanksClient,
pub payer: Keypair,
pub recent_blockhash: Hash,
pub rent: Rent,
}
impl ProgramTest {
pub fn new(
program_name: &str,
@ -552,7 +544,7 @@ impl ProgramTest {
///
/// Returns a `BanksClient` interface into the test environment as well as a payer `Keypair`
/// with SOL for sending transactions
pub async fn start(self) -> StartOutputs {
pub async fn start(self) -> (BanksClient, Keypair, Hash) {
{
use std::sync::Once;
static ONCE: Once = Once::new();
@ -571,8 +563,7 @@ impl ProgramTest {
bootstrap_validator_stake_lamports,
);
let mut genesis_config = gci.genesis_config;
let rent = Rent::default();
genesis_config.rent = rent;
genesis_config.rent = Rent::default();
genesis_config.fee_rate_governor =
solana_program::fee_calculator::FeeRateGovernor::default();
let payer = gci.mint_keypair;
@ -624,11 +615,6 @@ impl ProgramTest {
.unwrap_or_else(|err| panic!("Failed to start banks client: {}", err));
let recent_blockhash = banks_client.get_recent_blockhash().await.unwrap();
StartOutputs {
banks_client,
payer,
recent_blockhash,
rent,
}
(banks_client, payer, recent_blockhash)
}
}