diff --git a/ci/test-stable.sh b/ci/test-stable.sh index 40ee0ae2c40a74..57b561120a90d4 100755 --- a/ci/test-stable.sh +++ b/ci/test-stable.sh @@ -68,6 +68,7 @@ test-stable-sbf) fi # SBF C program system tests + export SBF_OUT_DIR=target/sbf-solana-solana/release _ make -C programs/sbf/c tests _ cargo test \ --manifest-path programs/sbf/Cargo.toml \ diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 20f9e83d575a0c..748f77119a3b51 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5784,16 +5784,10 @@ dependencies = [ "solana-measure", "solana-program", "solana-program-runtime", - "solana-program-test", "solana-runtime", "solana-sbf-rust-invoke-dep", - "solana-sbf-rust-mem", "solana-sbf-rust-realloc-dep", "solana-sbf-rust-realloc-invoke-dep", - "solana-sbf-rust-remaining-compute-units", - "solana-sbf-rust-sanity", - "solana-sbf-rust-simulation", - "solana-sbf-rust-sysvar", "solana-sdk", "solana-svm", "solana-transaction-status", diff --git a/programs/sbf/Cargo.toml b/programs/sbf/Cargo.toml index 555940ef40a900..742f700bec4a14 100644 --- a/programs/sbf/Cargo.toml +++ b/programs/sbf/Cargo.toml @@ -38,21 +38,15 @@ solana-measure = { path = "../../measure", version = "=2.0.0" } solana-poseidon = { path = "../../poseidon/", version = "=2.0.0" } solana-program = { path = "../../sdk/program", version = "=2.0.0" } solana-program-runtime = { path = "../../program-runtime", version = "=2.0.0" } -solana-program-test = { path = "../../program-test", version = "=2.0.0" } solana-runtime = { path = "../../runtime", version = "=2.0.0" } solana-sbf-rust-128bit-dep = { path = "rust/128bit_dep", version = "=2.0.0" } solana-sbf-rust-invoke-dep = { path = "rust/invoke_dep", version = "=2.0.0" } solana-sbf-rust-invoked-dep = { path = "rust/invoked_dep", version = "=2.0.0" } solana-sbf-rust-many-args-dep = { path = "rust/many_args_dep", version = "=2.0.0" } -solana-sbf-rust-mem = { path = "rust/mem", version = "=2.0.0" } solana-sbf-rust-mem-dep = { path = "rust/mem_dep", version = "=2.0.0" } solana-sbf-rust-param-passing-dep = { path = "rust/param_passing_dep", version = "=2.0.0" } solana-sbf-rust-realloc-dep = { path = "rust/realloc_dep", version = "=2.0.0" } solana-sbf-rust-realloc-invoke-dep = { path = "rust/realloc_invoke_dep", version = "=2.0.0" } -solana-sbf-rust-remaining-compute-units = { path = "rust/remaining_compute_units", version = "=2.0.0" } -solana-sbf-rust-sanity = { path = "rust/sanity", version = "=2.0.0" } -solana-sbf-rust-simulation = { path = "rust/simulation", version = "=2.0.0" } -solana-sbf-rust-sysvar = { path = "rust/sysvar", version = "=2.0.0" } solana-sdk = { path = "../../sdk", version = "=2.0.0" } solana-svm = { path = "../../svm", version = "=2.0.0" } solana-transaction-status = { path = "../../transaction-status", version = "=2.0.0" } @@ -102,16 +96,10 @@ solana-logger = { workspace = true } solana-measure = { workspace = true } solana-program = { workspace = true } solana-program-runtime = { workspace = true } -solana-program-test = { workspace = true } solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } solana-sbf-rust-invoke-dep = { workspace = true } -solana-sbf-rust-mem = { workspace = true } solana-sbf-rust-realloc-dep = { workspace = true } solana-sbf-rust-realloc-invoke-dep = { workspace = true } -solana-sbf-rust-remaining-compute-units = { workspace = true } -solana-sbf-rust-sanity = { workspace = true } -solana-sbf-rust-simulation = { workspace = true } -solana-sbf-rust-sysvar = { workspace = true } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } solana-svm = { workspace = true } solana-transaction-status = { workspace = true } diff --git a/programs/sbf/build.rs b/programs/sbf/build.rs index 97f2423162aee7..bf3feb48c087bd 100644 --- a/programs/sbf/build.rs +++ b/programs/sbf/build.rs @@ -108,6 +108,7 @@ fn main() { "simulation", "spoof1", "spoof1_system", + "sysvar", "upgradeable", "upgraded", ]; diff --git a/programs/sbf/rust/mem/Cargo.toml b/programs/sbf/rust/mem/Cargo.toml index ab05428bcd0a26..9b99a551c7c8ec 100644 --- a/programs/sbf/rust/mem/Cargo.toml +++ b/programs/sbf/rust/mem/Cargo.toml @@ -13,4 +13,4 @@ solana-program = { workspace = true } solana-sbf-rust-mem-dep = { workspace = true } [lib] -crate-type = ["cdylib", "lib"] +crate-type = ["cdylib"] diff --git a/programs/sbf/rust/remaining_compute_units/Cargo.toml b/programs/sbf/rust/remaining_compute_units/Cargo.toml index 403177a8df61d6..c35ed06152b234 100644 --- a/programs/sbf/rust/remaining_compute_units/Cargo.toml +++ b/programs/sbf/rust/remaining_compute_units/Cargo.toml @@ -12,4 +12,4 @@ edition = { workspace = true } solana-program = { workspace = true } [lib] -crate-type = ["cdylib", "lib"] +crate-type = ["cdylib"] diff --git a/programs/sbf/rust/sanity/Cargo.toml b/programs/sbf/rust/sanity/Cargo.toml index 435acceddfef36..f01dd7501e6906 100644 --- a/programs/sbf/rust/sanity/Cargo.toml +++ b/programs/sbf/rust/sanity/Cargo.toml @@ -12,4 +12,4 @@ edition = { workspace = true } solana-program = { workspace = true } [lib] -crate-type = ["cdylib", "lib"] +crate-type = ["cdylib"] diff --git a/programs/sbf/rust/simulation/Cargo.toml b/programs/sbf/rust/simulation/Cargo.toml index 3114e2a1a75c8b..3fd65622c876a4 100644 --- a/programs/sbf/rust/simulation/Cargo.toml +++ b/programs/sbf/rust/simulation/Cargo.toml @@ -12,4 +12,4 @@ edition = { workspace = true } solana-program = { workspace = true } [lib] -crate-type = ["cdylib", "lib"] +crate-type = ["cdylib"] diff --git a/programs/sbf/rust/sysvar/Cargo.toml b/programs/sbf/rust/sysvar/Cargo.toml index 1144ebde960cae..bb9683fa5a63dd 100644 --- a/programs/sbf/rust/sysvar/Cargo.toml +++ b/programs/sbf/rust/sysvar/Cargo.toml @@ -12,4 +12,4 @@ edition = { workspace = true } solana-program = { workspace = true } [lib] -crate-type = ["cdylib", "lib"] +crate-type = ["cdylib"] diff --git a/programs/sbf/rust/sysvar/src/lib.rs b/programs/sbf/rust/sysvar/src/lib.rs index d460b5ca635da2..72e3563caf5364 100644 --- a/programs/sbf/rust/sysvar/src/lib.rs +++ b/programs/sbf/rust/sysvar/src/lib.rs @@ -31,7 +31,7 @@ pub fn process_instruction( sysvar::clock::id().log(); let clock = Clock::from_account_info(&accounts[2]).unwrap(); assert_ne!(clock, Clock::default()); - let got_clock = Clock::get()?; + let got_clock = Clock::get().unwrap(); assert_eq!(clock, got_clock); } @@ -41,7 +41,7 @@ pub fn process_instruction( sysvar::epoch_schedule::id().log(); let epoch_schedule = EpochSchedule::from_account_info(&accounts[3]).unwrap(); assert_eq!(epoch_schedule, EpochSchedule::default()); - let got_epoch_schedule = EpochSchedule::get()?; + let got_epoch_schedule = EpochSchedule::get().unwrap(); assert_eq!(epoch_schedule, got_epoch_schedule); } @@ -49,8 +49,9 @@ pub fn process_instruction( msg!("Instructions identifier:"); sysvar::instructions::id().log(); assert_eq!(*accounts[4].owner, sysvar::id()); - let index = instructions::load_current_index_checked(&accounts[4])?; - let instruction = instructions::load_instruction_at_checked(index as usize, &accounts[4])?; + let index = instructions::load_current_index_checked(&accounts[4]).unwrap(); + let instruction = + instructions::load_instruction_at_checked(index as usize, &accounts[4]).unwrap(); assert_eq!(0, index); assert_eq!( instruction, @@ -88,8 +89,7 @@ pub fn process_instruction( msg!("Rent identifier:"); sysvar::rent::id().log(); let rent = Rent::from_account_info(&accounts[6]).unwrap(); - assert_eq!(rent, Rent::default()); - let got_rent = Rent::get()?; + let got_rent = Rent::get().unwrap(); assert_eq!(rent, got_rent); } @@ -120,7 +120,7 @@ pub fn process_instruction( msg!("Fee identifier:"); sysvar::fees::id().log(); let fees = Fees::from_account_info(&accounts[10]).unwrap(); - let got_fees = Fees::get()?; + let got_fees = Fees::get().unwrap(); assert_eq!(fees, got_fees); } @@ -129,7 +129,7 @@ pub fn process_instruction( msg!("EpochRewards identifier:"); sysvar::epoch_rewards::id().log(); let epoch_rewards = EpochRewards::from_account_info(&accounts[11]).unwrap(); - let got_epoch_rewards = EpochRewards::get()?; + let got_epoch_rewards = EpochRewards::get().unwrap(); assert_eq!(epoch_rewards, got_epoch_rewards); } diff --git a/programs/sbf/tests/mem.rs b/programs/sbf/tests/mem.rs deleted file mode 100644 index 530ad158a6b3e7..00000000000000 --- a/programs/sbf/tests/mem.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![cfg(feature = "test-bpf")] - -use { - solana_program_test::*, - solana_sbf_rust_mem::process_instruction, - solana_sdk::{ - instruction::Instruction, pubkey::Pubkey, signature::Signer, transaction::Transaction, - }, -}; - -#[tokio::test] -async fn test_mem() { - let program_id = Pubkey::new_unique(); - let program_test = ProgramTest::new( - "solana_sbf_rust_mem", - program_id, - processor!(process_instruction), - ); - let (mut banks_client, payer, recent_blockhash) = program_test.start().await; - - let mut transaction = Transaction::new_with_payer( - &[Instruction::new_with_bincode(program_id, &(), vec![])], - Some(&payer.pubkey()), - ); - transaction.sign(&[&payer], recent_blockhash); - banks_client.process_transaction(transaction).await.unwrap(); -} diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 38ea3afffaa024..9fdcee23aa4749 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -270,12 +270,14 @@ fn test_program_sbf_sanity() { ("solana_sbf_rust_external_spend", false), ("solana_sbf_rust_iter", true), ("solana_sbf_rust_many_args", true), + ("solana_sbf_rust_mem", true), ("solana_sbf_rust_membuiltins", true), ("solana_sbf_rust_noop", true), ("solana_sbf_rust_panic", false), ("solana_sbf_rust_param_passing", true), ("solana_sbf_rust_poseidon", true), ("solana_sbf_rust_rand", true), + ("solana_sbf_rust_remaining_compute_units", true), ("solana_sbf_rust_sanity", true), ("solana_sbf_rust_secp256k1_recover", true), ("solana_sbf_rust_sha", true), diff --git a/programs/sbf/tests/remaining_compute_units.rs b/programs/sbf/tests/remaining_compute_units.rs deleted file mode 100644 index 30da15b2953a53..00000000000000 --- a/programs/sbf/tests/remaining_compute_units.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![cfg(feature = "test-bpf")] - -use { - solana_program_test::*, - solana_sbf_rust_remaining_compute_units::process_instruction, - solana_sdk::{ - instruction::Instruction, pubkey::Pubkey, signature::Signer, transaction::Transaction, - }, -}; - -#[tokio::test] -async fn test_remaining_compute_units() { - let program_id = Pubkey::new_unique(); - let program_test = ProgramTest::new( - "solana_sbf_rust_remaining_compute_units", - program_id, - processor!(process_instruction), - ); - let (mut banks_client, payer, recent_blockhash) = program_test.start().await; - - let mut transaction = Transaction::new_with_payer( - &[Instruction::new_with_bincode(program_id, &(), vec![])], - Some(&payer.pubkey()), - ); - transaction.sign(&[&payer], recent_blockhash); - banks_client.process_transaction(transaction).await.unwrap(); -} diff --git a/programs/sbf/tests/sanity.rs b/programs/sbf/tests/sanity.rs deleted file mode 100644 index 6a561bcae1c395..00000000000000 --- a/programs/sbf/tests/sanity.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![cfg(feature = "test-bpf")] - -use { - solana_program_test::*, - solana_sbf_rust_sanity::process_instruction, - solana_sdk::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - signature::{Keypair, Signer}, - transaction::Transaction, - }, -}; - -#[tokio::test] -async fn test_sanity() { - let program_id = Pubkey::new_unique(); - let program_test = ProgramTest::new( - "solana_sbf_rust_sanity", - program_id, - processor!(process_instruction), - ); - let (mut banks_client, payer_keypair, recent_blockhash) = program_test.start().await; - - let mut transaction = Transaction::new_with_payer( - &[Instruction::new_with_bincode( - program_id, - &(), - vec![ - AccountMeta::new(payer_keypair.pubkey(), true), - AccountMeta::new(Keypair::new().pubkey(), false), - ], - )], - Some(&payer_keypair.pubkey()), - ); - transaction.sign(&[&payer_keypair], recent_blockhash); - banks_client.process_transaction(transaction).await.unwrap(); -} diff --git a/programs/sbf/tests/simulation.rs b/programs/sbf/tests/simulation.rs index f27cf52eeb25f9..6b799c05690c0b 100644 --- a/programs/sbf/tests/simulation.rs +++ b/programs/sbf/tests/simulation.rs @@ -1,44 +1,86 @@ -#![cfg(feature = "test-bpf")] - use { - solana_program_test::{processor, tokio, ProgramTest}, - solana_sbf_rust_simulation::process_instruction, + agave_validator::test_validator::*, + solana_runtime::{ + bank::Bank, + bank_client::BankClient, + genesis_utils::{create_genesis_config, GenesisConfigInfo}, + loader_utils::load_upgradeable_program_and_advance_slot, + }, solana_sdk::{ instruction::{AccountMeta, Instruction}, + message::Message, pubkey::Pubkey, - signature::Signer, - sysvar, - transaction::Transaction, + signature::{Keypair, Signer}, + sysvar::{clock, slot_history}, + transaction::{SanitizedTransaction, Transaction}, }, }; -#[tokio::test] -async fn no_panic_banks_client() { - let program_id = Pubkey::new_unique(); - let program_test = ProgramTest::new( +#[test] +#[cfg(feature = "sbf_rust")] +fn test_no_panic_banks_client() { + solana_logger::setup(); + + let GenesisConfigInfo { + genesis_config, + 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.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_simulation", + ); + bank.freeze(); + + let instruction = Instruction::new_with_bincode( program_id, - processor!(process_instruction), + &[0u8; 0], + vec![ + AccountMeta::new_readonly(slot_history::id(), false), + AccountMeta::new_readonly(clock::id(), false), + ], ); + let blockhash = bank.last_blockhash(); + let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); + let transaction = Transaction::new(&[&mint_keypair], message, blockhash); + let sanitized_tx = SanitizedTransaction::from_transaction_for_tests(transaction); + let result = bank.simulate_transaction(&sanitized_tx, false); + assert!(result.result.is_ok()); +} + +#[test] +#[cfg(feature = "sbf_rust")] +fn test_no_panic_rpc_client() { + solana_logger::setup(); + + let program_id = Pubkey::new_unique(); + let (test_validator, payer) = TestValidatorGenesis::default() + .add_program("solana_sbf_rust_simulation", program_id) + .start(); + let rpc_client = test_validator.get_rpc_client(); + let blockhash = rpc_client.get_latest_blockhash().unwrap(); - let mut context = program_test.start_with_context().await; let transaction = Transaction::new_signed_with_payer( &[Instruction { program_id, accounts: vec![ - AccountMeta::new_readonly(sysvar::slot_history::id(), false), - AccountMeta::new_readonly(sysvar::clock::id(), false), + AccountMeta::new_readonly(slot_history::id(), false), + AccountMeta::new_readonly(clock::id(), false), ], data: vec![], }], - Some(&context.payer.pubkey()), - &[&context.payer], - context.last_blockhash, + Some(&payer.pubkey()), + &[&payer], + blockhash, ); - context - .banks_client - .process_transaction_with_preflight(transaction) - .await + rpc_client + .send_and_confirm_transaction(&transaction) .unwrap(); } diff --git a/programs/sbf/tests/simulation_validator.rs b/programs/sbf/tests/simulation_validator.rs deleted file mode 100644 index 17de51e665e3ec..00000000000000 --- a/programs/sbf/tests/simulation_validator.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![cfg(feature = "test-bpf")] - -use { - agave_validator::test_validator::*, - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - sysvar, - }, - solana_sdk::{signature::Signer, transaction::Transaction}, -}; - -#[test] -fn no_panic_rpc_client() { - solana_logger::setup_with_default("solana_program_runtime=debug"); - let program_id = Pubkey::new_unique(); - - let (test_validator, payer) = TestValidatorGenesis::default() - .add_program("solana_sbf_rust_simulation", program_id) - .start(); - let rpc_client = test_validator.get_rpc_client(); - let blockhash = rpc_client.get_latest_blockhash().unwrap(); - - let transaction = Transaction::new_signed_with_payer( - &[Instruction { - program_id, - accounts: vec![ - AccountMeta::new_readonly(sysvar::slot_history::id(), false), - AccountMeta::new_readonly(sysvar::clock::id(), false), - ], - data: vec![], - }], - Some(&payer.pubkey()), - &[&payer], - blockhash, - ); - - rpc_client - .send_and_confirm_transaction(&transaction) - .unwrap(); -} diff --git a/programs/sbf/tests/sysvar.rs b/programs/sbf/tests/sysvar.rs index ffa2f625b6d03d..9fd35adcaf82c4 100644 --- a/programs/sbf/tests/sysvar.rs +++ b/programs/sbf/tests/sysvar.rs @@ -1,31 +1,36 @@ -#![cfg(feature = "test-bpf")] - use { - solana_program_test::*, - solana_sbf_rust_sysvar::process_instruction, + solana_runtime::{ + bank::Bank, + bank_client::BankClient, + genesis_utils::{create_genesis_config, GenesisConfigInfo}, + loader_utils::load_upgradeable_program_and_advance_slot, + }, solana_sdk::{ feature_set::disable_fees_sysvar, instruction::{AccountMeta, Instruction}, + message::Message, pubkey::Pubkey, - signature::Signer, + signature::{Keypair, Signer}, sysvar::{ clock, epoch_rewards, epoch_schedule, fees, instructions, recent_blockhashes, rent, slot_hashes, slot_history, stake_history, }, - transaction::Transaction, + transaction::{SanitizedTransaction, Transaction}, }, }; -#[tokio::test] -async fn test_sysvars() { - let program_id = Pubkey::new_unique(); - - let mut program_test = ProgramTest::new( - "solana_sbf_rust_sysvar", - program_id, - processor!(process_instruction), - ); +#[test] +#[cfg(feature = "sbf_rust")] +fn test_sysvar_syscalls() { + solana_logger::setup(); + let GenesisConfigInfo { + mut genesis_config, + mint_keypair, + .. + } = create_genesis_config(50); + genesis_config.accounts.remove(&disable_fees_sysvar::id()); + let bank = Bank::new_for_tests(&genesis_config); let epoch_rewards = epoch_rewards::EpochRewards { distribution_starting_block_height: 42, total_rewards: 100, @@ -33,50 +38,25 @@ async fn test_sysvars() { active: true, ..epoch_rewards::EpochRewards::default() }; - program_test.add_sysvar_account(epoch_rewards::id(), &epoch_rewards); - let (mut banks_client, payer, recent_blockhash) = program_test.start().await; - - let mut transaction = Transaction::new_with_payer( - &[Instruction::new_with_bincode( - program_id, - &[0u8], - vec![ - AccountMeta::new(payer.pubkey(), true), - AccountMeta::new(Pubkey::new_unique(), false), - AccountMeta::new_readonly(clock::id(), false), - AccountMeta::new_readonly(epoch_schedule::id(), false), - AccountMeta::new_readonly(instructions::id(), false), - #[allow(deprecated)] - AccountMeta::new_readonly(recent_blockhashes::id(), false), - AccountMeta::new_readonly(rent::id(), false), - AccountMeta::new_readonly(slot_hashes::id(), false), - AccountMeta::new_readonly(slot_history::id(), false), - AccountMeta::new_readonly(stake_history::id(), false), - #[allow(deprecated)] - AccountMeta::new_readonly(fees::id(), false), - AccountMeta::new_readonly(epoch_rewards::id(), false), - ], - )], - Some(&payer.pubkey()), - ); - transaction.sign(&[&payer], recent_blockhash); - banks_client.process_transaction(transaction).await.unwrap(); - - let mut program_test = ProgramTest::new( + bank.set_sysvar_for_tests(&epoch_rewards); + 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, "solana_sbf_rust_sysvar", - program_id, - processor!(process_instruction), ); - program_test.deactivate_feature(disable_fees_sysvar::id()); - program_test.add_sysvar_account(epoch_rewards::id(), &epoch_rewards); - let (mut banks_client, payer, recent_blockhash) = program_test.start().await; + bank.freeze(); - let mut transaction = Transaction::new_with_payer( - &[Instruction::new_with_bincode( + for instruction_data in &[0u8, 1u8] { + let instruction = Instruction::new_with_bincode( program_id, - &[1u8], + &[instruction_data], vec![ - AccountMeta::new(payer.pubkey(), true), + AccountMeta::new(mint_keypair.pubkey(), true), AccountMeta::new(Pubkey::new_unique(), false), AccountMeta::new_readonly(clock::id(), false), AccountMeta::new_readonly(epoch_schedule::id(), false), @@ -91,9 +71,12 @@ async fn test_sysvars() { AccountMeta::new_readonly(fees::id(), false), AccountMeta::new_readonly(epoch_rewards::id(), false), ], - )], - Some(&payer.pubkey()), - ); - transaction.sign(&[&payer], recent_blockhash); - banks_client.process_transaction(transaction).await.unwrap(); + ); + let blockhash = bank.last_blockhash(); + let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); + let transaction = Transaction::new(&[&mint_keypair], message, blockhash); + let sanitized_tx = SanitizedTransaction::from_transaction_for_tests(transaction); + let result = bank.simulate_transaction(&sanitized_tx, false); + assert!(result.result.is_ok()); + } }