Implement MockInvokeContext::is_feature_active properly
This commit is contained in:
parent
b0734fabf7
commit
f96de208e2
|
@ -1138,7 +1138,7 @@ mod tests {
|
||||||
programs: vec![],
|
programs: vec![],
|
||||||
accounts: vec![],
|
accounts: vec![],
|
||||||
sysvars: vec![],
|
sysvars: vec![],
|
||||||
feature_active: false,
|
disabled_features: vec![].into_iter().collect(),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Err(InstructionError::ProgramFailedToComplete),
|
Err(InstructionError::ProgramFailedToComplete),
|
||||||
|
|
|
@ -941,7 +941,9 @@ mod tests {
|
||||||
&sysvar::id(),
|
&sysvar::id(),
|
||||||
&signers,
|
&signers,
|
||||||
&MockInvokeContext {
|
&MockInvokeContext {
|
||||||
feature_active: false,
|
disabled_features: vec![feature_set::rent_for_sysvars::id()]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
..MockInvokeContext::new(vec![])
|
..MockInvokeContext::new(vec![])
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1089,7 +1091,9 @@ mod tests {
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[from].iter().cloned().collect::<HashSet<_>>(),
|
&[from].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext {
|
&MockInvokeContext {
|
||||||
feature_active: false,
|
disabled_features: vec![feature_set::rent_for_sysvars::id()]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
..MockInvokeContext::new(vec![])
|
..MockInvokeContext::new(vec![])
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -5,7 +5,7 @@ use solana_sdk::{
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
sysvar::Sysvar,
|
sysvar::Sysvar,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, fmt::Debug, rc::Rc, sync::Arc};
|
use std::{cell::RefCell, collections::HashSet, fmt::Debug, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
/// Prototype of a native loader entry point
|
/// Prototype of a native loader entry point
|
||||||
///
|
///
|
||||||
|
@ -334,7 +334,7 @@ pub struct MockInvokeContext<'a> {
|
||||||
pub programs: Vec<(Pubkey, ProcessInstructionWithContext)>,
|
pub programs: Vec<(Pubkey, ProcessInstructionWithContext)>,
|
||||||
pub accounts: Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>,
|
pub accounts: Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>,
|
||||||
pub sysvars: Vec<(Pubkey, Option<Rc<Vec<u8>>>)>,
|
pub sysvars: Vec<(Pubkey, Option<Rc<Vec<u8>>>)>,
|
||||||
pub feature_active: bool,
|
pub disabled_features: HashSet<Pubkey>,
|
||||||
}
|
}
|
||||||
impl<'a> MockInvokeContext<'a> {
|
impl<'a> MockInvokeContext<'a> {
|
||||||
pub fn new(keyed_accounts: Vec<KeyedAccount<'a>>) -> Self {
|
pub fn new(keyed_accounts: Vec<KeyedAccount<'a>>) -> Self {
|
||||||
|
@ -349,7 +349,7 @@ impl<'a> MockInvokeContext<'a> {
|
||||||
programs: vec![],
|
programs: vec![],
|
||||||
accounts: vec![],
|
accounts: vec![],
|
||||||
sysvars: vec![],
|
sysvars: vec![],
|
||||||
feature_active: true,
|
disabled_features: HashSet::default(),
|
||||||
};
|
};
|
||||||
invoke_context
|
invoke_context
|
||||||
.invoke_stack
|
.invoke_stack
|
||||||
|
@ -443,8 +443,8 @@ impl<'a> InvokeContext for MockInvokeContext<'a> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn record_instruction(&self, _instruction: &Instruction) {}
|
fn record_instruction(&self, _instruction: &Instruction) {}
|
||||||
fn is_feature_active(&self, _feature_id: &Pubkey) -> bool {
|
fn is_feature_active(&self, feature_id: &Pubkey) -> bool {
|
||||||
self.feature_active
|
!self.disabled_features.contains(feature_id)
|
||||||
}
|
}
|
||||||
fn get_account(&self, pubkey: &Pubkey) -> Option<Rc<RefCell<AccountSharedData>>> {
|
fn get_account(&self, pubkey: &Pubkey) -> Option<Rc<RefCell<AccountSharedData>>> {
|
||||||
for (key, account) in self.accounts.iter() {
|
for (key, account) in self.accounts.iter() {
|
||||||
|
|
Loading…
Reference in New Issue