Move Bank-based tests into unit-tests
This commit is contained in:
@ -104,8 +104,15 @@ pub fn entrypoint(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::bank::Bank;
|
||||
use crate::bank_client::BankClient;
|
||||
use solana_sdk::account::Account;
|
||||
use solana_sdk::genesis_block::GenesisBlock;
|
||||
use solana_sdk::native_program::ProgramError;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::system_program;
|
||||
use solana_sdk::transaction::{Instruction, InstructionError, TransactionError};
|
||||
|
||||
#[test]
|
||||
fn test_create_system_account() {
|
||||
@ -267,4 +274,36 @@ mod tests {
|
||||
assert_eq!(from_account.lamports, 50);
|
||||
assert_eq!(to_account.lamports, 51);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_system_unsigned_transaction() {
|
||||
let (genesis_block, mint_keypair) = GenesisBlock::new(100);
|
||||
let bank = Bank::new(&genesis_block);
|
||||
|
||||
let alice_client = BankClient::new(&bank, mint_keypair);
|
||||
let alice_pubkey = alice_client.pubkey();
|
||||
|
||||
let mallory_client = BankClient::new(&bank, Keypair::new());
|
||||
let mallory_pubkey = mallory_client.pubkey();
|
||||
|
||||
// Fund to account to bypass AccountNotFound error
|
||||
alice_client.transfer(50, &mallory_pubkey).unwrap();
|
||||
|
||||
// Erroneously sign transaction with recipient account key
|
||||
// No signature case is tested by bank `test_zero_signatures()`
|
||||
let malicious_script = vec![Instruction::new(
|
||||
system_program::id(),
|
||||
&SystemInstruction::Move { lamports: 10 },
|
||||
vec![(alice_pubkey, false), (mallory_pubkey, true)],
|
||||
)];
|
||||
assert_eq!(
|
||||
mallory_client.process_script(malicious_script),
|
||||
Err(TransactionError::InstructionError(
|
||||
0,
|
||||
InstructionError::ProgramError(ProgramError::MissingRequiredSignature)
|
||||
))
|
||||
);
|
||||
assert_eq!(bank.get_balance(&alice_pubkey), 50);
|
||||
assert_eq!(bank.get_balance(&mallory_pubkey), 50);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user