Generalize Budget tests to work on multi-ix txs
This commit is contained in:
parent
9e9c0785e7
commit
5b672f8921
|
@ -167,34 +167,33 @@ mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_budget_api::budget_transaction::BudgetTransaction;
|
use solana_budget_api::budget_transaction::BudgetTransaction;
|
||||||
use solana_budget_api::id;
|
use solana_budget_api::id;
|
||||||
|
use solana_runtime::runtime;
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::transaction::{Instruction, Transaction};
|
use solana_sdk::transaction::Transaction;
|
||||||
|
|
||||||
fn process_transaction(
|
fn process_transaction(
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
program_accounts: &mut [Account],
|
tx_accounts: &mut [Account],
|
||||||
) -> Result<(), BudgetError> {
|
) -> Result<(), BudgetError> {
|
||||||
assert_eq!(tx.instructions.len(), 1);
|
for ix in &tx.instructions {
|
||||||
let Instruction {
|
let mut ix_accounts = runtime::get_subset_unchecked_mut(tx_accounts, &ix.accounts);
|
||||||
ref accounts,
|
let mut keyed_accounts: Vec<_> = ix
|
||||||
ref userdata,
|
.accounts
|
||||||
..
|
|
||||||
} = tx.instructions[0];
|
|
||||||
|
|
||||||
let mut keyed_accounts: Vec<_> = accounts
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&index| {
|
.map(|&index| {
|
||||||
let index = index as usize;
|
let index = index as usize;
|
||||||
let key = &tx.account_keys[index];
|
let key = &tx.account_keys[index];
|
||||||
(key, index < tx.signatures.len())
|
(key, index < tx.signatures.len())
|
||||||
})
|
})
|
||||||
.zip(program_accounts.iter_mut())
|
.zip(ix_accounts.iter_mut())
|
||||||
.map(|((key, is_signer), account)| KeyedAccount::new(key, is_signer, account))
|
.map(|((key, is_signer), account)| KeyedAccount::new(key, is_signer, account))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
super::process_instruction(&mut keyed_accounts, &userdata)
|
process_instruction(&mut keyed_accounts, &ix.userdata)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_instruction() {
|
fn test_invalid_instruction() {
|
||||||
|
@ -219,6 +218,7 @@ mod test {
|
||||||
Account::new(1, 0, id()),
|
Account::new(1, 0, id()),
|
||||||
Account::new(0, 512, id()),
|
Account::new(0, 512, id()),
|
||||||
Account::new(0, 0, id()),
|
Account::new(0, 0, id()),
|
||||||
|
Account::new(0, 0, id()),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
|
@ -258,6 +258,7 @@ mod test {
|
||||||
Account::new(1, 0, id()),
|
Account::new(1, 0, id()),
|
||||||
Account::new(0, 512, id()),
|
Account::new(0, 512, id()),
|
||||||
Account::new(0, 0, id()),
|
Account::new(0, 0, id()),
|
||||||
|
Account::new(0, 0, id()),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Initialize BudgetState
|
// Initialize BudgetState
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub mod bloom;
|
||||||
mod hash_queue;
|
mod hash_queue;
|
||||||
pub mod loader_utils;
|
pub mod loader_utils;
|
||||||
mod native_loader;
|
mod native_loader;
|
||||||
mod runtime;
|
pub mod runtime;
|
||||||
mod status_cache;
|
mod status_cache;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -143,7 +143,7 @@ pub fn has_duplicates<T: PartialEq>(xs: &[T]) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get mut references to a subset of elements.
|
/// 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
|
// Since the compiler doesn't know the indexes are unique, dereferencing
|
||||||
// multiple mut elements is assumed to be unsafe. If, however, all
|
// multiple mut elements is assumed to be unsafe. If, however, all
|
||||||
// indexes are unique, it's perfectly safe. The returned elements will share
|
// indexes are unique, it's perfectly safe. The returned elements will share
|
||||||
|
|
Loading…
Reference in New Issue