forked from anza-xyz/agave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor - Avoid host build of SBPF program test crates (anza-xyz#1711)
* Removes ProgramTest from simulation tests. * Removes ProgramTest from sysvar syscall tests. * Workaround for rustc crash caused by 16 byte aligned memcpy. * Deduplicates test_program_sbf_sanity. * Moves mem and remaining_compute_units into test_program_sbf_sanity(). * Removes unused dev-dependencies in Cargo.toml. * Removes crate-type = lib from Cargo.tomls. * Adds SBF_OUT_DIR env to CI script. * Adds "sysvar" to build.rs.
- Loading branch information
Showing
17 changed files
with
123 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,7 @@ fn main() { | |
"simulation", | ||
"spoof1", | ||
"spoof1_system", | ||
"sysvar", | ||
"upgradeable", | ||
"upgraded", | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
Oops, something went wrong.