From d7d6783e5ff3312cbfc4d3bb2b7cc4e253bb1d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 5 Nov 2024 17:29:19 +0000 Subject: [PATCH] Adjusts tests. --- cli/tests/program.rs | 163 +++++++-- log-collector/src/lib.rs | 6 +- programs/sbf/benches/bpf_loader.rs | 6 +- programs/sbf/tests/programs.rs | 561 +++++++++++++---------------- programs/sbf/tests/simulation.rs | 4 +- programs/sbf/tests/sysvar.rs | 4 +- runtime/src/bank/tests.rs | 13 +- 7 files changed, 402 insertions(+), 355 deletions(-) diff --git a/cli/tests/program.rs b/cli/tests/program.rs index f1c441a8654ea4..5a6431e08a7e34 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -12,7 +12,7 @@ use { }, solana_cli_output::{parse_sign_only_reply_string, OutputFormat}, solana_faucet::faucet::run_local_faucet, - solana_feature_set::enable_alt_bn128_syscall, + solana_feature_set::{enable_alt_bn128_syscall, enable_loader_v4}, solana_rpc::rpc::JsonRpcConfig, solana_rpc_client::rpc_client::{GetConfirmedSignaturesForAddress2Config, RpcClient}, solana_rpc_client_api::config::RpcTransactionConfig, @@ -32,7 +32,7 @@ use { transaction::Transaction, }, solana_streamer::socket::SocketAddrSpace, - solana_test_validator::{TestValidator, TestValidatorGenesis}, + solana_test_validator::TestValidatorGenesis, solana_transaction_status::UiTransactionEncoding, std::{ env, @@ -81,8 +81,17 @@ fn test_cli_program_deploy_non_upgradeable() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -286,8 +295,17 @@ fn test_cli_program_deploy_no_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -403,6 +421,7 @@ fn test_cli_program_deploy_feature(enable_feature: bool) { test_validator_builder.deactivate_features(&[enable_alt_bn128_syscall::id()]); } + test_validator_builder = test_validator_builder.deactivate_features(&[enable_loader_v4::id()]); let test_validator = test_validator_builder .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) .expect("validator start failed"); @@ -530,6 +549,7 @@ fn test_cli_program_upgrade_with_feature(enable_feature: bool) { test_validator_builder.deactivate_features(&[enable_alt_bn128_syscall::id()]); } + test_validator_builder = test_validator_builder.deactivate_features(&[enable_loader_v4::id()]); let test_validator = test_validator_builder .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) .expect("validator start failed"); @@ -678,8 +698,17 @@ fn test_cli_program_deploy_with_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1079,8 +1108,17 @@ fn test_cli_program_upgrade_auto_extend() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1232,8 +1270,17 @@ fn test_cli_program_close_program() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1351,8 +1398,17 @@ fn test_cli_program_extend_program() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1521,8 +1577,17 @@ fn test_cli_program_write_buffer() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2008,8 +2073,17 @@ fn test_cli_program_set_buffer_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2180,8 +2254,17 @@ fn test_cli_program_mismatch_buffer_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2306,8 +2389,17 @@ fn test_cli_program_deploy_with_offline_signing(use_offline_signer_as_fee_payer: let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2499,8 +2591,17 @@ fn test_cli_program_show() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2696,8 +2797,17 @@ fn test_cli_program_dump() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2835,6 +2945,7 @@ fn test_cli_program_deploy_with_args(compute_unit_price: Option, use_rpc: b exemption_threshold: 1.0, ..Rent::default() }) + .deactivate_features(&[enable_loader_v4::id()]) .rpc_config(JsonRpcConfig { enable_rpc_transaction_history: true, faucet_addr: Some(faucet_addr), diff --git a/log-collector/src/lib.rs b/log-collector/src/lib.rs index 612300f8e94bfc..60d3cb5b6fde93 100644 --- a/log-collector/src/lib.rs +++ b/log-collector/src/lib.rs @@ -64,8 +64,7 @@ impl LogCollector { #[macro_export] macro_rules! ic_logger_msg { ($log_collector:expr, $message:expr) => { - $crate::log::debug!( - target: "solana_runtime::message_processor::stable_log", + println!( "{}", $message ); @@ -76,8 +75,7 @@ macro_rules! ic_logger_msg { } }; ($log_collector:expr, $fmt:expr, $($arg:tt)*) => { - $crate::log::debug!( - target: "solana_runtime::message_processor::stable_log", + println!( $fmt, $($arg)* ); diff --git a/programs/sbf/benches/bpf_loader.rs b/programs/sbf/benches/bpf_loader.rs index 7475e9ea2d0f53..d2c98719c0f6b6 100644 --- a/programs/sbf/benches/bpf_loader.rs +++ b/programs/sbf/benches/bpf_loader.rs @@ -32,7 +32,7 @@ use { bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, - loader_utils::{load_program_from_file, load_upgradeable_program_and_advance_slot}, + loader_utils::{load_program_from_file, load_program_of_loader_v4}, }, solana_sdk::{ account::AccountSharedData, @@ -201,9 +201,9 @@ fn bench_program_execute_noop(bencher: &mut Bencher) { let authority_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); - let (_, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "noop", diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 991d7a8695444c..19adbc93439bf7 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -28,9 +28,9 @@ use { create_genesis_config_with_leader_ex, GenesisConfigInfo, }, loader_utils::{ - create_program, load_program_from_file, load_upgradeable_buffer, - load_upgradeable_program, load_upgradeable_program_and_advance_slot, - load_upgradeable_program_wrapper, set_upgrade_authority, upgrade_program, + create_program, instructions_to_load_program_of_loader_v4, load_program_from_file, + load_program_of_loader_v4, load_upgradeable_buffer, load_upgradeable_program, + set_upgrade_authority, upgrade_program, }, }, solana_runtime_transaction::{ @@ -53,6 +53,7 @@ use { genesis_config::ClusterType, hash::Hash, instruction::{AccountMeta, Instruction, InstructionError}, + loader_v4, message::{v0::LoadedAddresses, Message, SanitizedMessage}, pubkey::Pubkey, rent::Rent, @@ -290,9 +291,9 @@ fn test_program_sbf_sanity() { let authority_keypair = Keypair::new(); // Call user program - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program.0, @@ -356,7 +357,7 @@ fn test_program_sbf_loader_deprecated() { #[test] #[cfg(feature = "sbf_rust")] #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: TransactionError(InstructionError(1, InvalidAccountData))" + expected = "called `Result::unwrap()` on an `Err` value: TransactionError(InstructionError(0, InvalidAccountData))" )] fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { solana_logger::setup(); @@ -384,9 +385,9 @@ fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { // 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( + let (_bank, _program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_deprecated_loader", @@ -421,9 +422,9 @@ fn test_program_sbf_duplicate_accounts() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -528,9 +529,9 @@ fn test_program_sbf_error_handling() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -638,9 +639,9 @@ fn test_return_data_and_log_data_syscall() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -707,23 +708,23 @@ fn test_program_sbf_invoke_sanity() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let invoke_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, program.1, ); - - let invoked_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoked_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, program.2, ); - - let (bank, noop_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, noop_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program.3, @@ -1128,16 +1129,16 @@ fn test_program_sbf_program_id_spoofing() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let malicious_swap_pubkey = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, malicious_swap_pubkey) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_spoof1", ); - - let (bank, malicious_system_pubkey) = load_upgradeable_program_and_advance_slot( + let (bank, malicious_system_pubkey) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_spoof1_system", @@ -1182,16 +1183,16 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let caller_pubkey = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, caller_pubkey) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_caller_access", ); - - let (_bank, caller2_pubkey) = load_upgradeable_program_and_advance_slot( + let (_bank, caller2_pubkey) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_caller_access", @@ -1224,9 +1225,9 @@ fn test_program_sbf_ro_modify() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_pubkey) = load_upgradeable_program_and_advance_slot( + let (bank, program_pubkey) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_modify", @@ -1281,9 +1282,9 @@ fn test_program_sbf_call_depth() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_call_depth", @@ -1318,9 +1319,9 @@ fn test_program_sbf_compute_budget() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -1449,9 +1450,9 @@ fn test_program_sbf_instruction_introspection() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_instruction_introspection", @@ -1508,21 +1509,14 @@ fn test_program_sbf_upgrade() { let mut bank_client = BankClient::new_shared(bank); // Deploy upgrade 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( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance the slot"); let mut instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); @@ -1639,10 +1633,13 @@ fn test_program_sbf_invoke_stable_genesis_and_bank() { solana_logger::setup(); let GenesisConfigInfo { - genesis_config, + mut genesis_config, mint_keypair, .. } = get_stable_genesis_config(); + genesis_config + .accounts + .remove(&feature_set::enable_loader_v4::id()); let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let bank_client = BankClient::new_shared(bank.clone()); @@ -1821,26 +1818,46 @@ fn test_program_sbf_invoke_in_same_tx_as_deployment() { let mut bank_client = BankClient::new_shared(bank.clone()); // Deploy upgradeable program - let buffer_keypair = Keypair::new(); - let program_keypair = Keypair::new(); - let program_id = program_keypair.pubkey(); let authority_keypair = Keypair::new(); + let (program_keypair, mut deployment_instructions) = instructions_to_load_program_of_loader_v4( + &bank_client, + &mint_keypair, + &authority_keypair, + "solana_sbf_rust_noop", + None, + None, + ); + let program_id = program_keypair.pubkey(); + let deployment_instruction = deployment_instructions.pop().unwrap(); + let signers: &[&[&Keypair]] = &[ + &[&mint_keypair, &program_keypair], + &[&mint_keypair, &program_keypair, &authority_keypair], + &[&mint_keypair, &authority_keypair], + ]; + let signers = std::iter::once(signers[0]) + .chain(std::iter::once(signers[1])) + .chain(std::iter::repeat(signers[2])); + for (instruction, signers) in deployment_instructions.into_iter().zip(signers) { + let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); + bank_client + .send_and_confirm_message(signers, message) + .unwrap(); + } // Deploy indirect invocation program - let indirect_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (bank, indirect_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &indirect_program_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); + // Prepare invocations let invoke_instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); let indirect_invoke_instruction = Instruction::new_with_bytes( - indirect_program_keypair.pubkey(), + indirect_program_id, &[0], vec![ AccountMeta::new_readonly(program_id, false), @@ -1848,57 +1865,29 @@ fn test_program_sbf_invoke_in_same_tx_as_deployment() { ], ); - // Prepare deployment - let program = load_upgradeable_buffer( - &bank_client, - &mint_keypair, - &buffer_keypair, - &authority_keypair, - "solana_sbf_rust_noop", - ); - let deployment_instructions = bpf_loader_upgradeable::deploy_with_max_program_len( - &mint_keypair.pubkey(), - &program_keypair.pubkey(), - &buffer_keypair.pubkey(), - &authority_keypair.pubkey(), - 1.max( - bank_client - .get_minimum_balance_for_rent_exemption( - bpf_loader_upgradeable::UpgradeableLoaderState::size_of_program(), - ) - .unwrap(), - ), - program.len() * 2, - ) - .unwrap(); - - let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance slot"); - // Deployment is invisible to both top-level-instructions and CPI instructions for (index, invoke_instruction) in [invoke_instruction, indirect_invoke_instruction] .into_iter() .enumerate() { - let mut instructions = deployment_instructions.clone(); - instructions.push(invoke_instruction); let tx = Transaction::new( - &[&mint_keypair, &program_keypair, &authority_keypair], - Message::new(&instructions, Some(&mint_keypair.pubkey())), + &[&mint_keypair, &authority_keypair], + Message::new( + &[deployment_instruction.clone(), invoke_instruction], + Some(&mint_keypair.pubkey()), + ), bank.last_blockhash(), ); + let (result, _, _) = process_transaction_and_record_inner(&bank, tx); if index == 0 { - let result = load_execute_and_commit_transaction(&bank, tx); assert_eq!( - result.unwrap().status, - Err(TransactionError::ProgramAccountNotFound), + result.unwrap_err(), + TransactionError::ProgramAccountNotFound, ); } else { - let (result, _, _) = process_transaction_and_record_inner(&bank, tx); assert_eq!( result.unwrap_err(), - TransactionError::InstructionError(2, InstructionError::UnsupportedProgramId), + TransactionError::InstructionError(1, InstructionError::UnsupportedProgramId), ); } } @@ -1918,45 +1907,54 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { let mut bank_client = BankClient::new_shared(bank.clone()); // 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( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_noop", ); + let (source_program_keypair, mut deployment_instructions) = + instructions_to_load_program_of_loader_v4( + &bank_client, + &mint_keypair, + &authority_keypair, + "solana_sbf_rust_panic", + None, + Some(&program_id), + ); + let undeployment_instruction = loader_v4::retract(&program_id, &authority_keypair.pubkey()); + let deployment_instruction = deployment_instructions.pop().unwrap(); + let signers: &[&[&Keypair]] = &[ + &[&mint_keypair, &source_program_keypair], + &[&mint_keypair, &source_program_keypair, &authority_keypair], + &[&mint_keypair, &authority_keypair], + ]; + let signers = std::iter::once(signers[0]) + .chain(std::iter::once(signers[1])) + .chain(std::iter::repeat(signers[2])); + for (instruction, signers) in deployment_instructions.into_iter().zip(signers) { + let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); + bank_client + .send_and_confirm_message(signers, message) + .unwrap(); + } // Deploy indirect invocation program - let indirect_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (bank, indirect_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &indirect_program_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); - // Deploy panic program - let panic_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, - &mint_keypair, - &buffer_keypair, - &panic_program_keypair, - &authority_keypair, - "solana_sbf_rust_panic", - ); - + // Prepare invocations let invoke_instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); let indirect_invoke_instruction = Instruction::new_with_bytes( - indirect_program_keypair.pubkey(), + indirect_program_id, &[0], vec![ AccountMeta::new_readonly(program_id, false), @@ -1964,31 +1962,6 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { ], ); - // 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.as_ref(), &Pubkey::default()) - .unwrap(); - let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .unwrap(); - - // Prepare redeployment - let buffer_keypair = Keypair::new(); - load_upgradeable_buffer( - &bank_client, - &mint_keypair, - &buffer_keypair, - &authority_keypair, - "solana_sbf_rust_panic", - ); - let redeployment_instruction = bpf_loader_upgradeable::upgrade( - &program_id, - &buffer_keypair.pubkey(), - &authority_keypair.pubkey(), - &mint_keypair.pubkey(), - ); - // Redeployment causes programs to be unavailable to both top-level-instructions and CPI instructions for invoke_instruction in [invoke_instruction, indirect_invoke_instruction] { // Call upgradeable program @@ -1998,7 +1971,11 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { // Upgrade the program and invoke in same tx let message = Message::new( - &[redeployment_instruction.clone(), invoke_instruction], + &[ + undeployment_instruction.clone(), + deployment_instruction.clone(), + invoke_instruction, + ], Some(&mint_keypair.pubkey()), ); let tx = Transaction::new( @@ -2009,7 +1986,7 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { let (result, _, _) = process_transaction_and_record_inner(&bank, tx); assert_eq!( result.unwrap_err(), - TransactionError::InstructionError(1, InstructionError::UnsupportedProgramId), + TransactionError::InstructionError(2, InstructionError::UnsupportedProgramId), ); } } @@ -2028,34 +2005,29 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() { let mut bank_client = BankClient::new_shared(bank.clone()); // 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( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_noop", ); // Deploy indirect invocation program - let indirect_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (bank, indirect_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &indirect_program_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); + // Prepare invocations let invoke_instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); let indirect_invoke_instruction = Instruction::new_with_bytes( - indirect_program_keypair.pubkey(), + indirect_program_id, &[0], vec![ AccountMeta::new_readonly(program_id, false), @@ -2063,26 +2035,8 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() { ], ); - // 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.as_ref(), &Pubkey::default()) - .unwrap(); - let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .unwrap(); - // Prepare undeployment - let (programdata_address, _) = Pubkey::find_program_address( - &[program_keypair.pubkey().as_ref()], - &bpf_loader_upgradeable::id(), - ); - let undeployment_instruction = bpf_loader_upgradeable::close_any( - &programdata_address, - &mint_keypair.pubkey(), - Some(&authority_keypair.pubkey()), - Some(&program_id), - ); + let undeployment_instruction = loader_v4::retract(&program_id, &authority_keypair.pubkey()); // Undeployment is visible to both top-level-instructions and CPI instructions for invoke_instruction in [invoke_instruction, indirect_invoke_instruction] { @@ -2124,29 +2078,22 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_and_return) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // Deploy upgradeable program - let program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_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, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance slot"); let mut instruction = Instruction::new_with_bytes( invoke_and_return, @@ -2252,9 +2199,9 @@ fn test_program_sbf_disguised_as_sbf_loader() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -2285,9 +2232,9 @@ fn test_program_reads_from_program_account() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "read_program", @@ -2318,9 +2265,9 @@ fn test_program_sbf_c_dup() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "ser", @@ -2350,30 +2297,23 @@ fn test_program_sbf_upgrade_via_cpi() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_and_return) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &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( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance the slot"); let program_account = bank_client.get_account(&program_id).unwrap().unwrap(); let Ok(bpf_loader_upgradeable::UpgradeableLoaderState::Program { programdata_address, @@ -2459,31 +2399,28 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { mint_keypair, .. } = 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 authority_keypair = Keypair::new(); // Deploy CPI invoker program - let invoke_and_return = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_and_return) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // Deploy upgradeable program - let program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance the slot"); - // Set program upgrade authority instruction to invoke via CPI let new_upgrade_authority_key = Keypair::new().pubkey(); let mut set_upgrade_authority_instruction = bpf_loader_upgradeable::set_upgrade_authority( @@ -2537,12 +2474,13 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { #[cfg(feature = "sbf_rust")] fn test_program_upgradeable_locks() { fn setup_program_upgradeable_locks( - payer_keypair: &Keypair, - buffer_keypair: &Keypair, - program_keypair: &Keypair, ) -> (Arc, Arc>, Transaction, Transaction) { solana_logger::setup(); + let payer_keypair = keypair_from_seed(&[56u8; 32]).unwrap(); + let buffer_keypair = keypair_from_seed(&[11; 32]).unwrap(); + let program_keypair = keypair_from_seed(&[77u8; 32]).unwrap(); + let GenesisConfigInfo { genesis_config, mint_keypair, @@ -2551,26 +2489,30 @@ fn test_program_upgradeable_locks() { let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank.clone()); - load_upgradeable_program( + let (program_keypair, instructions) = instructions_to_load_program_of_loader_v4( &bank_client, - &mint_keypair, - buffer_keypair, - program_keypair, - payer_keypair, - "solana_sbf_rust_panic", - ); - - // Load the buffer account - load_upgradeable_buffer( - &bank_client, - &mint_keypair, - buffer_keypair, &payer_keypair, - "solana_sbf_rust_noop", + &payer_keypair, + "solana_sbf_rust_panic", + Some(program_keypair), + None, ); - + let signers: &[&[&Keypair]] = &[ + &[&payer_keypair, &program_keypair], + &[&payer_keypair, &program_keypair], + &[&payer_keypair], + ]; + let signers = std::iter::once(signers[0]) + .chain(std::iter::once(signers[1])) + .chain(std::iter::repeat(signers[2])); + for (instruction, signers) in instructions.into_iter().zip(signers) { + let message = Message::new(&[instruction], Some(&payer_keypair.pubkey())); + bank_client + .send_and_confirm_message(signers, message) + .unwrap(); + } let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) + .advance_slot(1, &bank_forks, &Pubkey::default()) .expect("Failed to advance the slot"); bank_client @@ -2585,7 +2527,7 @@ fn test_program_upgradeable_locks() { .unwrap(); let invoke_tx = Transaction::new( - &[payer_keypair], + &[&payer_keypair], Message::new( &[Instruction::new_with_bytes( program_keypair.pubkey(), @@ -2597,7 +2539,7 @@ fn test_program_upgradeable_locks() { bank.last_blockhash(), ); let upgrade_tx = Transaction::new( - &[payer_keypair], + &[&payer_keypair], Message::new( &[bpf_loader_upgradeable::upgrade( &program_keypair.pubkey(), @@ -2613,19 +2555,13 @@ fn test_program_upgradeable_locks() { (bank, bank_forks, invoke_tx, upgrade_tx) } - let payer_keypair = keypair_from_seed(&[56u8; 32]).unwrap(); - let buffer_keypair = keypair_from_seed(&[11; 32]).unwrap(); - let program_keypair = keypair_from_seed(&[77u8; 32]).unwrap(); - let results1 = { - let (bank, _bank_forks, invoke_tx, upgrade_tx) = - setup_program_upgradeable_locks(&payer_keypair, &buffer_keypair, &program_keypair); + let (bank, _bank_forks, invoke_tx, upgrade_tx) = setup_program_upgradeable_locks(); execute_transactions(&bank, vec![upgrade_tx, invoke_tx]) }; let results2 = { - let (bank, _bank_forks, invoke_tx, upgrade_tx) = - setup_program_upgradeable_locks(&payer_keypair, &buffer_keypair, &program_keypair); + let (bank, _bank_forks, invoke_tx, upgrade_tx) = setup_program_upgradeable_locks(); execute_transactions(&bank, vec![invoke_tx, upgrade_tx]) }; @@ -2675,9 +2611,9 @@ fn test_program_sbf_ro_account_modify() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_account_modify", @@ -2749,9 +2685,9 @@ fn test_program_sbf_realloc() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -3166,16 +3102,16 @@ fn test_program_sbf_realloc_invoke() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let realloc_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, realloc_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", ); - - let (bank, realloc_invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, realloc_invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc_invoke", @@ -3779,27 +3715,30 @@ fn test_program_sbf_processed_inner_instruction() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let sibling_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, sibling_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_sibling_instructions", ); - let sibling_inner_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, sibling_inner_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_sibling_inner_instructions", ); - let noop_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, noop_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, - "solana_sbf_rust_noop", + "noop_program_id", ); - let (_, invoke_and_return_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_and_return_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -3862,9 +3801,9 @@ fn test_program_fees() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -3949,9 +3888,9 @@ fn test_get_minimum_delegation() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_get_minimum_delegation", @@ -4024,23 +3963,23 @@ fn test_cpi_account_ownership_writability() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let invoke_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - - let invoked_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoked_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoked", ); - - let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, realloc_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4208,16 +4147,16 @@ fn test_cpi_account_data_updates() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let invoke_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - - let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, realloc_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4366,9 +4305,9 @@ 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_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4511,9 +4450,9 @@ fn test_cpi_change_account_data_memory_allocation() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4556,12 +4495,16 @@ fn test_cpi_invalid_account_info_pointers() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let c_invoke_program_id = - load_upgradeable_program_wrapper(&bank_client, &mint_keypair, &authority_keypair, "invoke"); - - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, c_invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, + &mint_keypair, + &authority_keypair, + "invoke", + ); + let (bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4626,9 +4569,9 @@ fn test_deny_executable_write() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4681,9 +4624,9 @@ fn test_update_callee_account() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4966,9 +4909,9 @@ fn test_account_info_in_account() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -5024,27 +4967,21 @@ fn test_clone_account_data() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (_, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - - let (bank, invoke_program_id2) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id2) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - assert_ne!(invoke_program_id, invoke_program_id2); - - println!("invoke_program_id:{invoke_program_id}"); - println!("invoke_program_id2:{invoke_program_id2}"); - let account_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); @@ -5159,9 +5096,9 @@ fn test_stack_heap_zeroed() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -5225,9 +5162,9 @@ fn test_function_call_args() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_call_args", diff --git a/programs/sbf/tests/simulation.rs b/programs/sbf/tests/simulation.rs index 62732531065915..e16d25eee2910f 100644 --- a/programs/sbf/tests/simulation.rs +++ b/programs/sbf/tests/simulation.rs @@ -6,7 +6,7 @@ use { bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, - loader_utils::load_upgradeable_program_and_advance_slot, + loader_utils::load_program_of_loader_v4, }, solana_runtime_transaction::runtime_transaction::RuntimeTransaction, solana_sdk::{ @@ -31,7 +31,7 @@ fn test_no_panic_banks_client() { 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(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, bank_forks.as_ref(), &mint_keypair, diff --git a/programs/sbf/tests/sysvar.rs b/programs/sbf/tests/sysvar.rs index 41a3d7016daffa..a54c89158bffc6 100644 --- a/programs/sbf/tests/sysvar.rs +++ b/programs/sbf/tests/sysvar.rs @@ -6,7 +6,7 @@ use { bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, - loader_utils::load_upgradeable_program_and_advance_slot, + loader_utils::load_program_of_loader_v4, }, solana_runtime_transaction::runtime_transaction::RuntimeTransaction, solana_sdk::{ @@ -62,7 +62,7 @@ fn test_sysvar_syscalls() { 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( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, bank_forks.as_ref(), &mint_keypair, diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 70e730affa745d..3914a1cde42295 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -7127,9 +7127,11 @@ fn test_bank_load_program() { #[test] fn test_bpf_loader_upgradeable_deploy_with_max_len() { - let (genesis_config, mint_keypair) = create_genesis_config_no_tx_fee(1_000_000_000); - let mut bank = Bank::new_for_tests(&genesis_config); - bank.feature_set = Arc::new(FeatureSet::all_enabled()); + let (mut genesis_config, mint_keypair) = create_genesis_config_no_tx_fee(1_000_000_000); + genesis_config + .accounts + .remove(&solana_feature_set::enable_loader_v4::id()); + let bank = Bank::new_for_tests(&genesis_config); let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); let mut bank_client = BankClient::new_shared(bank.clone()); @@ -13100,9 +13102,8 @@ fn test_deploy_last_epoch_slot() { let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL); genesis_config .accounts - .remove(&feature_set::disable_fees_sysvar::id()); - let mut bank = Bank::new_for_tests(&genesis_config); - bank.activate_feature(&feature_set::disable_fees_sysvar::id()); + .remove(&solana_feature_set::enable_loader_v4::id()); + let bank = Bank::new_for_tests(&genesis_config); // go to the last slot in the epoch let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests();