Files
solana/runtime/tests/system.rs

44 lines
1.7 KiB
Rust
Raw Normal View History

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;
use solana_sdk::native_program::ProgramError;
2019-03-05 00:14:51 -07:00
use solana_sdk::signature::{Keypair, KeypairUtil};
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]
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);
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
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);
// 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
// Erroneously sign transaction with recipient account key
// No signature case is tested by bank `test_zero_signatures()`
let ix = Instruction::new(
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(
0,
2019-03-13 12:48:11 -06:00
InstructionError::ProgramError(ProgramError::MissingRequiredSignature)
))
2019-03-05 00:14:51 -07: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
}