From 08dba4c396bdad257ea01b3af31243df036f05c0 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Sun, 14 Jan 2024 19:20:01 -0500 Subject: [PATCH 1/5] Upgrade sbf tests to use bpf loader v3 (#34691) * update sbf test to use bpf_loader v2 * update test_program_sbf_invoke_sanity test * update test bpf program owner * update test_program_sbf_invoke_upgradeable_via_cpi * update test_program_sbf_disguised_as_sbf_loader * update test_program_reads_from_program_account * update test_program_sbf_program_id_spoofing * update test_program_sbf_caller_has_access_to_cpi_program * update 3 more tests * fix program buffer size in minimul for rent exempt calculation * more test updates * more update * more test updates * comments * undo c format * typo * add sol_alloc_free not deployable and deployable tests * comments * review feedback - move buffer_keypair and program_keypair inside callee fn. * more refactor * delete sof_alloc_free_syscall enabled tests * revert lamport change --------- Co-authored-by: HaoranYi (cherry picked from commit 8869d0c8a0b56c4294fe9292bf856e79d16989b5) # Conflicts: # programs/sbf/tests/programs.rs --- programs/sbf/c/src/invoked/invoked.c | 11 +- .../sbf/c/src/read_program/read_program.c | 2 +- programs/sbf/rust/invoked/src/processor.rs | 7 +- programs/sbf/tests/programs.rs | 608 ++++++++++++++---- 4 files changed, 509 insertions(+), 119 deletions(-) diff --git a/programs/sbf/c/src/invoked/invoked.c b/programs/sbf/c/src/invoked/invoked.c index f57896c47bf44c..37671cfb9fe51b 100644 --- a/programs/sbf/c/src/invoked/invoked.c +++ b/programs/sbf/c/src/invoked/invoked.c @@ -31,10 +31,11 @@ extern uint64_t entrypoint(const uint8_t *input) { static const int INVOKED_PROGRAM_DUP_INDEX = 3; sol_assert(sol_deserialize(input, ¶ms, 4)); - SolPubkey sbf_loader_id = - (SolPubkey){.x = {2, 168, 246, 145, 78, 136, 161, 110, 57, 90, 225, - 40, 148, 143, 250, 105, 86, 147, 55, 104, 24, 221, - 71, 67, 82, 33, 243, 198, 0, 0, 0, 0}}; + SolPubkey sbf_loader_upgradeable_id = + (SolPubkey){.x = { + 2, 168, 246, 145, 78, 136, 161, 176, 226, 16, 21, 62, + 247, 99, 174, 43, 0, 194, 185, 61, 22, 193, 36, 210, 192, + 83, 122, 16, 4, 128, 0, 0}}; for (int i = 0; i < params.data_len; i++) { sol_assert(params.data[i] == i); @@ -63,7 +64,7 @@ extern uint64_t entrypoint(const uint8_t *input) { sol_assert( SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].key, params.program_id)) sol_assert(SolPubkey_same(accounts[INVOKED_PROGRAM_INDEX].owner, - &sbf_loader_id)); + &sbf_loader_upgradeable_id)); sol_assert(!accounts[INVOKED_PROGRAM_INDEX].is_signer); sol_assert(!accounts[INVOKED_PROGRAM_INDEX].is_writable); sol_assert(accounts[INVOKED_PROGRAM_INDEX].rent_epoch == UINT64_MAX); diff --git a/programs/sbf/c/src/read_program/read_program.c b/programs/sbf/c/src/read_program/read_program.c index 47e5a22d4c1c76..28d242efa7f8be 100644 --- a/programs/sbf/c/src/read_program/read_program.c +++ b/programs/sbf/c/src/read_program/read_program.c @@ -10,7 +10,7 @@ extern uint64_t entrypoint(const uint8_t *input) { return ERROR_INVALID_ARGUMENT; } - char ka_data[] = {0x7F, 0x45, 0x4C, 0x46}; + char ka_data[] = {0x02, 0x00, 0x00, 0x00}; sol_assert(params.ka_num == 1); sol_assert(!sol_memcmp(params.ka[0].data, ka_data, 4)); diff --git a/programs/sbf/rust/invoked/src/processor.rs b/programs/sbf/rust/invoked/src/processor.rs index 52d02dc99a6c21..8f60a90c15cf4e 100644 --- a/programs/sbf/rust/invoked/src/processor.rs +++ b/programs/sbf/rust/invoked/src/processor.rs @@ -7,7 +7,7 @@ use { crate::instructions::*, solana_program::{ account_info::AccountInfo, - bpf_loader, + bpf_loader_upgradeable, entrypoint::{ProgramResult, MAX_PERMITTED_DATA_INCREASE}, log::sol_log_64, msg, @@ -70,7 +70,10 @@ fn process_instruction( assert!(!accounts[INVOKED_ARGUMENT_INDEX].executable); assert_eq!(accounts[INVOKED_PROGRAM_INDEX].key, program_id); - assert_eq!(accounts[INVOKED_PROGRAM_INDEX].owner, &bpf_loader::id()); + assert_eq!( + accounts[INVOKED_PROGRAM_INDEX].owner, + &bpf_loader_upgradeable::id() + ); assert!(!accounts[INVOKED_PROGRAM_INDEX].is_signer); assert!(!accounts[INVOKED_PROGRAM_INDEX].is_writable); assert_eq!(accounts[INVOKED_PROGRAM_INDEX].rent_epoch, u64::MAX); diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 9aac20bdc7d410..07aaed6dabdd63 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -268,6 +268,48 @@ fn load_program_and_advance_slot( ) } +fn load_upgradeable_program_wrapper( + bank_client: &BankClient, + mint_keypair: &Keypair, + authority_keypair: &Keypair, + name: &str, +) -> Pubkey { + let buffer_keypair = Keypair::new(); + let program_keypair = Keypair::new(); + load_upgradeable_program( + bank_client, + mint_keypair, + &buffer_keypair, + &program_keypair, + authority_keypair, + name, + ); + program_keypair.pubkey() +} + +fn load_upgradeable_program_and_advance_slot( + bank_client: &mut BankClient, + bank_forks: &RwLock, + mint_keypair: &Keypair, + authority_keypair: &Keypair, + name: &str, +) -> (Arc, Pubkey) { + let program_id = + load_upgradeable_program_wrapper(bank_client, mint_keypair, authority_keypair, name); + + // load_upgradeable_program sets clock sysvar to 1, which causes the program to be effective + // after 2 slots. They need to be called individually to create the correct fork graph in between. + bank_client + .advance_slot(1, bank_forks, &Pubkey::default()) + .expect("Failed to advance the slot"); + + let bank = bank_client + .advance_slot(1, bank_forks, &Pubkey::default()) + .expect("Failed to advance the slot"); + + (bank, program_id) +} + #[test] #[cfg(any(feature = "sbf_c", feature = "sbf_rust"))] fn test_program_sbf_sanity() { @@ -327,11 +369,12 @@ fn test_program_sbf_sanity() { println!("Test program: {:?}", program.0); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -340,14 +383,25 @@ fn test_program_sbf_sanity() { let bank = Bank::new_for_tests(&genesis_config); let mut bank_client = BankClient::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) // Call user program - let (_, program_id) = load_program_and_advance_slot( + let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, program.0, ); + let account_metas = vec![ AccountMeta::new(mint_keypair.pubkey(), true), AccountMeta::new(Keypair::new().pubkey(), false), @@ -403,6 +457,12 @@ fn test_program_sbf_loader_deprecated() { } } +/// This test is written with bpf_loader v2 specific instructions, which will be +/// deprecated when `disable_bpf_loader_instructions` feature is activated. +/// +/// The same test has been migrated to +/// `test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader` with a new version +/// of bpf_upgradeable_loader! #[test] #[cfg(feature = "sbf_rust")] fn test_sol_alloc_free_no_longer_deployable() { @@ -423,9 +483,16 @@ fn test_sol_alloc_free_no_longer_deployable() { .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +<<<<<<< HEAD let mut bank = Bank::new_for_tests(&genesis_config); +======= + genesis_config + .accounts + .remove(&feature_set::deprecate_executable_meta_update_in_bpf_loader::id()); + + let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) - // Populate loader account with elf that depends on _sol_alloc_free syscall let elf = load_program_from_file("solana_sbf_rust_deprecated_loader"); let mut program_account = AccountSharedData::new(1, elf.len(), &bpf_loader::id()); program_account @@ -447,25 +514,14 @@ fn test_sol_alloc_free_no_longer_deployable() { bank.last_blockhash(), ); - let invoke_tx = Transaction::new( - &[&mint_keypair], - Message::new( - &[Instruction::new_with_bytes( - program_address, - &[255], - vec![AccountMeta::new(mint_keypair.pubkey(), true)], - )], - Some(&mint_keypair.pubkey()), - ), - bank.last_blockhash(), - ); - // Try and deploy a program that depends on _sol_alloc_free assert_eq!( bank.process_transaction(&finalize_tx).unwrap_err(), TransactionError::InstructionError(0, InstructionError::InvalidAccountData) ); +} +<<<<<<< HEAD // Enable _sol_alloc_free syscall bank.deactivate_feature(&solana_sdk::feature_set::disable_deploy_of_alloc_free_syscall::id()); bank.clear_signatures(); @@ -475,22 +531,52 @@ fn test_sol_alloc_free_no_longer_deployable() { assert!(bank.process_transaction(&finalize_tx).is_ok()); let new_slot = bank.slot() + 1; let mut bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), new_slot); +======= +#[test] +#[cfg(feature = "sbf_rust")] +#[should_panic( + expected = "called `Result::unwrap()` on an `Err` value: TransactionError(InstructionError(1, InvalidAccountData))" +)] +fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { + solana_logger::setup(); + + let GenesisConfigInfo { + genesis_config, + mint_keypair, + .. + } = create_genesis_config(50); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) - // invoke the program - assert!(bank.process_transaction(&invoke_tx).is_ok()); + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); +<<<<<<< HEAD // disable _sol_alloc_free bank.activate_feature(&solana_sdk::feature_set::disable_deploy_of_alloc_free_syscall::id()); bank.clear_signatures(); - - // invoke should still succeed because cached - assert!(bank.process_transaction(&invoke_tx).is_ok()); - - bank.clear_signatures(); - bank.clear_program_cache(); - - // invoke should still succeed on execute because the program is already deployed - assert!(bank.process_transaction(&invoke_tx).is_ok()); +======= + // Populate loader account with `solana_sbf_rust_deprecated_loader` elf, which + // depends on `sol_alloc_free_` syscall. This can be verified with + // $ elfdump solana_sbf_rust_deprecated_loader.so + // : 0000000000001ab8 000000070000000a R_BPF_64_32 0000000000000000 sol_alloc_free_ + // In the symbol table, there is `sol_alloc_free_`. + // In fact, `sol_alloc_free_` is called from sbf allocator, which is originated from + // AccountInfo::realloc() in the program code. +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) + + // Expect that deployment to fail. B/C during deployment, there is an elf + // verification step, which uses the runtime to look up relocatable symbols + // in elf inside syscall table. In this case, `sol_alloc_free_` can't be + // found in syscall table. Hence, the verification fails and the deployment + // fails. + let (_bank, _program_id) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), + &mint_keypair, + &authority_keypair, + "solana_sbf_rust_deprecated_loader", + ); } #[test] @@ -512,11 +598,12 @@ fn test_program_sbf_duplicate_accounts() { println!("Test program: {:?}", program); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -525,11 +612,21 @@ fn test_program_sbf_duplicate_accounts() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); - let (bank, program_id) = load_program_and_advance_slot( + let authority_keypair = Keypair::new(); + + let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, program, ); let payee_account = AccountSharedData::new(10, 1, &program_id); @@ -623,11 +720,12 @@ fn test_program_sbf_error_handling() { println!("Test program: {:?}", program); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -639,9 +737,20 @@ fn test_program_sbf_error_handling() { let (_, program_id) = load_program_and_advance_slot( &mut bank_client, &bpf_loader::id(), +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + + let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, program, ); + let account_metas = vec![AccountMeta::new(mint_keypair.pubkey(), true)]; let instruction = Instruction::new_with_bytes(program_id, &[1], account_metas.clone()); @@ -735,11 +844,12 @@ fn test_return_data_and_log_data_syscall() { for program in programs.iter() { let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -748,12 +858,21 @@ fn test_return_data_and_log_data_syscall() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let (bank, program_id) = load_program_and_advance_slot( + let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, program, ); @@ -810,11 +929,12 @@ fn test_program_sbf_invoke_sanity() { println!("Test program: {:?}", program); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -823,16 +943,35 @@ fn test_program_sbf_invoke_sanity() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); + + let invoke_program_id = load_upgradeable_program_wrapper( + &bank_client, + &mint_keypair, + &authority_keypair, + program.1, + ); - let invoke_program_id = - load_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.1); - let invoked_program_id = - load_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.2); - let (bank, noop_program_id) = load_program_and_advance_slot( + let invoked_program_id = load_upgradeable_program_wrapper( + &bank_client, + &mint_keypair, + &authority_keypair, + program.2, + ); + + let (bank, noop_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, program.3, ); @@ -1214,11 +1353,12 @@ fn test_program_sbf_invoke_sanity() { #[cfg(feature = "sbf_rust")] fn test_program_sbf_program_id_spoofing() { let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -1227,18 +1367,28 @@ fn test_program_sbf_program_id_spoofing() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let malicious_swap_pubkey = load_program( + let malicious_swap_pubkey = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_spoof1", ); - let (bank, malicious_system_pubkey) = load_program_and_advance_slot( + + let (bank, malicious_system_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_spoof1_system", ); @@ -1272,11 +1422,12 @@ fn test_program_sbf_program_id_spoofing() { #[cfg(feature = "sbf_rust")] fn test_program_sbf_caller_has_access_to_cpi_program() { let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -1285,20 +1436,31 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let caller_pubkey = load_program( + let caller_pubkey = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_caller_access", ); - let (_, caller2_pubkey) = load_program_and_advance_slot( + + let (_bank, caller2_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_caller_access", ); + let account_metas = vec![ AccountMeta::new_readonly(caller_pubkey, false), AccountMeta::new_readonly(caller2_pubkey, false), @@ -1317,11 +1479,12 @@ fn test_program_sbf_ro_modify() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -1330,12 +1493,21 @@ fn test_program_sbf_ro_modify() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let (bank, program_pubkey) = load_program_and_advance_slot( + let (bank, program_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_ro_modify", ); @@ -1379,11 +1551,12 @@ fn test_program_sbf_call_depth() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -1395,7 +1568,17 @@ fn test_program_sbf_call_depth() { let (_, program_id) = load_program_and_advance_slot( &mut bank_client, &bpf_loader::id(), +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + + let (_, program_id) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_call_depth", ); @@ -1419,11 +1602,12 @@ fn test_program_sbf_compute_budget() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -1435,7 +1619,17 @@ fn test_program_sbf_compute_budget() { let (_, program_id) = load_program_and_advance_slot( &mut bank_client, &bpf_loader::id(), +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + + let (_, program_id) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_noop", ); let message = Message::new( @@ -1553,11 +1747,12 @@ fn test_program_sbf_instruction_introspection() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50_000); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -1566,12 +1761,21 @@ fn test_program_sbf_instruction_introspection() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let (bank, program_id) = load_program_and_advance_slot( + let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_instruction_introspection", ); @@ -1612,6 +1816,9 @@ fn test_program_sbf_instruction_introspection() { assert!(bank.get_account(&sysvar::instructions::id()).is_none()); } +/// This test is to test bpf_loader v2 `Finalize` instruction with different +/// programs. It is going to be deprecated once we activate +/// `disable_bpf_loader_instructions`. #[test] #[cfg(feature = "sbf_rust")] fn test_program_sbf_test_use_latest_executor() { @@ -1659,6 +1866,7 @@ fn test_program_sbf_test_use_latest_executor() { bank_client .advance_slot(1, &Pubkey::default()) .expect("Failed to advance the slot"); + assert!(bank_client .send_and_confirm_message(&[&mint_keypair, &program_keypair], message) .is_err()); @@ -2312,11 +2520,12 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -2328,23 +2537,31 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { let invoke_and_return = load_program( &bank_client, &bpf_loader::id(), +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + + let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // Deploy upgradeable program - let buffer_keypair = Keypair::new(); - let program_keypair = Keypair::new(); - let program_id = program_keypair.pubkey(); - let authority_keypair = Keypair::new(); - load_upgradeable_program( + let program_id = load_upgradeable_program_wrapper( &bank_client, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); + bank_client.set_sysvar_for_tests(&clock::Clock { + slot: 2, + ..clock::Clock::default() + }); bank_client .advance_slot(1, &Pubkey::default()) @@ -2378,7 +2595,7 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { "solana_sbf_rust_upgraded", ); bank_client.set_sysvar_for_tests(&clock::Clock { - slot: 2, + slot: 3, ..clock::Clock::default() }); bank_client @@ -2458,10 +2675,23 @@ fn test_program_sbf_disguised_as_sbf_loader() { bank.deactivate_feature( &solana_sdk::feature_set::remove_bpf_loader_incorrect_program_id::id(), ); +<<<<<<< HEAD bank.deactivate_feature(&feature_set::disable_bpf_loader_instructions::id()); let bank_client = BankClient::new(bank); +======= + let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + + let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), + &mint_keypair, + &authority_keypair, + program, + ); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) - let program_id = load_program(&bank_client, &bpf_loader::id(), &mint_keypair, program); let account_metas = vec![AccountMeta::new_readonly(program_id, false)]; let instruction = Instruction::new_with_bytes(bpf_loader::id(), &[1], account_metas); let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction); @@ -2478,11 +2708,12 @@ fn test_program_reads_from_program_account() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -2491,11 +2722,21 @@ fn test_program_reads_from_program_account() { let bank = Bank::new_for_tests(&genesis_config); let mut bank_client = BankClient::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) - let (_, program_id) = load_program_and_advance_slot( + let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "read_program", ); let account_metas = vec![AccountMeta::new_readonly(program_id, false)]; @@ -2511,11 +2752,12 @@ fn test_program_sbf_c_dup() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -2523,15 +2765,30 @@ fn test_program_sbf_c_dup() { .remove(&feature_set::disable_bpf_loader_instructions::id()); let bank = Bank::new_for_tests(&genesis_config); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let account_address = Pubkey::new_unique(); let account = AccountSharedData::new_data(42, &[1_u8, 2, 3], &system_program::id()).unwrap(); bank.store_account(&account_address, &account); +<<<<<<< HEAD let mut bank_client = BankClient::new(bank); let (_, program_id) = load_program_and_advance_slot(&mut bank_client, &bpf_loader::id(), &mint_keypair, "ser"); +======= + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + let (_, program_id) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), + &mint_keypair, + &authority_keypair, + "ser", + ); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let account_metas = vec![ AccountMeta::new_readonly(account_address, false), AccountMeta::new_readonly(account_address, false), @@ -2548,11 +2805,12 @@ fn test_program_sbf_upgrade_via_cpi() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -2564,7 +2822,17 @@ fn test_program_sbf_upgrade_via_cpi() { let invoke_and_return = load_program( &bank_client, &bpf_loader::id(), +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); + + let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( + &mut bank_client, + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke_and_return", ); @@ -2665,11 +2933,12 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -2678,25 +2947,24 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { let bank = Bank::new_for_tests(&genesis_config); let mut bank_client = BankClient::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) // Deploy CPI invoker program - let invoke_and_return = load_program( + let invoke_and_return = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // Deploy upgradeable program - let buffer_keypair = Keypair::new(); - let program_keypair = Keypair::new(); - let program_id = program_keypair.pubkey(); - let authority_keypair = Keypair::new(); - load_upgradeable_program( + let program_id = load_upgradeable_program_wrapper( &bank_client, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); @@ -2882,6 +3150,8 @@ fn test_program_upgradeable_locks() { assert_eq!(results2[1], Err(TransactionError::AccountInUse)); } +/// This test is to test bpf_loader v2 `Finalize` instruction. It is going to be +/// deprecated once we activate `disable_bpf_loader_instructions`. #[test] #[cfg(feature = "sbf_rust")] fn test_program_sbf_finalize() { @@ -2943,11 +3213,12 @@ fn test_program_sbf_ro_account_modify() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -2956,12 +3227,21 @@ fn test_program_sbf_ro_account_modify() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let (bank, program_id) = load_program_and_advance_slot( + let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_ro_account_modify", ); @@ -3012,17 +3292,20 @@ fn test_program_sbf_realloc() { const START_BALANCE: u64 = 100_000_000_000; let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(1_000_000_000_000); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mint_pubkey = mint_keypair.pubkey(); let signer = &[&mint_keypair]; for direct_mapping in [false, true] { @@ -3035,11 +3318,17 @@ fn test_program_sbf_realloc() { } let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let (bank, program_id) = load_program_and_advance_slot( + let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_realloc", ); @@ -3358,30 +3647,39 @@ fn test_program_sbf_realloc_invoke() { } = create_genesis_config(1_000_000_000_000); genesis_config.rent = Rent::default(); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mint_pubkey = mint_keypair.pubkey(); let signer = &[&mint_keypair]; let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let realloc_program_id = load_program( + let realloc_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_realloc", ); - let (bank, realloc_invoke_program_id) = load_program_and_advance_slot( + let (bank, realloc_invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_realloc_invoke", ); @@ -3836,7 +4134,7 @@ fn test_program_sbf_realloc_invoke() { TransactionError::InstructionError(0, InstructionError::InvalidRealloc) ); - // Realloc rescursively and fill data + // Realloc recursively and fill data let invoke_keypair = Keypair::new(); let invoke_pubkey = invoke_keypair.pubkey().clone(); let invoke_account = AccountSharedData::new(START_BALANCE, 0, &realloc_invoke_program_id); @@ -3879,11 +4177,12 @@ fn test_program_sbf_processed_inner_instruction() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(50); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config @@ -3892,30 +4191,39 @@ fn test_program_sbf_processed_inner_instruction() { let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); +======= + let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let sibling_program_id = load_program( + let sibling_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_sibling_instructions", ); - let sibling_inner_program_id = load_program( + let sibling_inner_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_sibling_inner_instructions", ); - let noop_program_id = load_program( + let noop_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_noop", ); - let (_, invoke_and_return_program_id) = load_program_and_advance_slot( + let (_, invoke_and_return_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke_and_return", ); @@ -3967,23 +4275,37 @@ fn test_program_fees() { .. } = create_genesis_config(500_000_000); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) genesis_config.fee_rate_governor = FeeRateGovernor::new(congestion_multiplier, 0); let mut bank = Bank::new_for_tests(&genesis_config); let fee_structure = FeeStructure::new(0.000005, 0.0, vec![(200, 0.0000005), (1400000, 0.000005)]); bank.fee_structure = fee_structure.clone(); +<<<<<<< HEAD let mut bank_client = BankClient::new(bank); +======= + let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); + let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) - let (_, program_id) = load_program_and_advance_slot( + let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_noop", ); @@ -4047,25 +4369,34 @@ fn test_program_fees() { #[cfg(feature = "sbf_rust")] fn test_get_minimum_delegation() { let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(100_123_456_789); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); + let authority_keypair = Keypair::new(); - let (_, program_id) = load_program_and_advance_slot( + let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_get_minimum_delegation", ); @@ -4129,31 +4460,41 @@ fn test_cpi_account_ownership_writability() { if !direct_mapping { feature_set.deactivate(&feature_set::bpf_account_data_direct_mapping::id()); } +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. feature_set.deactivate(&feature_set::disable_bpf_loader_instructions::id()); +======= + +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) bank.feature_set = Arc::new(feature_set); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); - let invoke_program_id = load_program( + let invoke_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke", ); - let invoked_program_id = load_program( + let invoked_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoked", ); - let (bank, realloc_program_id) = load_program_and_advance_slot( + let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_realloc", ); @@ -4313,25 +4654,34 @@ fn test_cpi_account_data_updates() { if !direct_mapping { feature_set.deactivate(&feature_set::bpf_account_data_direct_mapping::id()); } +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. feature_set.deactivate(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) bank.feature_set = Arc::new(feature_set); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); - let invoke_program_id = load_program( + let invoke_program_id = load_upgradeable_program_wrapper( &bank_client, - &bpf_loader::id(), &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke", ); - let (bank, realloc_program_id) = load_program_and_advance_slot( + let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_realloc", ); @@ -4465,10 +4815,13 @@ fn test_cpi_deprecated_loader_realloc() { feature_set.deactivate(&feature_set::bpf_account_data_direct_mapping::id()); } +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. feature_set.deactivate(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) bank.feature_set = Arc::new(feature_set); let bank = Arc::new(bank); @@ -4479,11 +4832,17 @@ fn test_cpi_deprecated_loader_realloc() { ); let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_program_and_advance_slot( + let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke", ); @@ -4572,17 +4931,20 @@ fn test_cpi_change_account_data_memory_allocation() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(100_123_456_789); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank = Bank::new_for_tests(&genesis_config); declare_process_instruction!(MockBuiltin, 42, |invoke_context| { @@ -4627,11 +4989,17 @@ fn test_cpi_change_account_data_memory_allocation() { let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_program_and_advance_slot( + let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke", ); @@ -4662,28 +5030,37 @@ fn test_cpi_invalid_account_info_pointers() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(100_123_456_789); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); let c_invoke_program_id = - load_program(&bank_client, &bpf_loader::id(), &mint_keypair, "invoke"); + load_upgradeable_program_wrapper(&bank_client, &mint_keypair, &authority_keypair, "invoke"); - let (bank, invoke_program_id) = load_program_and_advance_slot( + let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke", ); @@ -4729,17 +5106,20 @@ fn test_deny_executable_write() { solana_logger::setup(); let GenesisConfigInfo { - mut genesis_config, + genesis_config, mint_keypair, .. } = create_genesis_config(100_123_456_789); +<<<<<<< HEAD // deactivate `disable_bpf_loader_instructions` feature so that the program // can be loaded, finalized and tested. genesis_config .accounts .remove(&feature_set::disable_bpf_loader_instructions::id()); +======= +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) for direct_mapping in [false, true] { let mut bank = Bank::new_for_tests(&genesis_config); let feature_set = Arc::make_mut(&mut bank.feature_set); @@ -4750,11 +5130,17 @@ fn test_deny_executable_write() { } let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); + let authority_keypair = Keypair::new(); - let (_bank, invoke_program_id) = load_program_and_advance_slot( + let (_bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, +<<<<<<< HEAD &bpf_loader::id(), +======= + bank_forks.as_ref(), +>>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, + &authority_keypair, "solana_sbf_rust_invoke", ); From e7c6fdb3e8cfab11e7627c7bd1861cfdeca4e9fb Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Fri, 9 Feb 2024 15:31:34 +0000 Subject: [PATCH 2/5] fix merge conflicts --- programs/sbf/tests/programs.rs | 477 --------------------------------- 1 file changed, 477 deletions(-) diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 07aaed6dabdd63..b870af2580ce97 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -374,29 +374,14 @@ fn test_program_sbf_sanity() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) // Call user program let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, program.0, @@ -457,81 +442,6 @@ fn test_program_sbf_loader_deprecated() { } } -/// This test is written with bpf_loader v2 specific instructions, which will be -/// deprecated when `disable_bpf_loader_instructions` feature is activated. -/// -/// The same test has been migrated to -/// `test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader` with a new version -/// of bpf_upgradeable_loader! -#[test] -#[cfg(feature = "sbf_rust")] -fn test_sol_alloc_free_no_longer_deployable() { - solana_logger::setup(); - - let program_keypair = Keypair::new(); - let program_address = program_keypair.pubkey(); - - let GenesisConfigInfo { - mut genesis_config, - mint_keypair, - .. - } = create_genesis_config(50); - - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -<<<<<<< HEAD - let mut bank = Bank::new_for_tests(&genesis_config); -======= - genesis_config - .accounts - .remove(&feature_set::deprecate_executable_meta_update_in_bpf_loader::id()); - - let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) - - let elf = load_program_from_file("solana_sbf_rust_deprecated_loader"); - let mut program_account = AccountSharedData::new(1, elf.len(), &bpf_loader::id()); - program_account - .data_as_mut_slice() - .get_mut(..) - .unwrap() - .copy_from_slice(&elf); - bank.store_account(&program_address, &program_account); - - let finalize_tx = Transaction::new( - &[&mint_keypair, &program_keypair], - Message::new( - &[loader_instruction::finalize( - &program_keypair.pubkey(), - &bpf_loader::id(), - )], - Some(&mint_keypair.pubkey()), - ), - bank.last_blockhash(), - ); - - // Try and deploy a program that depends on _sol_alloc_free - assert_eq!( - bank.process_transaction(&finalize_tx).unwrap_err(), - TransactionError::InstructionError(0, InstructionError::InvalidAccountData) - ); -} - -<<<<<<< HEAD - // Enable _sol_alloc_free syscall - bank.deactivate_feature(&solana_sdk::feature_set::disable_deploy_of_alloc_free_syscall::id()); - bank.clear_signatures(); - bank.clear_program_cache(); - - // Try and finalize the program now that sol_alloc_free is re-enabled - assert!(bank.process_transaction(&finalize_tx).is_ok()); - let new_slot = bank.slot() + 1; - let mut bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), new_slot); -======= #[test] #[cfg(feature = "sbf_rust")] #[should_panic( @@ -545,17 +455,11 @@ fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { mint_keypair, .. } = create_genesis_config(50); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); -<<<<<<< HEAD - // disable _sol_alloc_free - bank.activate_feature(&solana_sdk::feature_set::disable_deploy_of_alloc_free_syscall::id()); - bank.clear_signatures(); -======= // Populate loader account with `solana_sbf_rust_deprecated_loader` elf, which // depends on `sol_alloc_free_` syscall. This can be verified with // $ elfdump solana_sbf_rust_deprecated_loader.so @@ -563,7 +467,6 @@ fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { // In the symbol table, there is `sol_alloc_free_`. // In fact, `sol_alloc_free_` is called from sbf allocator, which is originated from // AccountInfo::realloc() in the program code. ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) // Expect that deployment to fail. B/C during deployment, there is an elf // verification step, which uses the runtime to look up relocatable symbols @@ -603,28 +506,13 @@ fn test_program_sbf_duplicate_accounts() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, program, @@ -725,19 +613,6 @@ fn test_program_sbf_error_handling() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); - let (_, program_id) = load_program_and_advance_slot( - &mut bank_client, - &bpf_loader::id(), -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); @@ -745,7 +620,6 @@ fn test_program_sbf_error_handling() { let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, program, @@ -849,28 +723,13 @@ fn test_return_data_and_log_data_syscall() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, program, @@ -934,18 +793,7 @@ fn test_program_sbf_invoke_sanity() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -965,11 +813,7 @@ fn test_program_sbf_invoke_sanity() { let (bank, noop_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, program.3, @@ -1358,18 +1202,7 @@ fn test_program_sbf_program_id_spoofing() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -1382,11 +1215,7 @@ fn test_program_sbf_program_id_spoofing() { let (bank, malicious_system_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_spoof1_system", @@ -1427,18 +1256,7 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -1451,11 +1269,7 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { let (_bank, caller2_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_caller_access", @@ -1484,28 +1298,13 @@ fn test_program_sbf_ro_modify() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_modify", @@ -1556,19 +1355,6 @@ fn test_program_sbf_call_depth() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); - let (_, program_id) = load_program_and_advance_slot( - &mut bank_client, - &bpf_loader::id(), -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); @@ -1576,7 +1362,6 @@ fn test_program_sbf_call_depth() { let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_call_depth", @@ -1607,19 +1392,6 @@ fn test_program_sbf_compute_budget() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); - let (_, program_id) = load_program_and_advance_slot( - &mut bank_client, - &bpf_loader::id(), -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); @@ -1627,7 +1399,6 @@ fn test_program_sbf_compute_budget() { let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -1752,28 +1523,13 @@ fn test_program_sbf_instruction_introspection() { .. } = create_genesis_config(50_000); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_instruction_introspection", @@ -2525,19 +2281,6 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); - let invoke_and_return = load_program( - &bank_client, - &bpf_loader::id(), -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); @@ -2545,7 +2288,6 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( &mut bank_client, bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -2675,10 +2417,6 @@ fn test_program_sbf_disguised_as_sbf_loader() { bank.deactivate_feature( &solana_sdk::feature_set::remove_bpf_loader_incorrect_program_id::id(), ); -<<<<<<< HEAD - bank.deactivate_feature(&feature_set::disable_bpf_loader_instructions::id()); - let bank_client = BankClient::new(bank); -======= let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); @@ -2690,7 +2428,6 @@ fn test_program_sbf_disguised_as_sbf_loader() { &authority_keypair, program, ); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let account_metas = vec![AccountMeta::new_readonly(program_id, false)]; let instruction = Instruction::new_with_bytes(bpf_loader::id(), &[1], account_metas); @@ -2713,28 +2450,13 @@ fn test_program_reads_from_program_account() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "read_program", @@ -2757,28 +2479,12 @@ fn test_program_sbf_c_dup() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let account_address = Pubkey::new_unique(); let account = AccountSharedData::new_data(42, &[1_u8, 2, 3], &system_program::id()).unwrap(); bank.store_account(&account_address, &account); -<<<<<<< HEAD - let mut bank_client = BankClient::new(bank); - - let (_, program_id) = - load_program_and_advance_slot(&mut bank_client, &bpf_loader::id(), &mint_keypair, "ser"); -======= let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); let (_, program_id) = load_upgradeable_program_and_advance_slot( @@ -2788,7 +2494,6 @@ fn test_program_sbf_c_dup() { &authority_keypair, "ser", ); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let account_metas = vec![ AccountMeta::new_readonly(account_address, false), AccountMeta::new_readonly(account_address, false), @@ -2810,19 +2515,6 @@ fn test_program_sbf_upgrade_via_cpi() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); - let invoke_and_return = load_program( - &bank_client, - &bpf_loader::id(), -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); @@ -2830,7 +2522,6 @@ fn test_program_sbf_upgrade_via_cpi() { let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( &mut bank_client, bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -2938,20 +2629,9 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) // Deploy CPI invoker program let invoke_and_return = load_upgradeable_program_wrapper( @@ -3218,28 +2898,13 @@ fn test_program_sbf_ro_account_modify() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_account_modify", @@ -3297,15 +2962,6 @@ fn test_program_sbf_realloc() { .. } = create_genesis_config(1_000_000_000_000); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mint_pubkey = mint_keypair.pubkey(); let signer = &[&mint_keypair]; for direct_mapping in [false, true] { @@ -3322,11 +2978,7 @@ fn test_program_sbf_realloc() { let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -3647,15 +3299,6 @@ fn test_program_sbf_realloc_invoke() { } = create_genesis_config(1_000_000_000_000); genesis_config.rent = Rent::default(); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mint_pubkey = mint_keypair.pubkey(); let signer = &[&mint_keypair]; @@ -3673,11 +3316,7 @@ fn test_program_sbf_realloc_invoke() { let (bank, realloc_invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc_invoke", @@ -4182,18 +3821,7 @@ fn test_program_sbf_processed_inner_instruction() { .. } = create_genesis_config(50); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); -======= let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -4217,11 +3845,7 @@ fn test_program_sbf_processed_inner_instruction() { ); let (_, invoke_and_return_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -4275,35 +3899,18 @@ fn test_program_fees() { .. } = create_genesis_config(500_000_000); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) genesis_config.fee_rate_governor = FeeRateGovernor::new(congestion_multiplier, 0); let mut bank = Bank::new_for_tests(&genesis_config); let fee_structure = FeeStructure::new(0.000005, 0.0, vec![(200, 0.0000005), (1400000, 0.000005)]); bank.fee_structure = fee_structure.clone(); -<<<<<<< HEAD - let mut bank_client = BankClient::new(bank); -======= let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -4374,15 +3981,6 @@ fn test_get_minimum_delegation() { .. } = create_genesis_config(100_123_456_789); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); @@ -4390,11 +3988,7 @@ fn test_get_minimum_delegation() { let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_get_minimum_delegation", @@ -4460,13 +4054,6 @@ fn test_cpi_account_ownership_writability() { if !direct_mapping { feature_set.deactivate(&feature_set::bpf_account_data_direct_mapping::id()); } -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - feature_set.deactivate(&feature_set::disable_bpf_loader_instructions::id()); -======= - ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) bank.feature_set = Arc::new(feature_set); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); @@ -4488,11 +4075,7 @@ fn test_cpi_account_ownership_writability() { let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4654,12 +4237,6 @@ fn test_cpi_account_data_updates() { if !direct_mapping { feature_set.deactivate(&feature_set::bpf_account_data_direct_mapping::id()); } -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - feature_set.deactivate(&feature_set::disable_bpf_loader_instructions::id()); -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) bank.feature_set = Arc::new(feature_set); let bank = Arc::new(bank); @@ -4675,11 +4252,7 @@ fn test_cpi_account_data_updates() { let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4815,13 +4388,6 @@ fn test_cpi_deprecated_loader_realloc() { feature_set.deactivate(&feature_set::bpf_account_data_direct_mapping::id()); } -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - feature_set.deactivate(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) bank.feature_set = Arc::new(feature_set); let bank = Arc::new(bank); @@ -4836,11 +4402,7 @@ fn test_cpi_deprecated_loader_realloc() { let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4936,15 +4498,6 @@ fn test_cpi_change_account_data_memory_allocation() { .. } = create_genesis_config(100_123_456_789); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let mut bank = Bank::new_for_tests(&genesis_config); declare_process_instruction!(MockBuiltin, 42, |invoke_context| { @@ -4993,11 +4546,7 @@ fn test_cpi_change_account_data_memory_allocation() { let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -5035,15 +4584,6 @@ fn test_cpi_invalid_account_info_pointers() { .. } = create_genesis_config(100_123_456_789); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank); @@ -5054,11 +4594,7 @@ fn test_cpi_invalid_account_info_pointers() { let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -5111,15 +4647,6 @@ fn test_deny_executable_write() { .. } = create_genesis_config(100_123_456_789); -<<<<<<< HEAD - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - -======= ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) for direct_mapping in [false, true] { let mut bank = Bank::new_for_tests(&genesis_config); let feature_set = Arc::make_mut(&mut bank.feature_set); @@ -5134,11 +4661,7 @@ fn test_deny_executable_write() { let (_bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, -<<<<<<< HEAD - &bpf_loader::id(), -======= bank_forks.as_ref(), ->>>>>>> 8869d0c8a0 (Upgrade sbf tests to use bpf loader v3 (#34691)) &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", From b3603cb2c6f25d3cfa6f4650e278b368cc68c371 Mon Sep 17 00:00:00 2001 From: haoran Date: Fri, 9 Feb 2024 13:21:56 -0600 Subject: [PATCH 3/5] update tests to avoid using the new test api from 1.18 --- programs/sbf/tests/programs.rs | 286 ++++++--------------------------- 1 file changed, 45 insertions(+), 241 deletions(-) diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index b870af2580ce97..8da4cdc18f4310 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -25,9 +25,8 @@ use { solana_runtime::{ bank::TransactionBalancesSet, loader_utils::{ - create_program, load_and_finalize_program, load_program, load_program_from_file, - load_upgradeable_buffer, load_upgradeable_program, set_upgrade_authority, - upgrade_program, + create_program, load_program_from_file, load_upgradeable_buffer, + load_upgradeable_program, set_upgrade_authority, upgrade_program, }, }, solana_sbf_rust_invoke::instructions::*, @@ -42,12 +41,11 @@ use { entrypoint::MAX_PERMITTED_DATA_INCREASE, feature_set::{self, remove_deprecated_request_unit_ix, FeatureSet}, fee::FeeStructure, - loader_instruction, message::{v0::LoadedAddresses, SanitizedMessage}, signature::keypair_from_seed, stake, system_instruction::{self, MAX_PERMITTED_DATA_LENGTH}, - sysvar::{self, clock, rent}, + sysvar::{self, clock}, transaction::VersionedTransaction, }, solana_transaction_status::{ @@ -253,21 +251,6 @@ fn execute_transactions( .collect() } -fn load_program_and_advance_slot( - bank_client: &mut BankClient, - loader_id: &Pubkey, - payer_keypair: &Keypair, - name: &str, -) -> (Arc, Pubkey) { - let pubkey = load_program(bank_client, loader_id, payer_keypair, name); - ( - bank_client - .advance_slot(1, &Pubkey::default()) - .expect("Failed to advance the slot"), - pubkey, - ) -} - fn load_upgradeable_program_wrapper( bank_client: &BankClient, mint_keypair: &Keypair, @@ -289,7 +272,6 @@ fn load_upgradeable_program_wrapper( fn load_upgradeable_program_and_advance_slot( bank_client: &mut BankClient, - bank_forks: &RwLock, mint_keypair: &Keypair, authority_keypair: &Keypair, name: &str, @@ -300,11 +282,11 @@ fn load_upgradeable_program_and_advance_slot( // load_upgradeable_program sets clock sysvar to 1, which causes the program to be effective // after 2 slots. They need to be called individually to create the correct fork graph in between. bank_client - .advance_slot(1, bank_forks, &Pubkey::default()) + .advance_slot(1, &Pubkey::default()) .expect("Failed to advance the slot"); let bank = bank_client - .advance_slot(1, bank_forks, &Pubkey::default()) + .advance_slot(1, &Pubkey::default()) .expect("Failed to advance the slot"); (bank, program_id) @@ -374,19 +356,17 @@ fn test_program_sbf_sanity() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); // Call user program let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, program.0, ); - let account_metas = vec![ AccountMeta::new(mint_keypair.pubkey(), true), AccountMeta::new(Keypair::new().pubkey(), false), @@ -456,7 +436,8 @@ fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -475,7 +456,6 @@ fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { // fails. let (_bank, _program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_deprecated_loader", @@ -506,13 +486,12 @@ fn test_program_sbf_duplicate_accounts() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, program, @@ -613,18 +592,15 @@ fn test_program_sbf_error_handling() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, program, ); - let account_metas = vec![AccountMeta::new(mint_keypair.pubkey(), true)]; let instruction = Instruction::new_with_bytes(program_id, &[1], account_metas.clone()); @@ -723,13 +699,13 @@ fn test_return_data_and_log_data_syscall() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, program, @@ -793,7 +769,8 @@ fn test_program_sbf_invoke_sanity() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -813,7 +790,6 @@ fn test_program_sbf_invoke_sanity() { let (bank, noop_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, program.3, @@ -1202,7 +1178,8 @@ fn test_program_sbf_program_id_spoofing() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -1212,10 +1189,8 @@ fn test_program_sbf_program_id_spoofing() { &authority_keypair, "solana_sbf_rust_spoof1", ); - let (bank, malicious_system_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_spoof1_system", @@ -1256,7 +1231,8 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -1266,15 +1242,12 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { &authority_keypair, "solana_sbf_rust_caller_access", ); - let (_bank, caller2_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_caller_access", ); - let account_metas = vec![ AccountMeta::new_readonly(caller_pubkey, false), AccountMeta::new_readonly(caller2_pubkey, false), @@ -1298,13 +1271,13 @@ fn test_program_sbf_ro_modify() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_pubkey) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_modify", @@ -1355,13 +1328,11 @@ fn test_program_sbf_call_depth() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_call_depth", @@ -1392,13 +1363,11 @@ fn test_program_sbf_compute_budget() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -1523,13 +1492,13 @@ fn test_program_sbf_instruction_introspection() { .. } = create_genesis_config(50_000); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_instruction_introspection", @@ -1572,94 +1541,6 @@ fn test_program_sbf_instruction_introspection() { assert!(bank.get_account(&sysvar::instructions::id()).is_none()); } -/// This test is to test bpf_loader v2 `Finalize` instruction with different -/// programs. It is going to be deprecated once we activate -/// `disable_bpf_loader_instructions`. -#[test] -#[cfg(feature = "sbf_rust")] -fn test_program_sbf_test_use_latest_executor() { - solana_logger::setup(); - - let GenesisConfigInfo { - mut genesis_config, - mint_keypair, - .. - } = create_genesis_config(50); - - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let mut bank_client = BankClient::new(bank); - let panic_id = load_program( - &bank_client, - &bpf_loader::id(), - &mint_keypair, - "solana_sbf_rust_panic", - ); - - // Write the panic program into the program account - let (program_keypair, instruction) = load_and_finalize_program( - &bank_client, - &bpf_loader::id(), - None, - &mint_keypair, - "solana_sbf_rust_panic", - ); - - // Finalize the panic program, but fail the tx - let message = Message::new( - &[ - instruction, - Instruction::new_with_bytes(panic_id, &[0], vec![]), - ], - Some(&mint_keypair.pubkey()), - ); - - bank_client - .advance_slot(1, &Pubkey::default()) - .expect("Failed to advance the slot"); - - assert!(bank_client - .send_and_confirm_message(&[&mint_keypair, &program_keypair], message) - .is_err()); - - // Write the noop program into the same program account - let (program_keypair, instruction) = load_and_finalize_program( - &bank_client, - &bpf_loader::id(), - Some(program_keypair), - &mint_keypair, - "solana_sbf_rust_noop", - ); - bank_client - .advance_slot(1, &Pubkey::default()) - .expect("Failed to advance the slot"); - let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); - bank_client - .send_and_confirm_message(&[&mint_keypair, &program_keypair], message) - .unwrap(); - - // Call the noop program, should get noop not panic - let message = Message::new( - &[Instruction::new_with_bytes( - program_keypair.pubkey(), - &[0], - vec![], - )], - Some(&mint_keypair.pubkey()), - ); - bank_client - .advance_slot(1, &Pubkey::default()) - .expect("Failed to advance the slot"); - assert!(bank_client - .send_and_confirm_message(&[&mint_keypair], message) - .is_ok()); -} - #[test] #[cfg(feature = "sbf_rust")] fn test_program_sbf_upgrade() { @@ -2281,13 +2162,11 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -2417,18 +2296,15 @@ fn test_program_sbf_disguised_as_sbf_loader() { bank.deactivate_feature( &solana_sdk::feature_set::remove_bpf_loader_incorrect_program_id::id(), ); - let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); - let mut bank_client = BankClient::new_shared(bank); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, program, ); - let account_metas = vec![AccountMeta::new_readonly(program_id, false)]; let instruction = Instruction::new_with_bytes(bpf_loader::id(), &[1], account_metas); let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction); @@ -2450,13 +2326,12 @@ fn test_program_reads_from_program_account() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "read_program", @@ -2479,17 +2354,16 @@ fn test_program_sbf_c_dup() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); let account_address = Pubkey::new_unique(); let account = AccountSharedData::new_data(42, &[1_u8, 2, 3], &system_program::id()).unwrap(); bank.store_account(&account_address, &account); - let mut bank_client = BankClient::new_shared(bank); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); let (_, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "ser", @@ -2515,13 +2389,11 @@ fn test_program_sbf_upgrade_via_cpi() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -2629,8 +2501,8 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); - let mut bank_client = BankClient::new_shared(bank); + let bank = Bank::new_for_tests(&genesis_config); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); // Deploy CPI invoker program @@ -2830,63 +2702,6 @@ fn test_program_upgradeable_locks() { assert_eq!(results2[1], Err(TransactionError::AccountInUse)); } -/// This test is to test bpf_loader v2 `Finalize` instruction. It is going to be -/// deprecated once we activate `disable_bpf_loader_instructions`. -#[test] -#[cfg(feature = "sbf_rust")] -fn test_program_sbf_finalize() { - solana_logger::setup(); - - let GenesisConfigInfo { - mut genesis_config, - mint_keypair, - .. - } = create_genesis_config(50); - - // deactivate `disable_bpf_loader_instructions` feature so that the program - // can be loaded, finalized and tested. - genesis_config - .accounts - .remove(&feature_set::disable_bpf_loader_instructions::id()); - - let bank = Bank::new_for_tests(&genesis_config); - let bank = Arc::new(bank); - let mut bank_client = BankClient::new_shared(bank.clone()); - - let (_, program_pubkey) = load_program_and_advance_slot( - &mut bank_client, - &bpf_loader::id(), - &mint_keypair, - "solana_sbf_rust_finalize", - ); - - // Write the noop program into the same program account - let (program_keypair, _instruction) = load_and_finalize_program( - &bank_client, - &bpf_loader::id(), - None, - &mint_keypair, - "solana_sbf_rust_noop", - ); - - bank_client - .advance_slot(1, &Pubkey::default()) - .expect("Failed to advance the slot"); - - let account_metas = vec![ - AccountMeta::new(program_keypair.pubkey(), true), - AccountMeta::new_readonly(bpf_loader::id(), false), - AccountMeta::new(rent::id(), false), - ]; - let instruction = Instruction::new_with_bytes(program_pubkey, &[], account_metas.clone()); - let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); - let result = bank_client.send_and_confirm_message(&[&mint_keypair, &program_keypair], message); - assert_eq!( - result.unwrap_err().unwrap(), - TransactionError::InstructionError(0, InstructionError::ProgramFailedToComplete) - ); -} - #[test] #[cfg(feature = "sbf_rust")] fn test_program_sbf_ro_account_modify() { @@ -2898,13 +2713,13 @@ fn test_program_sbf_ro_account_modify() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_account_modify", @@ -2978,7 +2793,6 @@ fn test_program_sbf_realloc() { let (bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -3316,7 +3130,6 @@ fn test_program_sbf_realloc_invoke() { let (bank, realloc_invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc_invoke", @@ -3821,7 +3634,8 @@ fn test_program_sbf_processed_inner_instruction() { .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); + let bank = Bank::new_for_tests(&genesis_config); + let bank = Arc::new(bank); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); @@ -3845,7 +3659,6 @@ fn test_program_sbf_processed_inner_instruction() { ); let (_, invoke_and_return_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -3904,13 +3717,11 @@ fn test_program_fees() { let fee_structure = FeeStructure::new(0.000005, 0.0, vec![(200, 0.0000005), (1400000, 0.000005)]); bank.fee_structure = fee_structure.clone(); - let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); - let mut bank_client = BankClient::new_shared(bank); + let mut bank_client = BankClient::new(bank); let authority_keypair = Keypair::new(); let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -3988,7 +3799,6 @@ fn test_get_minimum_delegation() { let (_bank, program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_get_minimum_delegation", @@ -4075,7 +3885,6 @@ fn test_cpi_account_ownership_writability() { let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4252,7 +4061,6 @@ fn test_cpi_account_data_updates() { let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4402,7 +4210,6 @@ fn test_cpi_deprecated_loader_realloc() { let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4546,7 +4353,6 @@ fn test_cpi_change_account_data_memory_allocation() { let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4594,7 +4400,6 @@ fn test_cpi_invalid_account_info_pointers() { let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4661,7 +4466,6 @@ fn test_deny_executable_write() { let (_bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( &mut bank_client, - bank_forks.as_ref(), &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", From d44ee2bb828b9fbaba97a9d6e5d97b51b66a9015 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Sat, 10 Feb 2024 03:09:25 +0000 Subject: [PATCH 4/5] manually backport #34722 to fix a test --- runtime/src/loader_utils.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/src/loader_utils.rs b/runtime/src/loader_utils.rs index cddb37595cef91..7f4650ae561d3f 100644 --- a/runtime/src/loader_utils.rs +++ b/runtime/src/loader_utils.rs @@ -116,6 +116,7 @@ pub fn load_upgradeable_buffer( let program = load_program_from_file(name); let buffer_pubkey = buffer_keypair.pubkey(); let buffer_authority_pubkey = buffer_authority_keypair.pubkey(); + let program_buffer_bytes = UpgradeableLoaderState::size_of_buffer(program.len()); bank_client .send_and_confirm_message( @@ -127,7 +128,7 @@ pub fn load_upgradeable_buffer( &buffer_authority_pubkey, 1.max( bank_client - .get_minimum_balance_for_rent_exemption(program.len()) + .get_minimum_balance_for_rent_exemption(program_buffer_bytes) .unwrap(), ), program.len(), From f470254f31c5aa21b35746d80c2503e1913161c0 Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Sat, 10 Feb 2024 16:25:52 +0100 Subject: [PATCH 5/5] Ignore failing benchmark tests and fix compilation --- programs/sbf/benches/bpf_loader.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/programs/sbf/benches/bpf_loader.rs b/programs/sbf/benches/bpf_loader.rs index 8fb1ec74ba40c0..bec2106708aad9 100644 --- a/programs/sbf/benches/bpf_loader.rs +++ b/programs/sbf/benches/bpf_loader.rs @@ -101,6 +101,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) { } #[bench] +#[ignore] fn bench_program_alu(bencher: &mut Bencher) { let ns_per_s = 1000000000; let one_million = 1000000; @@ -118,13 +119,18 @@ fn bench_program_alu(bencher: &mut Bencher) { true, false, ); + #[allow(unused_mut)] let mut executable = Executable::::from_elf(&elf, Arc::new(program_runtime_environment.unwrap())) .unwrap(); executable.verify::().unwrap(); - executable.jit_compile().unwrap(); + #[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))] + { + executable.jit_compile().unwrap(); + } + create_vm!( vm, &executable, @@ -181,6 +187,7 @@ fn bench_program_alu(bencher: &mut Bencher) { } #[bench] +#[ignore] fn bench_program_execute_noop(bencher: &mut Bencher) { let GenesisConfigInfo { mut genesis_config,