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:
parent
2cd875f8e0
commit
6cc22e62d4
|
@ -8,21 +8,29 @@ use {
|
||||||
solana_banks_client::start_client,
|
solana_banks_client::start_client,
|
||||||
solana_banks_server::banks_server::start_local_server,
|
solana_banks_server::banks_server::start_local_server,
|
||||||
solana_program::{
|
solana_program::{
|
||||||
account_info::AccountInfo, entrypoint::ProgramResult, fee_calculator::FeeCalculator,
|
account_info::AccountInfo,
|
||||||
hash::Hash, instruction::Instruction, instruction::InstructionError, message::Message,
|
entrypoint::ProgramResult,
|
||||||
native_token::sol_to_lamports, program_error::ProgramError, program_stubs, pubkey::Pubkey,
|
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,
|
rent::Rent,
|
||||||
},
|
},
|
||||||
solana_runtime::{
|
solana_runtime::{
|
||||||
bank::{Bank, Builtin, ExecuteTimings},
|
bank::{Bank, Builtin, ExecuteTimings},
|
||||||
bank_forks::BankForks,
|
bank_forks::BankForks,
|
||||||
commitment::BlockCommitmentCache,
|
commitment::BlockCommitmentCache,
|
||||||
genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo},
|
genesis_utils::{create_genesis_config_with_leader_ex, GenesisConfigInfo},
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{Account, AccountSharedData, ReadableAccount},
|
account::{Account, AccountSharedData, ReadableAccount},
|
||||||
clock::Slot,
|
clock::Slot,
|
||||||
genesis_config::GenesisConfig,
|
genesis_config::{ClusterType, GenesisConfig},
|
||||||
keyed_account::KeyedAccount,
|
keyed_account::KeyedAccount,
|
||||||
process_instruction::{
|
process_instruction::{
|
||||||
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
|
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
|
||||||
|
@ -623,19 +631,27 @@ impl ProgramTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
let rent = Rent::default();
|
let rent = Rent::default();
|
||||||
|
let fee_rate_governor = FeeRateGovernor::default();
|
||||||
let bootstrap_validator_pubkey = Pubkey::new_unique();
|
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),
|
sol_to_lamports(1_000_000.0),
|
||||||
|
&mint_keypair.pubkey(),
|
||||||
&bootstrap_validator_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;
|
debug!("Payer address: {}", mint_keypair.pubkey());
|
||||||
genesis_config.rent = rent;
|
|
||||||
genesis_config.fee_rate_governor =
|
|
||||||
solana_program::fee_calculator::FeeRateGovernor::default();
|
|
||||||
debug!("Payer address: {}", gci.mint_keypair.pubkey());
|
|
||||||
debug!("Genesis config: {}", genesis_config);
|
debug!("Genesis config: {}", genesis_config);
|
||||||
|
|
||||||
let mut bank = Bank::new(&genesis_config);
|
let mut bank = Bank::new(&genesis_config);
|
||||||
|
@ -682,7 +698,16 @@ impl ProgramTest {
|
||||||
BlockCommitmentCache::new_for_tests_with_slots(slot, slot),
|
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) {
|
pub async fn start(self) -> (BanksClient, Keypair, Hash) {
|
||||||
|
|
|
@ -164,6 +164,8 @@ async fn stake_rewards_from_warp() {
|
||||||
let program_test = ProgramTest::default();
|
let program_test = ProgramTest::default();
|
||||||
|
|
||||||
let mut context = program_test.start_with_context().await;
|
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 mut instructions = vec![];
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
instructions.push(system_instruction::create_account(
|
instructions.push(system_instruction::create_account(
|
||||||
|
|
Loading…
Reference in New Issue