Skip to content

Commit

Permalink
runtime: bank: add tests for adding test builtins on feature activation
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Feb 20, 2024
1 parent 8eafb3f commit 6f57f5b
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion runtime/src/bank/builtin_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ mod tests {
use {
crate::bank::*,
solana_sdk::{
ed25519_program, feature_set::FeatureSet, genesis_config::create_genesis_config,
ed25519_program,
feature::{self, Feature},
feature_set::FeatureSet,
genesis_config::create_genesis_config,
},
};

Expand Down Expand Up @@ -62,4 +65,73 @@ mod tests {
// Simulate starting up from snapshot finishing the initialization for a frozen bank
bank.finish_init(&genesis_config, None, false);
}

#[test]
fn test_add_new_builtins_on_feature_activation() {
let check_bank_builtin_feature_activation = |builtins: &[BuiltinPrototype]| {
let feature_ids = builtins
.iter()
.filter_map(|builtin| builtin.feature_id)
.collect::<HashSet<_>>();

let mut bank = Bank::new_for_tests_with_config(
&GenesisConfig::default(),
BankTestConfig::default(),
);

let mut feature_set = FeatureSet::default();
feature_ids.iter().for_each(|feature_id| {
feature_set.inactive.insert(*feature_id);
bank.store_account(
feature_id,
&feature::create_account(&Feature::default(), 42),
);
});
bank.feature_set = Arc::new(feature_set.clone());

// Assert the builtins have not been enabled yet.
builtins.iter().for_each(|builtin| {
assert!(bank.builtin_programs.get(&builtin.program_id).is_none());
});

bank.apply_feature_activations(
ApplyFeatureActivationsCaller::NewFromParent,
false,
Some(builtins),
);

// Assert the builtins have been enabled.
builtins.iter().for_each(|builtin| {
assert!(bank.builtin_programs.get(&builtin.program_id).is_some());
});
};

check_bank_builtin_feature_activation(&[]);
check_bank_builtin_feature_activation(&[BuiltinPrototype {
feature_id: Some(Pubkey::new_unique()),
program_id: Pubkey::new_unique(),
name: "random_program1",
entrypoint: solana_system_program::system_processor::Entrypoint::vm,
}]);
check_bank_builtin_feature_activation(&[
BuiltinPrototype {
feature_id: Some(Pubkey::new_unique()),
program_id: Pubkey::new_unique(),
name: "random_program1",
entrypoint: solana_system_program::system_processor::Entrypoint::vm,
},
BuiltinPrototype {
feature_id: Some(Pubkey::new_unique()),
program_id: Pubkey::new_unique(),
name: "random_program2",
entrypoint: solana_system_program::system_processor::Entrypoint::vm,
},
BuiltinPrototype {
feature_id: Some(Pubkey::new_unique()),
program_id: Pubkey::new_unique(),
name: "random_program3",
entrypoint: solana_system_program::system_processor::Entrypoint::vm,
},
]);
}
}

0 comments on commit 6f57f5b

Please sign in to comment.