From 72a968fbe8df4692bbb008fd71d11bcd37fd8f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Fri, 1 Jul 2022 00:06:24 +0200 Subject: [PATCH] Fix/system instruction processor tests (#26338) * Make mock_process_instruction() stricter by invoking the verify() method. * Fixes broken test cases. --- program-runtime/src/invoke_context.rs | 3 ++- runtime/src/system_instruction_processor.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 0d4bbf3b1f..7b3c364ec7 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -1196,7 +1196,8 @@ pub fn mock_process_instruction( &program_indices, instruction_data, ) - .and_then(|_| process_instruction(1, &mut invoke_context)); + .and_then(|_| process_instruction(1, &mut invoke_context)) + .and_then(|_| invoke_context.verify(&preparation.instruction_accounts, &program_indices)); invoke_context.pop().unwrap(); assert_eq!(result, expected_result); let mut transaction_accounts = transaction_context.deconstruct_without_keys().unwrap(); diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 6ad7aecaa5..e69c8680c5 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -916,7 +916,7 @@ mod tests { #[test] fn test_request_more_than_allowed_data_length() { let from = Pubkey::new_unique(); - let from_account = AccountSharedData::new(100, 0, &Pubkey::new_unique()); + let from_account = AccountSharedData::new(100, 0, &system_program::id()); let to = Pubkey::new_unique(); let to_account = AccountSharedData::new(0, 0, &Pubkey::default()); let instruction_accounts = vec![ @@ -1359,7 +1359,7 @@ mod tests { #[test] fn test_transfer_lamports() { let from = Pubkey::new_unique(); - let from_account = AccountSharedData::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter + let from_account = AccountSharedData::new(100, 0, &system_program::id()); let to = Pubkey::new(&[3; 32]); let to_account = AccountSharedData::new(1, 0, &to); // account owner should not matter let transaction_accounts = vec![(from, from_account), (to, to_account)]; @@ -1439,7 +1439,7 @@ mod tests { let from_seed = "42".to_string(); let from_owner = system_program::id(); let from = Pubkey::create_with_seed(&base, from_seed.as_str(), &from_owner).unwrap(); - let from_account = AccountSharedData::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter + let from_account = AccountSharedData::new(100, 0, &system_program::id()); let to = Pubkey::new(&[3; 32]); let to_account = AccountSharedData::new(1, 0, &to); // account owner should not matter let transaction_accounts =