2019-02-01 09:00:34 -08:00
|
|
|
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
|
2019-03-02 21:33:02 -08:00
|
|
|
mod bpf {
|
2020-04-18 22:39:08 -07:00
|
|
|
use solana_bpf_loader_program::solana_bpf_loader_program;
|
2020-01-28 17:03:37 -08:00
|
|
|
use solana_runtime::{
|
|
|
|
bank::Bank,
|
|
|
|
bank_client::BankClient,
|
|
|
|
genesis_utils::{create_genesis_config, GenesisConfigInfo},
|
2020-03-17 19:37:16 -07:00
|
|
|
loader_utils::load_program,
|
2020-01-28 17:03:37 -08:00
|
|
|
};
|
2020-03-17 15:59:09 -07:00
|
|
|
use solana_sdk::{
|
|
|
|
account::Account,
|
|
|
|
bpf_loader,
|
|
|
|
client::SyncClient,
|
|
|
|
clock::DEFAULT_SLOTS_PER_EPOCH,
|
|
|
|
instruction::{AccountMeta, Instruction, InstructionError},
|
2020-04-28 14:33:56 -07:00
|
|
|
message::Message,
|
2020-03-17 15:59:09 -07:00
|
|
|
pubkey::Pubkey,
|
|
|
|
signature::Keypair,
|
|
|
|
signature::Signer,
|
|
|
|
sysvar::{clock, fees, rent, rewards, slot_hashes, stake_history},
|
|
|
|
transaction::TransactionError,
|
|
|
|
};
|
|
|
|
use std::{env, fs::File, io::Read, path::PathBuf, sync::Arc};
|
2019-02-01 09:00:34 -08:00
|
|
|
|
2019-03-02 21:33:02 -08:00
|
|
|
/// BPF program file extension
|
|
|
|
const PLATFORM_FILE_EXTENSION_BPF: &str = "so";
|
2018-10-04 09:44:44 -07:00
|
|
|
|
2019-03-02 21:33:02 -08:00
|
|
|
/// Create a BPF program file name
|
|
|
|
fn create_bpf_path(name: &str) -> PathBuf {
|
|
|
|
let mut pathbuf = {
|
|
|
|
let current_exe = env::current_exe().unwrap();
|
|
|
|
PathBuf::from(current_exe.parent().unwrap().parent().unwrap())
|
|
|
|
};
|
|
|
|
pathbuf.push("bpf/");
|
|
|
|
pathbuf.push(name);
|
|
|
|
pathbuf.set_extension(PLATFORM_FILE_EXTENSION_BPF);
|
|
|
|
pathbuf
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:18:01 -08:00
|
|
|
fn load_bpf_program(bank_client: &BankClient, payer_keypair: &Keypair, name: &str) -> Pubkey {
|
|
|
|
let path = create_bpf_path(name);
|
|
|
|
println!("path {:?}", path);
|
|
|
|
let mut file = File::open(path).unwrap();
|
|
|
|
let mut elf = Vec::new();
|
|
|
|
file.read_to_end(&mut elf).unwrap();
|
|
|
|
load_program(bank_client, payer_keypair, &bpf_loader::id(), elf)
|
|
|
|
}
|
|
|
|
|
2020-03-17 19:37:16 -07:00
|
|
|
#[test]
|
|
|
|
#[cfg(any(feature = "bpf_c", feature = "bpf_rust"))]
|
2020-03-17 15:59:09 -07:00
|
|
|
fn test_program_bpf_sanity() {
|
2020-03-17 19:37:16 -07:00
|
|
|
solana_logger::setup();
|
2019-03-02 21:33:02 -08:00
|
|
|
|
2020-03-17 15:59:09 -07:00
|
|
|
let mut programs = Vec::new();
|
|
|
|
#[cfg(feature = "bpf_c")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[
|
2019-06-20 19:10:03 -07:00
|
|
|
("bpf_to_bpf", true),
|
|
|
|
("multiple_static", true),
|
|
|
|
("noop", true),
|
|
|
|
("noop++", true),
|
|
|
|
("panic", false),
|
|
|
|
("relative_call", true),
|
|
|
|
("struct_pass", true),
|
|
|
|
("struct_ret", true),
|
2020-03-17 15:59:09 -07:00
|
|
|
]);
|
2019-03-02 21:33:02 -08:00
|
|
|
}
|
2020-03-17 19:37:16 -07:00
|
|
|
#[cfg(feature = "bpf_rust")]
|
2020-03-17 15:59:09 -07:00
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[
|
2019-06-21 02:43:50 -07:00
|
|
|
("solana_bpf_rust_128bit", true),
|
2019-06-10 11:00:15 -07:00
|
|
|
("solana_bpf_rust_alloc", true),
|
2019-06-20 16:07:12 -07:00
|
|
|
("solana_bpf_rust_dep_crate", true),
|
2019-09-09 10:55:35 -07:00
|
|
|
("solana_bpf_rust_external_spend", false),
|
2019-06-10 11:00:15 -07:00
|
|
|
("solana_bpf_rust_iter", true),
|
2019-07-11 14:27:18 -08:00
|
|
|
("solana_bpf_rust_many_args", true),
|
2019-06-10 11:00:15 -07:00
|
|
|
("solana_bpf_rust_noop", true),
|
|
|
|
("solana_bpf_rust_panic", false),
|
2019-08-29 11:25:22 -07:00
|
|
|
("solana_bpf_rust_param_passing", true),
|
2019-09-10 18:53:02 -07:00
|
|
|
("solana_bpf_rust_sysval", true),
|
2020-03-17 15:59:09 -07:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-03-17 19:37:16 -07:00
|
|
|
for program in programs.iter() {
|
|
|
|
println!("Test program: {:?}", program.0);
|
2019-03-02 21:33:02 -08:00
|
|
|
|
2020-03-17 19:37:16 -07:00
|
|
|
let GenesisConfigInfo {
|
2020-04-15 09:41:29 -07:00
|
|
|
mut genesis_config,
|
2020-03-17 19:37:16 -07:00
|
|
|
mint_keypair,
|
|
|
|
..
|
|
|
|
} = create_genesis_config(50);
|
2020-04-18 22:39:08 -07:00
|
|
|
genesis_config
|
|
|
|
.native_instruction_processors
|
|
|
|
.push(solana_bpf_loader_program!());
|
2020-03-17 19:37:16 -07:00
|
|
|
let bank = Arc::new(Bank::new(&genesis_config));
|
2020-05-08 12:37:04 -07:00
|
|
|
// Create bank with a specific slot, used by solana_bpf_rust_sysvar test
|
2020-03-17 19:37:16 -07:00
|
|
|
let bank =
|
|
|
|
Bank::new_from_parent(&bank, &Pubkey::default(), DEFAULT_SLOTS_PER_EPOCH + 1);
|
|
|
|
let bank_client = BankClient::new(bank);
|
2019-03-21 08:14:14 -06:00
|
|
|
|
2020-03-17 19:37:16 -07:00
|
|
|
// Call user program
|
|
|
|
let program_id = load_bpf_program(&bank_client, &mint_keypair, program.0);
|
|
|
|
let account_metas = vec![
|
|
|
|
AccountMeta::new(mint_keypair.pubkey(), true),
|
|
|
|
AccountMeta::new(Keypair::new().pubkey(), false),
|
|
|
|
AccountMeta::new(clock::id(), false),
|
|
|
|
AccountMeta::new(fees::id(), false),
|
|
|
|
AccountMeta::new(rewards::id(), false),
|
|
|
|
AccountMeta::new(slot_hashes::id(), false),
|
|
|
|
AccountMeta::new(stake_history::id(), false),
|
|
|
|
AccountMeta::new(rent::id(), false),
|
|
|
|
];
|
|
|
|
let instruction = Instruction::new(program_id, &1u8, account_metas);
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
if program.1 {
|
|
|
|
assert!(result.is_ok());
|
|
|
|
} else {
|
|
|
|
assert!(result.is_err());
|
2019-03-02 21:33:02 -08:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 19:37:16 -07:00
|
|
|
}
|
2020-01-22 09:11:56 -08:00
|
|
|
|
2020-03-17 19:37:16 -07:00
|
|
|
#[test]
|
2020-03-17 15:59:09 -07:00
|
|
|
fn test_program_bpf_duplicate_accounts() {
|
2020-03-17 19:37:16 -07:00
|
|
|
solana_logger::setup();
|
2020-01-22 09:11:56 -08:00
|
|
|
|
2020-03-17 15:59:09 -07:00
|
|
|
let mut programs = Vec::new();
|
|
|
|
#[cfg(feature = "bpf_c")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[("dup_accounts")]);
|
|
|
|
}
|
|
|
|
#[cfg(feature = "bpf_rust")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[("solana_bpf_rust_dup_accounts")]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for program in programs.iter() {
|
|
|
|
println!("Test program: {:?}", program);
|
|
|
|
|
2020-01-22 09:11:56 -08:00
|
|
|
let GenesisConfigInfo {
|
2020-04-15 09:41:29 -07:00
|
|
|
mut genesis_config,
|
2020-01-22 09:11:56 -08:00
|
|
|
mint_keypair,
|
|
|
|
..
|
|
|
|
} = create_genesis_config(50);
|
2020-04-18 22:39:08 -07:00
|
|
|
genesis_config
|
|
|
|
.native_instruction_processors
|
|
|
|
.push(solana_bpf_loader_program!());
|
2020-01-22 09:11:56 -08:00
|
|
|
let bank = Arc::new(Bank::new(&genesis_config));
|
|
|
|
let bank_client = BankClient::new_shared(&bank);
|
2020-03-17 15:59:09 -07:00
|
|
|
let program_id = load_bpf_program(&bank_client, &mint_keypair, program);
|
2020-01-22 09:11:56 -08:00
|
|
|
let payee_account = Account::new(10, 1, &program_id);
|
|
|
|
let payee_pubkey = Pubkey::new_rand();
|
|
|
|
bank.store_account(&payee_pubkey, &payee_account);
|
|
|
|
|
|
|
|
let account = Account::new(10, 1, &program_id);
|
|
|
|
let pubkey = Pubkey::new_rand();
|
|
|
|
let account_metas = vec![
|
|
|
|
AccountMeta::new(mint_keypair.pubkey(), true),
|
|
|
|
AccountMeta::new(payee_pubkey, false),
|
|
|
|
AccountMeta::new(pubkey, false),
|
|
|
|
AccountMeta::new(pubkey, false),
|
|
|
|
];
|
|
|
|
|
|
|
|
bank.store_account(&pubkey, &account);
|
|
|
|
let instruction = Instruction::new(program_id, &1u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
let data = bank_client.get_account_data(&pubkey).unwrap().unwrap();
|
|
|
|
assert!(result.is_ok());
|
|
|
|
assert_eq!(data[0], 1);
|
|
|
|
|
|
|
|
bank.store_account(&pubkey, &account);
|
|
|
|
let instruction = Instruction::new(program_id, &2u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
let data = bank_client.get_account_data(&pubkey).unwrap().unwrap();
|
|
|
|
assert!(result.is_ok());
|
|
|
|
assert_eq!(data[0], 2);
|
|
|
|
|
|
|
|
bank.store_account(&pubkey, &account);
|
|
|
|
let instruction = Instruction::new(program_id, &3u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
2020-01-24 10:54:26 -08:00
|
|
|
let data = bank_client.get_account_data(&pubkey).unwrap().unwrap();
|
|
|
|
assert!(result.is_ok());
|
|
|
|
assert_eq!(data[0], 3);
|
2020-01-22 09:11:56 -08:00
|
|
|
|
|
|
|
bank.store_account(&pubkey, &account);
|
|
|
|
let instruction = Instruction::new(program_id, &4u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
let lamports = bank_client.get_balance(&pubkey).unwrap();
|
|
|
|
assert!(result.is_ok());
|
|
|
|
assert_eq!(lamports, 11);
|
|
|
|
|
|
|
|
bank.store_account(&pubkey, &account);
|
|
|
|
let instruction = Instruction::new(program_id, &5u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
let lamports = bank_client.get_balance(&pubkey).unwrap();
|
|
|
|
assert!(result.is_ok());
|
|
|
|
assert_eq!(lamports, 12);
|
|
|
|
|
|
|
|
bank.store_account(&pubkey, &account);
|
|
|
|
let instruction = Instruction::new(program_id, &6u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
2020-01-24 10:54:26 -08:00
|
|
|
let lamports = bank_client.get_balance(&pubkey).unwrap();
|
|
|
|
assert!(result.is_ok());
|
|
|
|
assert_eq!(lamports, 13);
|
2020-01-22 09:11:56 -08:00
|
|
|
}
|
2020-03-17 15:59:09 -07:00
|
|
|
}
|
2020-01-30 09:47:22 -08:00
|
|
|
|
2020-03-17 19:37:16 -07:00
|
|
|
#[test]
|
2020-03-17 15:59:09 -07:00
|
|
|
fn test_program_bpf_error_handling() {
|
2020-03-17 19:37:16 -07:00
|
|
|
solana_logger::setup();
|
2020-01-30 09:47:22 -08:00
|
|
|
|
2020-03-17 15:59:09 -07:00
|
|
|
let mut programs = Vec::new();
|
|
|
|
#[cfg(feature = "bpf_c")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[("error_handling")]);
|
|
|
|
}
|
|
|
|
#[cfg(feature = "bpf_rust")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[("solana_bpf_rust_error_handling")]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for program in programs.iter() {
|
|
|
|
println!("Test program: {:?}", program);
|
|
|
|
|
2020-01-30 09:47:22 -08:00
|
|
|
let GenesisConfigInfo {
|
2020-04-15 09:41:29 -07:00
|
|
|
mut genesis_config,
|
2020-01-30 09:47:22 -08:00
|
|
|
mint_keypair,
|
|
|
|
..
|
|
|
|
} = create_genesis_config(50);
|
2020-04-18 22:39:08 -07:00
|
|
|
genesis_config
|
|
|
|
.native_instruction_processors
|
|
|
|
.push(solana_bpf_loader_program!());
|
2020-01-30 09:47:22 -08:00
|
|
|
let bank = Bank::new(&genesis_config);
|
|
|
|
let bank_client = BankClient::new(bank);
|
2020-03-17 15:59:09 -07:00
|
|
|
let program_id = load_bpf_program(&bank_client, &mint_keypair, program);
|
2020-01-30 09:47:22 -08:00
|
|
|
let account_metas = vec![AccountMeta::new(mint_keypair.pubkey(), true)];
|
|
|
|
|
|
|
|
let instruction = Instruction::new(program_id, &1u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
assert!(result.is_ok());
|
|
|
|
|
|
|
|
let instruction = Instruction::new(program_id, &2u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
assert_eq!(
|
|
|
|
result.unwrap_err().unwrap(),
|
2020-01-30 20:40:27 -08:00
|
|
|
TransactionError::InstructionError(0, InstructionError::InvalidAccountData)
|
2020-01-30 09:47:22 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
let instruction = Instruction::new(program_id, &3u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
assert_eq!(
|
|
|
|
result.unwrap_err().unwrap(),
|
2020-04-01 09:01:11 -07:00
|
|
|
TransactionError::InstructionError(0, InstructionError::Custom(0))
|
2020-01-30 09:47:22 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
let instruction = Instruction::new(program_id, &4u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
assert_eq!(
|
|
|
|
result.unwrap_err().unwrap(),
|
2020-04-01 09:01:11 -07:00
|
|
|
TransactionError::InstructionError(0, InstructionError::Custom(42))
|
2020-01-30 09:47:22 -08:00
|
|
|
);
|
|
|
|
|
2020-03-17 15:59:09 -07:00
|
|
|
let instruction = Instruction::new(program_id, &5u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
let result = result.unwrap_err().unwrap();
|
|
|
|
if TransactionError::InstructionError(0, InstructionError::InvalidInstructionData)
|
|
|
|
!= result
|
|
|
|
{
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
TransactionError::InstructionError(0, InstructionError::InvalidError)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-30 09:47:22 -08:00
|
|
|
let instruction = Instruction::new(program_id, &6u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
2020-03-17 15:59:09 -07:00
|
|
|
let result = result.unwrap_err().unwrap();
|
|
|
|
if TransactionError::InstructionError(0, InstructionError::InvalidInstructionData)
|
|
|
|
!= result
|
|
|
|
{
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
TransactionError::InstructionError(0, InstructionError::InvalidError)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let instruction = Instruction::new(program_id, &7u8, account_metas.clone());
|
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
|
|
|
let result = result.unwrap_err().unwrap();
|
|
|
|
if TransactionError::InstructionError(0, InstructionError::InvalidInstructionData)
|
|
|
|
!= result
|
|
|
|
{
|
2020-03-17 19:37:16 -07:00
|
|
|
assert_eq!(
|
2020-03-17 15:59:09 -07:00
|
|
|
result,
|
2020-03-17 19:37:16 -07:00
|
|
|
TransactionError::InstructionError(0, InstructionError::AccountBorrowFailed)
|
|
|
|
);
|
2020-03-17 15:59:09 -07:00
|
|
|
}
|
2020-01-30 20:40:27 -08:00
|
|
|
|
2020-03-17 15:59:09 -07:00
|
|
|
let instruction = Instruction::new(program_id, &8u8, account_metas.clone());
|
2020-01-30 20:40:27 -08:00
|
|
|
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
2020-01-30 09:47:22 -08:00
|
|
|
assert_eq!(
|
|
|
|
result.unwrap_err().unwrap(),
|
|
|
|
TransactionError::InstructionError(0, InstructionError::InvalidInstructionData)
|
|
|
|
);
|
|
|
|
}
|
2019-01-02 15:12:42 -08:00
|
|
|
}
|
2020-04-28 14:33:56 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_program_bpf_invoke() {
|
|
|
|
solana_logger::setup();
|
|
|
|
|
2020-05-26 01:02:31 -07:00
|
|
|
const TEST_SUCCESS: u8 = 1;
|
|
|
|
const TEST_PRIVILEGE_ESCALATION_SIGNER: u8 = 2;
|
|
|
|
const TEST_PRIVILEGE_ESCALATION_WRITABLE: u8 = 3;
|
|
|
|
|
2020-04-28 14:33:56 -07:00
|
|
|
let mut programs = Vec::new();
|
|
|
|
#[cfg(feature = "bpf_c")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[("invoke", "invoked")]);
|
|
|
|
}
|
|
|
|
#[cfg(feature = "bpf_rust")]
|
|
|
|
{
|
|
|
|
programs.extend_from_slice(&[("solana_bpf_rust_invoke", "solana_bpf_rust_invoked")]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for program in programs.iter() {
|
|
|
|
println!("Test program: {:?}", program);
|
|
|
|
|
|
|
|
let GenesisConfigInfo {
|
|
|
|
mut genesis_config,
|
|
|
|
mint_keypair,
|
|
|
|
..
|
|
|
|
} = create_genesis_config(50);
|
|
|
|
genesis_config
|
|
|
|
.native_instruction_processors
|
|
|
|
.push(solana_bpf_loader_program!());
|
|
|
|
let bank = Arc::new(Bank::new(&genesis_config));
|
|
|
|
let bank_client = BankClient::new_shared(&bank);
|
|
|
|
|
2020-05-08 12:24:36 -07:00
|
|
|
let invoke_program_id = load_bpf_program(&bank_client, &mint_keypair, program.0);
|
2020-04-28 14:33:56 -07:00
|
|
|
let invoked_program_id = load_bpf_program(&bank_client, &mint_keypair, program.1);
|
|
|
|
|
|
|
|
let argument_keypair = Keypair::new();
|
2020-05-20 09:24:57 -07:00
|
|
|
let account = Account::new(41, 100, &invoke_program_id);
|
2020-04-28 14:33:56 -07:00
|
|
|
bank.store_account(&argument_keypair.pubkey(), &account);
|
|
|
|
|
|
|
|
let invoked_argument_keypair = Keypair::new();
|
2020-05-20 09:24:57 -07:00
|
|
|
let account = Account::new(10, 10, &invoked_program_id);
|
2020-04-28 14:33:56 -07:00
|
|
|
bank.store_account(&invoked_argument_keypair.pubkey(), &account);
|
|
|
|
|
2020-05-20 09:24:57 -07:00
|
|
|
let from_keypair = Keypair::new();
|
|
|
|
let account = Account::new(43, 0, &solana_sdk::system_program::id());
|
|
|
|
bank.store_account(&from_keypair.pubkey(), &account);
|
|
|
|
|
2020-05-08 12:24:36 -07:00
|
|
|
let derived_key1 =
|
|
|
|
Pubkey::create_program_address(&["You pass butter"], &invoke_program_id).unwrap();
|
2020-04-28 14:33:56 -07:00
|
|
|
let derived_key2 =
|
2020-05-08 12:24:36 -07:00
|
|
|
Pubkey::create_program_address(&["Lil'", "Bits"], &invoked_program_id).unwrap();
|
|
|
|
let derived_key3 =
|
2020-04-28 14:33:56 -07:00
|
|
|
Pubkey::create_program_address(&["Gar Ma Nar Nar"], &invoked_program_id).unwrap();
|
|
|
|
|
|
|
|
let account_metas = vec![
|
|
|
|
AccountMeta::new(mint_keypair.pubkey(), true),
|
|
|
|
AccountMeta::new(argument_keypair.pubkey(), true),
|
|
|
|
AccountMeta::new_readonly(invoked_program_id, false),
|
|
|
|
AccountMeta::new(invoked_argument_keypair.pubkey(), true),
|
|
|
|
AccountMeta::new_readonly(invoked_program_id, false),
|
|
|
|
AccountMeta::new(argument_keypair.pubkey(), true),
|
2020-05-08 12:24:36 -07:00
|
|
|
AccountMeta::new(derived_key1, false),
|
|
|
|
AccountMeta::new(derived_key2, false),
|
|
|
|
AccountMeta::new_readonly(derived_key3, false),
|
2020-05-20 09:24:57 -07:00
|
|
|
AccountMeta::new_readonly(solana_sdk::system_program::id(), false),
|
|
|
|
AccountMeta::new(from_keypair.pubkey(), true),
|
2020-04-28 14:33:56 -07:00
|
|
|
];
|
|
|
|
|
2020-05-26 01:02:31 -07:00
|
|
|
// success cases
|
2020-04-28 14:33:56 -07:00
|
|
|
|
2020-05-26 01:02:31 -07:00
|
|
|
let instruction =
|
|
|
|
Instruction::new(invoke_program_id, &TEST_SUCCESS, account_metas.clone());
|
|
|
|
let message = Message::new(&[instruction]);
|
2020-04-28 14:33:56 -07:00
|
|
|
assert!(bank_client
|
|
|
|
.send_message(
|
2020-05-22 18:54:24 +01:00
|
|
|
&[
|
|
|
|
&mint_keypair,
|
|
|
|
&argument_keypair,
|
|
|
|
&invoked_argument_keypair,
|
|
|
|
&from_keypair
|
|
|
|
],
|
2020-04-28 14:33:56 -07:00
|
|
|
message,
|
|
|
|
)
|
|
|
|
.is_ok());
|
2020-05-26 01:02:31 -07:00
|
|
|
|
|
|
|
// failure cases
|
|
|
|
|
|
|
|
let instruction = Instruction::new(
|
|
|
|
invoke_program_id,
|
|
|
|
&TEST_PRIVILEGE_ESCALATION_SIGNER,
|
|
|
|
account_metas.clone(),
|
|
|
|
);
|
|
|
|
let message = Message::new(&[instruction]);
|
|
|
|
assert_eq!(
|
|
|
|
bank_client
|
|
|
|
.send_message(
|
|
|
|
&[
|
|
|
|
&mint_keypair,
|
|
|
|
&argument_keypair,
|
|
|
|
&invoked_argument_keypair,
|
|
|
|
&from_keypair
|
|
|
|
],
|
|
|
|
message,
|
|
|
|
)
|
|
|
|
.unwrap_err()
|
|
|
|
.unwrap(),
|
|
|
|
TransactionError::InstructionError(0, InstructionError::Custom(194969602))
|
|
|
|
);
|
|
|
|
|
|
|
|
let instruction = Instruction::new(
|
|
|
|
invoke_program_id,
|
|
|
|
&TEST_PRIVILEGE_ESCALATION_WRITABLE,
|
|
|
|
account_metas.clone(),
|
|
|
|
);
|
|
|
|
let message = Message::new(&[instruction]);
|
|
|
|
assert_eq!(
|
|
|
|
bank_client
|
|
|
|
.send_message(
|
|
|
|
&[
|
|
|
|
&mint_keypair,
|
|
|
|
&argument_keypair,
|
|
|
|
&invoked_argument_keypair,
|
|
|
|
&from_keypair
|
|
|
|
],
|
|
|
|
message,
|
|
|
|
)
|
|
|
|
.unwrap_err()
|
|
|
|
.unwrap(),
|
|
|
|
TransactionError::InstructionError(0, InstructionError::Custom(194969602))
|
|
|
|
);
|
2020-04-28 14:33:56 -07:00
|
|
|
}
|
|
|
|
}
|
2019-01-02 15:12:42 -08:00
|
|
|
}
|