Skip to content

Commit

Permalink
updated ProgramTest with desctivated native_programs_consume_cu featu…
Browse files Browse the repository at this point in the history
…re to continue support existing mock/test programs that do not consume units
  • Loading branch information
tao-stones committed Mar 17, 2023
1 parent 2da5054 commit b5f3f27
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 22 deletions.
7 changes: 6 additions & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,18 @@ impl Default for ProgramTest {
let prefer_bpf =
std::env::var("BPF_OUT_DIR").is_ok() || std::env::var("SBF_OUT_DIR").is_ok();

// deactivate feature `native_program_consume_cu` to continue support existing mock/test
// programs that do not consume units.
let mut deactivate_feature_set = HashSet::default();
deactivate_feature_set.insert(solana_sdk::feature_set::native_programs_consume_cu::id());

Self {
accounts: vec![],
builtins: vec![],
compute_max_units: None,
prefer_bpf,
use_bpf_jit: false,
deactivate_feature_set: HashSet::default(),
deactivate_feature_set,
transaction_account_lock_limit: None,
}
}
Expand Down
3 changes: 0 additions & 3 deletions program-test/tests/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ async fn cpi() {
invoker_program_id,
processor!(invoker_process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
let invoked_program_id = Pubkey::new_unique();
program_test.add_program(
"invoked",
Expand Down Expand Up @@ -160,7 +159,6 @@ async fn cpi_dupes() {
invoker_program_id,
processor!(invoker_dupes_process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
let invoked_program_id = Pubkey::new_unique();
program_test.add_program(
"invoked",
Expand Down Expand Up @@ -270,7 +268,6 @@ async fn stack_height() {
invoker_stack_height_program_id,
processor!(invoker_stack_height),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
program_test.add_program(
"invoked_stack_height",
invoked_stack_height_program_id,
Expand Down
6 changes: 2 additions & 4 deletions program-test/tests/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ fn simulate_fuzz() {
let rt = tokio::runtime::Runtime::new().unwrap();
let program_id = Pubkey::new_unique();
// Initialize and start the test network
let mut program_test = ProgramTest::new(
let program_test = ProgramTest::new(
"program-test-fuzz",
program_id,
processor!(process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());

let (mut banks_client, payer, last_blockhash) =
rt.block_on(async { program_test.start().await });
Expand All @@ -59,12 +58,11 @@ fn simulate_fuzz_with_context() {
let rt = tokio::runtime::Runtime::new().unwrap();
let program_id = Pubkey::new_unique();
// Initialize and start the test network
let mut program_test = ProgramTest::new(
let program_test = ProgramTest::new(
"program-test-fuzz",
program_id,
processor!(process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());

let mut context = rt.block_on(async { program_test.start_with_context().await });

Expand Down
3 changes: 1 addition & 2 deletions program-test/tests/lamports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ fn move_lamports_process_instruction(
#[tokio::test]
async fn move_lamports() {
let move_lamports_program_id = Pubkey::new_unique();
let mut program_test = ProgramTest::new(
let program_test = ProgramTest::new(
"move_lamports",
move_lamports_program_id,
processor!(move_lamports_process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());

let lamports = 1_000_000_000;
let source = Keypair::new();
Expand Down
1 change: 0 additions & 1 deletion program-test/tests/return_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ async fn return_data() {
get_return_data_program_id,
processor!(get_return_data_process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
let set_return_data_program_id = Pubkey::new_unique();
program_test.add_program(
"set_return_data",
Expand Down
3 changes: 1 addition & 2 deletions program-test/tests/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,11 @@ fn process_instruction(
async fn clock_sysvar_updated_from_warp() {
let program_id = Pubkey::new_unique();
// Initialize and start the test network
let mut program_test = ProgramTest::new(
let program_test = ProgramTest::new(
"program-test-warp",
program_id,
processor!(process_instruction),
);
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());

let mut context = program_test.start_with_context().await;
let mut expected_slot = 100_000;
Expand Down
12 changes: 3 additions & 9 deletions programs/zk-token-proof-tests/tests/process_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ async fn test_verify_proof_without_context<T, U>(
T: Pod + ZkProofData<U>,
U: Pod,
{
let mut program_test = ProgramTest::default();
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
let mut context = program_test.start_with_context().await;
let mut context = ProgramTest::default().start_with_context().await;

let client = &mut context.banks_client;
let payer = &context.payer;
Expand Down Expand Up @@ -397,9 +395,7 @@ async fn test_verify_proof_with_context<T, U>(
T: Pod + ZkProofData<U>,
U: Pod,
{
let mut program_test = ProgramTest::default();
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
let mut context = program_test.start_with_context().await;
let mut context = ProgramTest::default().start_with_context().await;
let rent = context.banks_client.get_rent().await.unwrap();

let client = &mut context.banks_client;
Expand Down Expand Up @@ -601,9 +597,7 @@ async fn test_close_context_state<T, U>(
T: Pod + ZkProofData<U>,
U: Pod,
{
let mut program_test = ProgramTest::default();
program_test.deactivate_feature(solana_sdk::feature_set::native_programs_consume_cu::id());
let mut context = program_test.start_with_context().await;
let mut context = ProgramTest::default().start_with_context().await;
let rent = context.banks_client.get_rent().await.unwrap();

let client = &mut context.banks_client;
Expand Down

0 comments on commit b5f3f27

Please sign in to comment.