From ffe2f96a585a9bd258ad3eb66e481cf04eecb17b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 29 Mar 2021 07:00:53 +0000 Subject: [PATCH] Fix handling of invoked ix accounts in program-test (#16170) (#16175) (cherry picked from commit 27ab415ecc96aab3e6cacc574ce3bac91e754970) Co-authored-by: Justin Starry --- program-test/src/lib.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index 0f37637a13..b15f78d890 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -220,18 +220,17 @@ impl program_stubs::SyscallStubs for SyscallStubs { let logger = invoke_context.get_logger(); let caller = *invoke_context.get_caller().expect("get_caller"); - if instruction.accounts.len() + 1 != account_infos.len() { - panic!( - "Instruction accounts mismatch. Instruction contains {} accounts, with {} - AccountInfos provided", - instruction.accounts.len(), - account_infos.len() - ); - } let message = Message::new(&[instruction.clone()], None); let program_id_index = message.instructions[0].program_id_index as usize; let program_id = message.account_keys[program_id_index]; - let program_account_info = &account_infos[program_id_index]; + let program_account_info = || { + for account_info in account_infos { + if account_info.unsigned_key() == &program_id { + return account_info; + } + } + panic!("Program id {} wasn't found in account_infos", program_id); + }; // TODO don't have the caller's keyed_accounts so can't validate writer or signer escalation or deescalation yet let caller_privileges = message .account_keys @@ -251,17 +250,18 @@ impl program_stubs::SyscallStubs for SyscallStubs { rent_epoch: ai.rent_epoch, } } - let executables = vec![(program_id, RefCell::new(ai_to_a(program_account_info)))]; + let executables = vec![(program_id, RefCell::new(ai_to_a(program_account_info())))]; // Convert AccountInfos into Accounts let mut accounts = vec![]; - for key in &message.account_keys { + 'outer: for key in &message.account_keys { for account_info in account_infos { if account_info.unsigned_key() == key { accounts.push(Rc::new(RefCell::new(ai_to_a(account_info)))); - break; + continue 'outer; } } + panic!("Account {} wasn't found in account_infos", key); } assert_eq!( accounts.len(),