2019-03-13 14:37:24 -06:00
|
|
|
use solana_runtime::bank::Bank;
|
2019-03-14 20:42:01 -06:00
|
|
|
use solana_runtime::bank_client::BankClient;
|
2019-03-05 00:14:51 -07:00
|
|
|
use solana_sdk::genesis_block::GenesisBlock;
|
2019-03-05 13:11:20 -07:00
|
|
|
use solana_sdk::native_program::ProgramError;
|
2019-03-05 00:14:51 -07:00
|
|
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
2019-03-05 13:11:20 -07:00
|
|
|
use solana_sdk::system_instruction::SystemInstruction;
|
2019-03-05 00:14:51 -07:00
|
|
|
use solana_sdk::system_program;
|
2019-03-15 10:54:56 -06:00
|
|
|
use solana_sdk::transaction::{Instruction, InstructionError, Transaction, TransactionError};
|
2019-03-05 00:14:51 -07:00
|
|
|
|
|
|
|
#[test]
|
2019-03-05 13:11:20 -07:00
|
|
|
fn test_system_unsigned_transaction() {
|
|
|
|
let (genesis_block, from_keypair) = GenesisBlock::new(100);
|
2019-03-05 00:14:51 -07:00
|
|
|
let bank = Bank::new(&genesis_block);
|
2019-03-14 17:22:56 -06:00
|
|
|
let from_pubkey = from_keypair.pubkey();
|
2019-03-14 20:42:01 -06:00
|
|
|
let alice_client = BankClient::new(&bank, from_keypair);
|
2019-03-05 00:14:51 -07:00
|
|
|
|
2019-03-05 13:11:20 -07:00
|
|
|
let to_keypair = Keypair::new();
|
2019-03-14 20:42:01 -06:00
|
|
|
let to_pubkey = to_keypair.pubkey();
|
|
|
|
let mallory_client = BankClient::new(&bank, to_keypair);
|
2019-03-14 17:22:56 -06:00
|
|
|
|
|
|
|
// Fund to account to bypass AccountNotFound error
|
|
|
|
let ix = SystemInstruction::new_move(&from_pubkey, &to_pubkey, 50);
|
2019-03-15 10:54:56 -06:00
|
|
|
let mut tx = Transaction::new(vec![ix]);
|
2019-03-14 20:42:01 -06:00
|
|
|
alice_client.process_transaction(&mut tx).unwrap();
|
2019-03-05 00:14:51 -07:00
|
|
|
|
2019-03-05 13:11:20 -07:00
|
|
|
// Erroneously sign transaction with recipient account key
|
|
|
|
// No signature case is tested by bank `test_zero_signatures()`
|
2019-03-15 09:47:25 -06:00
|
|
|
let ix = Instruction::new(
|
2019-03-14 17:22:56 -06:00
|
|
|
system_program::id(),
|
|
|
|
&SystemInstruction::Move { lamports: 10 },
|
|
|
|
vec![(from_pubkey, false), (to_pubkey, true)],
|
|
|
|
);
|
2019-03-15 10:54:56 -06:00
|
|
|
let mut tx = Transaction::new(vec![ix]);
|
2019-03-05 00:14:51 -07:00
|
|
|
assert_eq!(
|
2019-03-14 20:42:01 -06:00
|
|
|
mallory_client.process_transaction(&mut tx),
|
2019-03-13 13:58:44 -06:00
|
|
|
Err(TransactionError::InstructionError(
|
2019-03-13 11:46:49 -06:00
|
|
|
0,
|
2019-03-13 12:48:11 -06:00
|
|
|
InstructionError::ProgramError(ProgramError::MissingRequiredSignature)
|
2019-03-13 11:46:49 -06:00
|
|
|
))
|
2019-03-05 00:14:51 -07:00
|
|
|
);
|
2019-03-14 17:22:56 -06:00
|
|
|
assert_eq!(bank.get_balance(&from_pubkey), 50);
|
|
|
|
assert_eq!(bank.get_balance(&to_pubkey), 50);
|
2019-03-05 00:14:51 -07:00
|
|
|
}
|