Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
program-test: Fix warp and staking issue (#16002) (#16031)
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 6cc22e6)

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
  • Loading branch information
mergify[bot] and joncinque authored Mar 19, 2021
1 parent 8b67ba6 commit 4e3f2c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
53 changes: 39 additions & 14 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -618,19 +626,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);
Expand Down Expand Up @@ -677,7 +693,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) {
Expand Down
2 changes: 2 additions & 0 deletions program-test/tests/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4e3f2c3

Please sign in to comment.