Fix fragile tests in prep of stake rewrite pr (#13654)
* Fix fragile tests in prep of stake rewrite pr * Restore BOOTSTRAP_VALIDATOR_LAMPORTS where appropriate * Further clean up * Further clean up * Aligh with other call site change * Remove false warn! * fix ci!
This commit is contained in:
parent
2cb006fa44
commit
b74d7b5758
|
@ -5,6 +5,9 @@ use crate::{
|
|||
validator::{Validator, ValidatorConfig},
|
||||
};
|
||||
use solana_ledger::create_new_tmp_ledger;
|
||||
use solana_runtime::genesis_utils::{
|
||||
bootstrap_validator_stake_lamports, BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
};
|
||||
use solana_sdk::{
|
||||
clock::DEFAULT_DEV_SLOTS_PER_EPOCH,
|
||||
hash::Hash,
|
||||
|
@ -31,7 +34,6 @@ pub struct TestValidatorOptions {
|
|||
|
||||
impl Default for TestValidatorOptions {
|
||||
fn default() -> Self {
|
||||
use solana_ledger::genesis_utils::BOOTSTRAP_VALIDATOR_LAMPORTS;
|
||||
TestValidatorOptions {
|
||||
fees: 0,
|
||||
bootstrap_validator_lamports: BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
|
@ -94,7 +96,7 @@ impl TestValidator {
|
|||
&contact_info.id,
|
||||
&Keypair::new(),
|
||||
&solana_sdk::pubkey::new_rand(),
|
||||
42,
|
||||
bootstrap_validator_stake_lamports(),
|
||||
bootstrap_validator_lamports,
|
||||
solana_sdk::genesis_config::ClusterType::Development,
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
pub use solana_runtime::genesis_utils::{
|
||||
create_genesis_config_with_leader, create_genesis_config_with_leader_ex, GenesisConfigInfo,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports, create_genesis_config_with_leader,
|
||||
create_genesis_config_with_leader_ex, GenesisConfigInfo,
|
||||
};
|
||||
|
||||
// same as genesis_config::create_genesis_config, but with bootstrap_validator staking logic
|
||||
|
@ -9,6 +9,6 @@ pub fn create_genesis_config(mint_lamports: u64) -> GenesisConfigInfo {
|
|||
create_genesis_config_with_leader(
|
||||
mint_lamports,
|
||||
&solana_sdk::pubkey::new_rand(),
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -260,13 +260,14 @@ mod tests {
|
|||
use crate::{
|
||||
blockstore::make_slot_entries,
|
||||
genesis_utils::{
|
||||
create_genesis_config, create_genesis_config_with_leader, GenesisConfigInfo,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports, create_genesis_config,
|
||||
create_genesis_config_with_leader, GenesisConfigInfo,
|
||||
},
|
||||
get_tmp_ledger_path,
|
||||
staking_utils::tests::setup_vote_and_stake_accounts,
|
||||
};
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::genesis_utils::BOOTSTRAP_VALIDATOR_LAMPORTS;
|
||||
use solana_sdk::clock::NUM_CONSECUTIVE_LEADER_SLOTS;
|
||||
use solana_sdk::epoch_schedule::{
|
||||
EpochSchedule, DEFAULT_LEADER_SCHEDULE_SLOT_OFFSET, DEFAULT_SLOTS_PER_EPOCH,
|
||||
|
@ -382,7 +383,7 @@ mod tests {
|
|||
let mut genesis_config = create_genesis_config_with_leader(
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
&pubkey,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports(),
|
||||
)
|
||||
.genesis_config;
|
||||
genesis_config.epoch_schedule = EpochSchedule::custom(
|
||||
|
@ -435,7 +436,7 @@ mod tests {
|
|||
let mut genesis_config = create_genesis_config_with_leader(
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
&pubkey,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports(),
|
||||
)
|
||||
.genesis_config;
|
||||
genesis_config.epoch_schedule.warmup = false;
|
||||
|
@ -519,7 +520,7 @@ mod tests {
|
|||
mut genesis_config,
|
||||
mint_keypair,
|
||||
..
|
||||
} = create_genesis_config(10_000);
|
||||
} = create_genesis_config(10_000 * bootstrap_validator_stake_lamports());
|
||||
genesis_config.epoch_schedule.warmup = false;
|
||||
|
||||
let bank = Bank::new(&genesis_config);
|
||||
|
@ -533,7 +534,7 @@ mod tests {
|
|||
&mint_keypair,
|
||||
&vote_account,
|
||||
&validator_identity,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports(),
|
||||
);
|
||||
let node_pubkey = validator_identity.pubkey();
|
||||
|
||||
|
|
|
@ -55,14 +55,15 @@ fn sort_stakes(stakes: &mut Vec<(Pubkey, u64)>) {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use solana_runtime::genesis_utils::{
|
||||
create_genesis_config_with_leader, BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports, create_genesis_config_with_leader,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_leader_schedule_via_bank() {
|
||||
let pubkey = solana_sdk::pubkey::new_rand();
|
||||
let genesis_config =
|
||||
create_genesis_config_with_leader(0, &pubkey, BOOTSTRAP_VALIDATOR_LAMPORTS)
|
||||
create_genesis_config_with_leader(0, &pubkey, bootstrap_validator_stake_lamports())
|
||||
.genesis_config;
|
||||
let bank = Bank::new(&genesis_config);
|
||||
|
||||
|
@ -86,7 +87,7 @@ mod tests {
|
|||
let genesis_config = create_genesis_config_with_leader(
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
&pubkey,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports(),
|
||||
)
|
||||
.genesis_config;
|
||||
let bank = Bank::new(&genesis_config);
|
||||
|
|
|
@ -101,7 +101,7 @@ where
|
|||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::genesis_utils::{
|
||||
create_genesis_config, GenesisConfigInfo, BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
bootstrap_validator_stake_lamports, create_genesis_config, GenesisConfigInfo,
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::from_account,
|
||||
|
@ -178,10 +178,10 @@ pub(crate) mod tests {
|
|||
#[test]
|
||||
fn test_epoch_stakes_and_lockouts() {
|
||||
solana_logger::setup();
|
||||
let stake = BOOTSTRAP_VALIDATOR_LAMPORTS * 100;
|
||||
let stake = bootstrap_validator_stake_lamports();
|
||||
let leader_stake = Stake {
|
||||
delegation: Delegation {
|
||||
stake: BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
stake: bootstrap_validator_stake_lamports(),
|
||||
activation_epoch: std::u64::MAX, // mark as bootstrap
|
||||
..Delegation::default()
|
||||
},
|
||||
|
@ -194,7 +194,7 @@ pub(crate) mod tests {
|
|||
genesis_config,
|
||||
mint_keypair,
|
||||
..
|
||||
} = create_genesis_config(10_000);
|
||||
} = create_genesis_config(10_000 * bootstrap_validator_stake_lamports());
|
||||
|
||||
let bank = Bank::new(&genesis_config);
|
||||
let vote_account = Keypair::new();
|
||||
|
|
|
@ -4357,9 +4357,9 @@ pub(crate) mod tests {
|
|||
use crate::{
|
||||
accounts_index::{AccountMap, Ancestors, ITER_BATCH_SIZE},
|
||||
genesis_utils::{
|
||||
activate_all_features, create_genesis_config_with_leader,
|
||||
create_genesis_config_with_vote_accounts, GenesisConfigInfo, ValidatorVoteKeypairs,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
activate_all_features, bootstrap_validator_stake_lamports,
|
||||
create_genesis_config_with_leader, create_genesis_config_with_vote_accounts,
|
||||
GenesisConfigInfo, ValidatorVoteKeypairs,
|
||||
},
|
||||
native_loader::NativeLoaderError,
|
||||
status_cache::MAX_CACHE_ENTRIES,
|
||||
|
@ -4427,7 +4427,7 @@ pub(crate) mod tests {
|
|||
#[allow(clippy::float_cmp)]
|
||||
fn test_bank_new() {
|
||||
let dummy_leader_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let dummy_leader_lamports = BOOTSTRAP_VALIDATOR_LAMPORTS;
|
||||
let dummy_leader_stake_lamports = bootstrap_validator_stake_lamports();
|
||||
let mint_lamports = 10_000;
|
||||
let GenesisConfigInfo {
|
||||
mut genesis_config,
|
||||
|
@ -4437,7 +4437,7 @@ pub(crate) mod tests {
|
|||
} = create_genesis_config_with_leader(
|
||||
mint_lamports,
|
||||
&dummy_leader_pubkey,
|
||||
dummy_leader_lamports,
|
||||
dummy_leader_stake_lamports,
|
||||
);
|
||||
|
||||
genesis_config.rent = Rent {
|
||||
|
@ -4450,7 +4450,7 @@ pub(crate) mod tests {
|
|||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), mint_lamports);
|
||||
assert_eq!(
|
||||
bank.get_balance(&voting_keypair.pubkey()),
|
||||
dummy_leader_lamports /* 1 token goes to the vote account associated with dummy_leader_lamports */
|
||||
dummy_leader_stake_lamports /* 1 token goes to the vote account associated with dummy_leader_lamports */
|
||||
);
|
||||
|
||||
let rent_account = bank.get_account(&sysvar::rent::id()).unwrap();
|
||||
|
|
|
@ -10,12 +10,18 @@ use solana_sdk::{
|
|||
system_program,
|
||||
};
|
||||
use solana_stake_program::stake_state;
|
||||
use solana_stake_program::stake_state::StakeState;
|
||||
use solana_vote_program::vote_state;
|
||||
use std::borrow::Borrow;
|
||||
|
||||
// The default stake placed with the bootstrap validator
|
||||
pub const BOOTSTRAP_VALIDATOR_LAMPORTS: u64 = 42;
|
||||
|
||||
// fun fact: rustc is very close to make this const fn.
|
||||
pub fn bootstrap_validator_stake_lamports() -> u64 {
|
||||
StakeState::get_rent_exempt_reserve(&Rent::default())
|
||||
}
|
||||
|
||||
pub struct ValidatorVoteKeypairs {
|
||||
pub node_keypair: Keypair,
|
||||
pub vote_keypair: Keypair,
|
||||
|
|
Loading…
Reference in New Issue