cargo-test-bpf now sets the "test-bpf" feature for crate tests
The feature allows for tests to distinguish between `cargo test` and `cargo test-bpf` primarily for the purpose of excluding CPI tests that require the system program under `cargo test`, as the path to enabling CPI in `cargo test`-based testing is unclear
This commit is contained in:
parent
d08c3232e2
commit
1a70a2a25b
|
@ -116,12 +116,12 @@ pub fn builtin_process_instruction(
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Execute the BPF entrypoint
|
// Execute the program
|
||||||
let result =
|
let result =
|
||||||
process_instruction(program_id, &account_infos, input).map_err(to_instruction_error);
|
process_instruction(program_id, &account_infos, input).map_err(to_instruction_error);
|
||||||
|
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
// Commit changes to the KeyedAccounts
|
// Commit AccountInfo changes back into KeyedAccounts
|
||||||
for keyed_account in keyed_accounts {
|
for keyed_account in keyed_accounts {
|
||||||
let mut account = keyed_account.account.borrow_mut();
|
let mut account = keyed_account.account.borrow_mut();
|
||||||
let key = keyed_account.unsigned_key();
|
let key = keyed_account.unsigned_key();
|
||||||
|
@ -195,7 +195,7 @@ impl program_stubs::SyscallStubs for SyscallStubs {
|
||||||
signers_seeds: &[&[&[u8]]],
|
signers_seeds: &[&[&[u8]]],
|
||||||
) -> ProgramResult {
|
) -> ProgramResult {
|
||||||
//
|
//
|
||||||
// TODO: Merge the business logic between here and the BPF invoke path in
|
// TODO: Merge the business logic below with the BPF invoke path in
|
||||||
// programs/bpf_loader/src/syscalls.rs
|
// programs/bpf_loader/src/syscalls.rs
|
||||||
//
|
//
|
||||||
info!("SyscallStubs::sol_invoke_signed()");
|
info!("SyscallStubs::sol_invoke_signed()");
|
||||||
|
@ -305,10 +305,20 @@ impl program_stubs::SyscallStubs for SyscallStubs {
|
||||||
|
|
||||||
let mut data = account_info.try_borrow_mut_data()?;
|
let mut data = account_info.try_borrow_mut_data()?;
|
||||||
let new_data = &account.borrow().data;
|
let new_data = &account.borrow().data;
|
||||||
if data.len() != new_data.len() {
|
if *account_info.owner != account.borrow().owner {
|
||||||
// TODO: Figure out how to change the callers account data size
|
// TODO: Figure out how to allow the System Program to change the account owner
|
||||||
panic!(
|
panic!(
|
||||||
"Account resizing ({} -> {}) not supported yet",
|
"Account ownership change not supported yet: {} -> {}. \
|
||||||
|
Consider making this test conditional on `#[cfg(feature = \"test-bpf\")]`",
|
||||||
|
*account_info.owner,
|
||||||
|
account.borrow().owner
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if data.len() != new_data.len() {
|
||||||
|
// TODO: Figure out how to allow the System Program to resize the account data
|
||||||
|
panic!(
|
||||||
|
"Account data resizing not supported yet: {} -> {}. \
|
||||||
|
Consider making this test conditional on `#[cfg(feature = \"test-bpf\")]`",
|
||||||
data.len(),
|
data.len(),
|
||||||
new_data.len()
|
new_data.len()
|
||||||
);
|
);
|
||||||
|
|
|
@ -74,6 +74,15 @@ fn test_bpf(config: Config) {
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let root_package = metadata.root_package().unwrap_or_else(|| {
|
||||||
|
eprintln!(
|
||||||
|
"Workspace does not have a root package: {}",
|
||||||
|
metadata.workspace_root.display()
|
||||||
|
);
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
let set_test_bpf_feature = root_package.features.contains_key("test-bpf");
|
||||||
|
|
||||||
let bpf_out_dir = config
|
let bpf_out_dir = config
|
||||||
.bpf_out_dir
|
.bpf_out_dir
|
||||||
.unwrap_or_else(|| format!("{}", metadata.target_directory.join("deploy").display()));
|
.unwrap_or_else(|| format!("{}", metadata.target_directory.join("deploy").display()));
|
||||||
|
@ -108,6 +117,13 @@ fn test_bpf(config: Config) {
|
||||||
env::set_var("BPF_OUT_DIR", bpf_out_dir);
|
env::set_var("BPF_OUT_DIR", bpf_out_dir);
|
||||||
|
|
||||||
cargo_args.insert(0, "test");
|
cargo_args.insert(0, "test");
|
||||||
|
|
||||||
|
// If the program crate declares the "test-bpf" feature, pass it along to the tests so they can
|
||||||
|
// distinguish between `cargo test` and `cargo test-bpf`
|
||||||
|
if set_test_bpf_feature {
|
||||||
|
cargo_args.push("--features");
|
||||||
|
cargo_args.push("test-bpf");
|
||||||
|
}
|
||||||
for extra_cargo_test_arg in &config.extra_cargo_test_args {
|
for extra_cargo_test_arg in &config.extra_cargo_test_args {
|
||||||
cargo_args.push(&extra_cargo_test_arg);
|
cargo_args.push(&extra_cargo_test_arg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue