|
25 | 25 | account_info::AccountInfo, |
26 | 26 | clock::Slot, |
27 | 27 | entrypoint::{ProgramResult, SUCCESS}, |
| 28 | + feature_set::FEATURE_NAMES, |
28 | 29 | fee_calculator::{FeeCalculator, FeeRateGovernor}, |
29 | 30 | genesis_config::{ClusterType, GenesisConfig}, |
30 | 31 | hash::Hash, |
|
41 | 42 | solana_vote_program::vote_state::{VoteState, VoteStateVersions}, |
42 | 43 | std::{ |
43 | 44 | cell::RefCell, |
44 | | - collections::HashMap, |
| 45 | + collections::{HashMap, HashSet}, |
45 | 46 | convert::TryFrom, |
46 | 47 | fs::File, |
47 | 48 | io::{self, Read}, |
|
58 | 59 | tokio::task::JoinHandle, |
59 | 60 | }; |
60 | 61 | // Export types so test clients can limit their solana crate dependencies |
61 | | -pub use {solana_banks_client::BanksClient, solana_program_runtime::invoke_context::InvokeContext}; |
| 62 | +pub use { |
| 63 | + solana_banks_client::{BanksClient, BanksClientError}, |
| 64 | + solana_program_runtime::invoke_context::InvokeContext, |
| 65 | +}; |
62 | 66 |
|
63 | 67 | pub mod programs; |
64 | 68 |
|
@@ -469,6 +473,7 @@ pub struct ProgramTest { |
469 | 473 | compute_max_units: Option<u64>, |
470 | 474 | prefer_bpf: bool, |
471 | 475 | use_bpf_jit: bool, |
| 476 | + deactivate_feature_set: HashSet<Pubkey>, |
472 | 477 | } |
473 | 478 |
|
474 | 479 | impl Default for ProgramTest { |
@@ -499,6 +504,7 @@ impl Default for ProgramTest { |
499 | 504 | compute_max_units: None, |
500 | 505 | prefer_bpf, |
501 | 506 | use_bpf_jit: false, |
| 507 | + deactivate_feature_set: HashSet::default(), |
502 | 508 | } |
503 | 509 | } |
504 | 510 | } |
@@ -728,6 +734,13 @@ impl ProgramTest { |
728 | 734 | .push(Builtin::new(program_name, program_id, process_instruction)); |
729 | 735 | } |
730 | 736 |
|
| 737 | + /// Deactivate a runtime feature. |
| 738 | + /// |
| 739 | + /// Note that all features are activated by default. |
| 740 | + pub fn deactivate_feature(&mut self, feature_id: Pubkey) { |
| 741 | + self.deactivate_feature_set.insert(feature_id); |
| 742 | + } |
| 743 | + |
731 | 744 | fn setup_bank( |
732 | 745 | &self, |
733 | 746 | ) -> ( |
@@ -767,6 +780,25 @@ impl ProgramTest { |
767 | 780 | ClusterType::Development, |
768 | 781 | vec![], |
769 | 782 | ); |
| 783 | + |
| 784 | + // Remove features tagged to deactivate |
| 785 | + for deactivate_feature_pk in &self.deactivate_feature_set { |
| 786 | + if FEATURE_NAMES.contains_key(deactivate_feature_pk) { |
| 787 | + match genesis_config.accounts.remove(deactivate_feature_pk) { |
| 788 | + Some(_) => debug!("Feature for {:?} deactivated", deactivate_feature_pk), |
| 789 | + None => warn!( |
| 790 | + "Feature {:?} set for deactivation not found in genesis_config account list, ignored.", |
| 791 | + deactivate_feature_pk |
| 792 | + ), |
| 793 | + } |
| 794 | + } else { |
| 795 | + warn!( |
| 796 | + "Feature {:?} set for deactivation is not a known Feature public key", |
| 797 | + deactivate_feature_pk |
| 798 | + ); |
| 799 | + } |
| 800 | + } |
| 801 | + |
770 | 802 | let target_tick_duration = Duration::from_micros(100); |
771 | 803 | genesis_config.poh_config = PohConfig::new_sleep(target_tick_duration); |
772 | 804 | debug!("Payer address: {}", mint_keypair.pubkey()); |
|
0 commit comments