From f96de208e29f89b7faa95f9017700998d84858fa Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Fri, 9 Jul 2021 20:58:18 +0900 Subject: [PATCH] Implement MockInvokeContext::is_feature_active properly --- programs/bpf_loader/src/lib.rs | 2 +- runtime/src/system_instruction_processor.rs | 8 ++++++-- sdk/src/process_instruction.rs | 10 +++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index d3cb760cb..c135dae9a 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -1138,7 +1138,7 @@ mod tests { programs: vec![], accounts: vec![], sysvars: vec![], - feature_active: false, + disabled_features: vec![].into_iter().collect(), }; assert_eq!( Err(InstructionError::ProgramFailedToComplete), diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 039105300..2d7ba7461 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -941,7 +941,9 @@ mod tests { &sysvar::id(), &signers, &MockInvokeContext { - feature_active: false, + disabled_features: vec![feature_set::rent_for_sysvars::id()] + .into_iter() + .collect(), ..MockInvokeContext::new(vec![]) }, ); @@ -1089,7 +1091,9 @@ mod tests { &new_owner, &[from].iter().cloned().collect::>(), &MockInvokeContext { - feature_active: false, + disabled_features: vec![feature_set::rent_for_sysvars::id()] + .into_iter() + .collect(), ..MockInvokeContext::new(vec![]) }, ), diff --git a/sdk/src/process_instruction.rs b/sdk/src/process_instruction.rs index dbffb6327..d740c87e8 100644 --- a/sdk/src/process_instruction.rs +++ b/sdk/src/process_instruction.rs @@ -5,7 +5,7 @@ use solana_sdk::{ pubkey::Pubkey, 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 /// @@ -334,7 +334,7 @@ pub struct MockInvokeContext<'a> { pub programs: Vec<(Pubkey, ProcessInstructionWithContext)>, pub accounts: Vec<(Pubkey, Rc>)>, pub sysvars: Vec<(Pubkey, Option>>)>, - pub feature_active: bool, + pub disabled_features: HashSet, } impl<'a> MockInvokeContext<'a> { pub fn new(keyed_accounts: Vec>) -> Self { @@ -349,7 +349,7 @@ impl<'a> MockInvokeContext<'a> { programs: vec![], accounts: vec![], sysvars: vec![], - feature_active: true, + disabled_features: HashSet::default(), }; invoke_context .invoke_stack @@ -443,8 +443,8 @@ impl<'a> InvokeContext for MockInvokeContext<'a> { None } fn record_instruction(&self, _instruction: &Instruction) {} - fn is_feature_active(&self, _feature_id: &Pubkey) -> bool { - self.feature_active + fn is_feature_active(&self, feature_id: &Pubkey) -> bool { + !self.disabled_features.contains(feature_id) } fn get_account(&self, pubkey: &Pubkey) -> Option>> { for (key, account) in self.accounts.iter() {