Simulate auto-creation of system accounts
This commit is contained in:
parent
17dcd1f62a
commit
3dc22e7323
|
@ -168,7 +168,7 @@ mod test {
|
||||||
|
|
||||||
fn process_transaction(
|
fn process_transaction(
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
tx_accounts: &mut [Account],
|
tx_accounts: &mut Vec<Account>,
|
||||||
) -> Result<(), BudgetError> {
|
) -> Result<(), BudgetError> {
|
||||||
runtime::process_transaction(tx, tx_accounts, process_instruction)
|
runtime::process_transaction(tx, tx_accounts, process_instruction)
|
||||||
}
|
}
|
||||||
|
@ -192,12 +192,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unsigned_witness_key() {
|
fn test_unsigned_witness_key() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||||
Account::new(1, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
];
|
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
|
@ -232,12 +227,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unsigned_timestamp() {
|
fn test_unsigned_timestamp() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||||
Account::new(1, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
];
|
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
|
@ -273,11 +263,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_on_date() {
|
fn test_transfer_on_date() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||||
Account::new(1, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
];
|
|
||||||
let from_account = 0;
|
let from_account = 0;
|
||||||
let contract_account = 1;
|
let contract_account = 1;
|
||||||
let to_account = 2;
|
let to_account = 2;
|
||||||
|
@ -349,11 +335,7 @@ mod test {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cancel_transfer() {
|
fn test_cancel_transfer() {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||||
Account::new(1, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
Account::new(0, 0, system_program::id()),
|
|
||||||
];
|
|
||||||
let from_account = 0;
|
let from_account = 0;
|
||||||
let contract_account = 1;
|
let contract_account = 1;
|
||||||
let pay_account = 2;
|
let pay_account = 2;
|
||||||
|
@ -386,8 +368,7 @@ mod test {
|
||||||
// nothing should be changed because apply witness didn't finalize a payment
|
// nothing should be changed because apply witness didn't finalize a payment
|
||||||
assert_eq!(accounts[from_account].lamports, 0);
|
assert_eq!(accounts[from_account].lamports, 0);
|
||||||
assert_eq!(accounts[contract_account].lamports, 1);
|
assert_eq!(accounts[contract_account].lamports, 1);
|
||||||
// this is the `to.pubkey()` account
|
assert_eq!(accounts.get(pay_account), None);
|
||||||
assert_eq!(accounts[pay_account].lamports, 0);
|
|
||||||
|
|
||||||
// Now, cancel the transaction. from gets her funds back
|
// Now, cancel the transaction. from gets her funds back
|
||||||
let tx = BudgetTransaction::new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
|
@ -399,7 +380,7 @@ mod test {
|
||||||
process_transaction(&tx, &mut accounts).unwrap();
|
process_transaction(&tx, &mut accounts).unwrap();
|
||||||
assert_eq!(accounts[from_account].lamports, 1);
|
assert_eq!(accounts[from_account].lamports, 1);
|
||||||
assert_eq!(accounts[contract_account].lamports, 0);
|
assert_eq!(accounts[contract_account].lamports, 0);
|
||||||
assert_eq!(accounts[pay_account].lamports, 0);
|
assert_eq!(accounts.get(pay_account), None);
|
||||||
|
|
||||||
// try to replay the cancel contract
|
// try to replay the cancel contract
|
||||||
let tx = BudgetTransaction::new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
|
@ -414,6 +395,6 @@ mod test {
|
||||||
);
|
);
|
||||||
assert_eq!(accounts[from_account].lamports, 1);
|
assert_eq!(accounts[from_account].lamports, 1);
|
||||||
assert_eq!(accounts[contract_account].lamports, 0);
|
assert_eq!(accounts[contract_account].lamports, 0);
|
||||||
assert_eq!(accounts[pay_account].lamports, 0);
|
assert_eq!(accounts.get(pay_account), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,12 +192,15 @@ pub fn execute_transaction(
|
||||||
/// for easier usage and better stack traces.
|
/// for easier usage and better stack traces.
|
||||||
pub fn process_transaction<F, E>(
|
pub fn process_transaction<F, E>(
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
tx_accounts: &mut [Account],
|
tx_accounts: &mut Vec<Account>,
|
||||||
process_instruction: F,
|
process_instruction: F,
|
||||||
) -> Result<(), E>
|
) -> Result<(), E>
|
||||||
where
|
where
|
||||||
F: Fn(&Pubkey, &mut [KeyedAccount], &[u8]) -> Result<(), E>,
|
F: Fn(&Pubkey, &mut [KeyedAccount], &[u8]) -> Result<(), E>,
|
||||||
{
|
{
|
||||||
|
for _ in tx_accounts.len()..tx.account_keys.len() {
|
||||||
|
tx_accounts.push(Account::new(0, 0, system_program::id()));
|
||||||
|
}
|
||||||
for (i, ix) in tx.instructions.iter().enumerate() {
|
for (i, ix) in tx.instructions.iter().enumerate() {
|
||||||
let mut ix_accounts = get_subset_unchecked_mut(tx_accounts, &ix.accounts);
|
let mut ix_accounts = get_subset_unchecked_mut(tx_accounts, &ix.accounts);
|
||||||
let mut keyed_accounts: Vec<_> = ix
|
let mut keyed_accounts: Vec<_> = ix
|
||||||
|
|
Loading…
Reference in New Issue