diff --git a/programs/budget/src/budget_program.rs b/programs/budget/src/budget_program.rs index b3e3c7adc..7d96bdb4f 100644 --- a/programs/budget/src/budget_program.rs +++ b/programs/budget/src/budget_program.rs @@ -167,34 +167,33 @@ mod test { use super::*; use solana_budget_api::budget_transaction::BudgetTransaction; use solana_budget_api::id; + use solana_runtime::runtime; use solana_sdk::account::Account; use solana_sdk::hash::Hash; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::transaction::{Instruction, Transaction}; + use solana_sdk::transaction::Transaction; fn process_transaction( tx: &Transaction, - program_accounts: &mut [Account], + tx_accounts: &mut [Account], ) -> Result<(), BudgetError> { - assert_eq!(tx.instructions.len(), 1); - let Instruction { - ref accounts, - ref userdata, - .. - } = tx.instructions[0]; + for ix in &tx.instructions { + let mut ix_accounts = runtime::get_subset_unchecked_mut(tx_accounts, &ix.accounts); + let mut keyed_accounts: Vec<_> = ix + .accounts + .iter() + .map(|&index| { + let index = index as usize; + let key = &tx.account_keys[index]; + (key, index < tx.signatures.len()) + }) + .zip(ix_accounts.iter_mut()) + .map(|((key, is_signer), account)| KeyedAccount::new(key, is_signer, account)) + .collect(); - let mut keyed_accounts: Vec<_> = accounts - .iter() - .map(|&index| { - let index = index as usize; - let key = &tx.account_keys[index]; - (key, index < tx.signatures.len()) - }) - .zip(program_accounts.iter_mut()) - .map(|((key, is_signer), account)| KeyedAccount::new(key, is_signer, account)) - .collect(); - - super::process_instruction(&mut keyed_accounts, &userdata) + process_instruction(&mut keyed_accounts, &ix.userdata)?; + } + Ok(()) } #[test] fn test_invalid_instruction() { @@ -219,6 +218,7 @@ mod test { Account::new(1, 0, id()), Account::new(0, 512, id()), Account::new(0, 0, id()), + Account::new(0, 0, id()), ]; // Initialize BudgetState @@ -258,6 +258,7 @@ mod test { Account::new(1, 0, id()), Account::new(0, 512, id()), Account::new(0, 0, id()), + Account::new(0, 0, id()), ]; // Initialize BudgetState diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index e682c4556..0dfa8e18c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -5,7 +5,7 @@ pub mod bloom; mod hash_queue; pub mod loader_utils; mod native_loader; -mod runtime; +pub mod runtime; mod status_cache; #[macro_use] diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index 229ef6a20..26b706109 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -143,7 +143,7 @@ pub fn has_duplicates(xs: &[T]) -> bool { } /// Get mut references to a subset of elements. -fn get_subset_unchecked_mut<'a, T>(xs: &'a mut [T], indexes: &[u8]) -> Vec<&'a mut T> { +pub fn get_subset_unchecked_mut<'a, T>(xs: &'a mut [T], indexes: &[u8]) -> Vec<&'a mut T> { // Since the compiler doesn't know the indexes are unique, dereferencing // multiple mut elements is assumed to be unsafe. If, however, all // indexes are unique, it's perfectly safe. The returned elements will share