Skip to content

Commit

Permalink
Use BankForks on tests - Part 1 (#34206)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Lucas Steuernagel <[email protected]>
  • Loading branch information
LucasSte authored Nov 27, 2023
1 parent da9fad8 commit e832765
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 69 deletions.
28 changes: 28 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,17 @@ pub(super) enum RewardInterval {
}

impl Bank {
fn wrap_with_bank_forks_for_tests(self) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
let bank_fork = BankForks::new_rw_arc(self);
let bank_arc = bank_fork.read().unwrap().root_bank();
bank_arc
.loaded_programs_cache
.write()
.unwrap()
.set_fork_graph(bank_fork.clone());
(bank_arc, bank_fork)
}

pub fn default_for_tests() -> Self {
Self::default_with_accounts(Accounts::default_for_tests())
}
Expand All @@ -978,6 +989,23 @@ impl Bank {
Self::new_for_tests_with_config(genesis_config, BankTestConfig::default())
}

pub fn new_with_bank_forks_for_tests(
genesis_config: &GenesisConfig,
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
let bank = Self::new_for_tests(genesis_config);
bank.wrap_with_bank_forks_for_tests()
}

pub fn new_with_mockup_builtin_for_tests(
genesis_config: &GenesisConfig,
program_id: Pubkey,
builtin_function: BuiltinFunctionWithContext,
) -> (Arc<Self>, Arc<RwLock<BankForks>>) {
let mut bank = Self::new_for_tests(genesis_config);
bank.add_mockup_builtin(program_id, builtin_function);
bank.wrap_with_bank_forks_for_tests()
}

pub fn new_for_tests_with_config(
genesis_config: &GenesisConfig,
test_config: BankTestConfig,
Expand Down
Loading

0 comments on commit e832765

Please sign in to comment.