Avoid AccountInUse errors when simulating transactions (#10391)
automerge
This commit is contained in:
@ -1058,6 +1058,15 @@ impl Bank {
|
||||
TransactionBatch::new(results, &self, txs, iteration_order)
|
||||
}
|
||||
|
||||
pub fn prepare_simulation_batch<'a, 'b>(
|
||||
&'a self,
|
||||
txs: &'b [Transaction],
|
||||
) -> TransactionBatch<'a, 'b> {
|
||||
let mut batch = TransactionBatch::new(vec![Ok(()); txs.len()], &self, txs, None);
|
||||
batch.needs_unlock = false;
|
||||
batch
|
||||
}
|
||||
|
||||
pub fn unlock_accounts(&self, batch: &mut TransactionBatch) {
|
||||
if batch.needs_unlock {
|
||||
batch.needs_unlock = false;
|
||||
|
@ -81,6 +81,23 @@ mod tests {
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simulation_batch() {
|
||||
let (bank, txs) = setup();
|
||||
|
||||
// Prepare batch without locks
|
||||
let batch = bank.prepare_simulation_batch(&txs);
|
||||
assert!(batch.lock_results().iter().all(|x| x.is_ok()));
|
||||
|
||||
// Grab locks
|
||||
let batch2 = bank.prepare_batch(&txs, None);
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
|
||||
|
||||
// Prepare another batch without locks
|
||||
let batch3 = bank.prepare_simulation_batch(&txs);
|
||||
assert!(batch3.lock_results().iter().all(|x| x.is_ok()));
|
||||
}
|
||||
|
||||
fn setup() -> (Bank, Vec<Transaction>) {
|
||||
let dummy_leader_pubkey = Pubkey::new_rand();
|
||||
let GenesisConfigInfo {
|
||||
|
Reference in New Issue
Block a user