program-test: Fix warp and staking issue (#16002)

Since program-test creates a test genesis and then adds fees and rent,
some of the genesis accounts get rent-collected after warping.  Most
notably, `StakeConfig` gets rent-collected, causing any stake operations
to fail after warp.  This fix creates genesis with the `Rent` and
`FeeRateGovernor` actually used by the bank.
This commit is contained in:
Jon Cinque 2021-03-19 14:37:13 +01:00 committed by GitHub
parent 2cd875f8e0
commit 6cc22e62d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 14 deletions

View File

@ -8,21 +8,29 @@ use {
solana_banks_client::start_client,
solana_banks_server::banks_server::start_local_server,
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, fee_calculator::FeeCalculator,
hash::Hash, instruction::Instruction, instruction::InstructionError, message::Message,
native_token::sol_to_lamports, program_error::ProgramError, program_stubs, pubkey::Pubkey,
account_info::AccountInfo,
entrypoint::ProgramResult,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
instruction::Instruction,
instruction::InstructionError,
message::Message,
native_token::sol_to_lamports,
program_error::ProgramError,
program_stubs,
pubkey::Pubkey,
rent::Rent,
},
solana_runtime::{
bank::{Bank, Builtin, ExecuteTimings},
bank_forks::BankForks,
commitment::BlockCommitmentCache,
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
genesis_utils::{create_genesis_config_with_leader_ex, GenesisConfigInfo},
},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount},
clock::Slot,
genesis_config::GenesisConfig,
genesis_config::{ClusterType, GenesisConfig},
keyed_account::KeyedAccount,
process_instruction::{
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
@ -623,19 +631,27 @@ impl ProgramTest {
}
let rent = Rent::default();
let fee_rate_governor = FeeRateGovernor::default();
let bootstrap_validator_pubkey = Pubkey::new_unique();
let bootstrap_validator_lamports = rent.minimum_balance(VoteState::size_of());
let bootstrap_validator_stake_lamports = rent.minimum_balance(VoteState::size_of());
let mut gci = create_genesis_config_with_leader(
let mint_keypair = Keypair::new();
let voting_keypair = Keypair::new();
let genesis_config = create_genesis_config_with_leader_ex(
sol_to_lamports(1_000_000.0),
&mint_keypair.pubkey(),
&bootstrap_validator_pubkey,
bootstrap_validator_lamports,
&voting_keypair.pubkey(),
&Pubkey::new_unique(),
bootstrap_validator_stake_lamports,
42,
fee_rate_governor,
rent,
ClusterType::Development,
vec![],
);
let genesis_config = &mut gci.genesis_config;
genesis_config.rent = rent;
genesis_config.fee_rate_governor =
solana_program::fee_calculator::FeeRateGovernor::default();
debug!("Payer address: {}", gci.mint_keypair.pubkey());
debug!("Payer address: {}", mint_keypair.pubkey());
debug!("Genesis config: {}", genesis_config);
let mut bank = Bank::new(&genesis_config);
@ -682,7 +698,16 @@ impl ProgramTest {
BlockCommitmentCache::new_for_tests_with_slots(slot, slot),
));
(bank_forks, block_commitment_cache, last_blockhash, gci)
(
bank_forks,
block_commitment_cache,
last_blockhash,
GenesisConfigInfo {
mint_keypair,
voting_keypair,
genesis_config,
},
)
}
pub async fn start(self) -> (BanksClient, Keypair, Hash) {

View File

@ -164,6 +164,8 @@ async fn stake_rewards_from_warp() {
let program_test = ProgramTest::default();
let mut context = program_test.start_with_context().await;
// warp once to make sure stake config doesn't get rent-collected
context.warp_to_slot(100).unwrap();
let mut instructions = vec![];
let validator_keypair = Keypair::new();
instructions.push(system_instruction::create_account(