FeatureSet test
This commit is contained in:
parent
cc6ba1e131
commit
92406cf9a0
@ -8993,4 +8993,59 @@ mod tests {
|
|||||||
assert!(executors.borrow().executors.contains_key(&key3));
|
assert!(executors.borrow().executors.contains_key(&key3));
|
||||||
assert!(executors.borrow().executors.contains_key(&key4));
|
assert!(executors.borrow().executors.contains_key(&key4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_compute_active_feature_set() {
|
||||||
|
let (genesis_config, _mint_keypair) = create_genesis_config(100_000);
|
||||||
|
let bank0 = Arc::new(Bank::new(&genesis_config));
|
||||||
|
let mut bank = Bank::new_from_parent(&bank0, &Pubkey::default(), 1);
|
||||||
|
|
||||||
|
let test_feature = "TestFeature11111111111111111111111111111111"
|
||||||
|
.parse::<Pubkey>()
|
||||||
|
.unwrap();
|
||||||
|
let mut feature_set = FeatureSet::default();
|
||||||
|
feature_set.inactive.insert(test_feature);
|
||||||
|
bank.feature_set = Arc::new(feature_set.clone());
|
||||||
|
|
||||||
|
let new_activations = bank.compute_active_feature_set(true);
|
||||||
|
assert!(new_activations.is_empty());
|
||||||
|
assert!(!bank.feature_set.active(&test_feature));
|
||||||
|
|
||||||
|
// Depositing into the `test_feature` account should do nothing
|
||||||
|
bank.deposit(&test_feature, 42);
|
||||||
|
let new_activations = bank.compute_active_feature_set(true);
|
||||||
|
assert!(new_activations.is_empty());
|
||||||
|
assert!(!bank.feature_set.active(&test_feature));
|
||||||
|
|
||||||
|
// Request `test_feature` activation
|
||||||
|
let feature = Feature::default();
|
||||||
|
assert_eq!(feature.activated_at, None);
|
||||||
|
bank.store_account(&test_feature, &feature.create_account(42));
|
||||||
|
|
||||||
|
// Run `compute_active_feature_set` disallowing new activations
|
||||||
|
let new_activations = bank.compute_active_feature_set(false);
|
||||||
|
assert!(new_activations.is_empty());
|
||||||
|
assert!(!bank.feature_set.active(&test_feature));
|
||||||
|
let feature = Feature::from_account(&bank.get_account(&test_feature).expect("get_account"))
|
||||||
|
.expect("from_account");
|
||||||
|
assert_eq!(feature.activated_at, None);
|
||||||
|
|
||||||
|
// Run `compute_active_feature_set` allowing new activations
|
||||||
|
let new_activations = bank.compute_active_feature_set(true);
|
||||||
|
assert_eq!(new_activations.len(), 1);
|
||||||
|
assert!(bank.feature_set.active(&test_feature));
|
||||||
|
let feature = Feature::from_account(&bank.get_account(&test_feature).expect("get_account"))
|
||||||
|
.expect("from_account");
|
||||||
|
assert_eq!(feature.activated_at, Some(1));
|
||||||
|
|
||||||
|
// Reset the bank's feature set
|
||||||
|
bank.feature_set = Arc::new(feature_set);
|
||||||
|
assert!(!bank.feature_set.active(&test_feature));
|
||||||
|
|
||||||
|
// Running `compute_active_feature_set` will not cause new activations, but
|
||||||
|
// `test_feature` is now be active
|
||||||
|
let new_activations = bank.compute_active_feature_set(true);
|
||||||
|
assert!(new_activations.is_empty());
|
||||||
|
assert!(bank.feature_set.active(&test_feature));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
use solana_sdk::{
|
use solana_sdk::{account::Account, clock::Slot};
|
||||||
account::{Account, KeyedAccount},
|
|
||||||
account_info::AccountInfo,
|
|
||||||
clock::Slot,
|
|
||||||
instruction::InstructionError,
|
|
||||||
program_error::ProgramError,
|
|
||||||
};
|
|
||||||
|
|
||||||
solana_sdk::declare_id!("Feature111111111111111111111111111111111111");
|
solana_sdk::declare_id!("Feature111111111111111111111111111111111111");
|
||||||
|
|
||||||
@ -39,16 +33,6 @@ impl Feature {
|
|||||||
pub fn to_account(&self, account: &mut Account) -> Option<()> {
|
pub fn to_account(&self, account: &mut Account) -> Option<()> {
|
||||||
bincode::serialize_into(&mut account.data[..], self).ok()
|
bincode::serialize_into(&mut account.data[..], self).ok()
|
||||||
}
|
}
|
||||||
pub fn from_account_info(account_info: &AccountInfo) -> Result<Self, ProgramError> {
|
|
||||||
bincode::deserialize(&account_info.data.borrow()).map_err(|_| ProgramError::InvalidArgument)
|
|
||||||
}
|
|
||||||
pub fn to_account_info(&self, account_info: &mut AccountInfo) -> Option<()> {
|
|
||||||
bincode::serialize_into(&mut account_info.data.borrow_mut()[..], self).ok()
|
|
||||||
}
|
|
||||||
pub fn from_keyed_account(keyed_account: &KeyedAccount) -> Result<Self, InstructionError> {
|
|
||||||
Self::from_account(&*keyed_account.try_account_ref()?)
|
|
||||||
.ok_or(InstructionError::InvalidArgument)
|
|
||||||
}
|
|
||||||
pub fn create_account(&self, lamports: u64) -> Account {
|
pub fn create_account(&self, lamports: u64) -> Account {
|
||||||
let data_len = Self::size_of().max(bincode::serialized_size(self).unwrap() as usize);
|
let data_len = Self::size_of().max(bincode::serialized_size(self).unwrap() as usize);
|
||||||
let mut account = Account::new(lamports, data_len, &id());
|
let mut account = Account::new(lamports, data_len, &id());
|
||||||
|
@ -37,7 +37,7 @@ lazy_static! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `FeatureSet` holds the set of currently active/inactive runtime features
|
/// `FeatureSet` holds the set of currently active/inactive runtime features
|
||||||
#[derive(AbiExample)]
|
#[derive(AbiExample, Clone)]
|
||||||
pub struct FeatureSet {
|
pub struct FeatureSet {
|
||||||
pub active: HashSet<Pubkey>,
|
pub active: HashSet<Pubkey>,
|
||||||
pub inactive: HashSet<Pubkey>,
|
pub inactive: HashSet<Pubkey>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user