2019-03-02 19:56:49 -08:00
|
|
|
use solana_runtime::bank::Bank;
|
2019-03-21 07:14:14 -07:00
|
|
|
use solana_runtime::bank_client::BankClient;
|
2019-10-25 16:22:41 -07:00
|
|
|
use solana_runtime::loader_utils::create_invoke_instruction;
|
|
|
|
use solana_sdk::client::SyncClient;
|
2019-11-08 20:56:57 -08:00
|
|
|
use solana_sdk::genesis_config::create_genesis_config;
|
2019-03-23 20:12:27 -07:00
|
|
|
use solana_sdk::instruction::InstructionError;
|
2020-04-03 17:40:59 -07:00
|
|
|
use solana_sdk::native_program_info;
|
2019-07-15 12:16:09 -07:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2020-02-20 13:28:55 -08:00
|
|
|
use solana_sdk::signature::Signer;
|
2019-03-23 20:12:27 -07:00
|
|
|
use solana_sdk::transaction::TransactionError;
|
2019-03-02 19:56:49 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_program_native_failure() {
|
2019-11-08 20:56:57 -08:00
|
|
|
let (genesis_config, alice_keypair) = create_genesis_config(50);
|
2019-07-15 12:16:09 -07:00
|
|
|
let program_id = Pubkey::new_rand();
|
2019-11-08 20:56:57 -08:00
|
|
|
let bank = Bank::new(&genesis_config);
|
2020-04-03 17:40:59 -07:00
|
|
|
bank.register_native_instruction_processor(
|
|
|
|
&native_program_info!("solana_failure_program"),
|
|
|
|
&program_id,
|
|
|
|
);
|
2019-03-02 19:56:49 -08:00
|
|
|
|
|
|
|
// Call user program
|
2019-10-25 16:22:41 -07:00
|
|
|
let instruction = create_invoke_instruction(alice_keypair.pubkey(), program_id, &1u8);
|
|
|
|
let bank_client = BankClient::new(bank);
|
2019-03-02 19:56:49 -08:00
|
|
|
assert_eq!(
|
2019-10-25 16:22:41 -07:00
|
|
|
bank_client
|
|
|
|
.send_instruction(&alice_keypair, instruction)
|
|
|
|
.unwrap_err()
|
|
|
|
.unwrap(),
|
2020-04-01 09:01:11 -07:00
|
|
|
TransactionError::InstructionError(0, InstructionError::Custom(0))
|
2019-03-02 19:56:49 -08:00
|
|
|
);
|
|
|
|
}
|