sdk: Make PubKey::create_program_address available in program unit tests (#11745)
* sdk: Make PubKey::create_program_address available in program unit tests This finishes the work started in #11604 to have `create_program_address` available when `target_arch` is not `bpf` and `program` is enabled. Otherwise, there is an undefined reference error to `sol_create_program_address`, which is only defined in `bpf`. A small test to simply call the function has been added in order to catch the problem in the future. The default dependency to `solana-sdk/default` doesn't cause a problem with existing programs since `build.sh` always specifies `--no-default-features`, and programs in `solana-program-library` all use it too. * Add `default-features = false` for inter-program dependencies Fix the build error found during CI. The `--no-default-features` flag only applies to the top-level package, and not to dependencies. A program that depends on another program, i.e. `128bit` which depends on `128bit_dep`, must specify `default-features = false` when including that package, otherwise the `bpf` build will try to pull in default packages, which includes `std`.
This commit is contained in:
@ -266,5 +266,17 @@ fn process_instruction(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Pull in syscall stubs when building for non-BPF targets
|
||||
solana_sdk::program_stubs!();
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
// Pull in syscall stubs when building for non-BPF targets
|
||||
solana_sdk::program_stubs!();
|
||||
|
||||
#[test]
|
||||
fn create_program_address_is_defined() {
|
||||
assert_eq!(
|
||||
Pubkey::create_program_address(&[b"You pass butter"], &Pubkey::default()).unwrap_err(),
|
||||
PubkeyError::InvalidSeeds
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user