diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index b2752804387251..7b946a371c8dad 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -112,6 +112,9 @@ pub fn invoke_builtin_function( let instruction_data = instruction_context.get_instruction_data(); let instruction_account_indices = 0..instruction_context.get_number_of_instruction_accounts(); + // mock builtin program must consume units + invoke_context.consume_checked(1)?; + let log_collector = invoke_context.get_log_collector(); let program_id = instruction_context.get_last_program_key(transaction_context)?; stable_log::program_invoke( diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 8f14e5d92ff938..5377473abe8d4f 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -14015,7 +14015,16 @@ fn test_failed_simulation_compute_units() { Bank::new_with_mockup_builtin_for_tests(&genesis_config, program_id, MockBuiltin::vm).0; const TEST_UNITS: u64 = 10_000; - declare_process_instruction!(MockBuiltin, 1, |invoke_context| { + const MOCK_BUILTIN_UNITS: u64 = 1; + let expected_consumed_units = if bank + .feature_set + .is_active(&solana_sdk::feature_set::native_programs_consume_cu::id()) + { + TEST_UNITS + MOCK_BUILTIN_UNITS + } else { + TEST_UNITS + }; + declare_process_instruction!(MockBuiltin, MOCK_BUILTIN_UNITS, |invoke_context| { invoke_context.consume_checked(TEST_UNITS).unwrap(); Err(InstructionError::InvalidInstructionData) }); @@ -14029,5 +14038,5 @@ fn test_failed_simulation_compute_units() { bank.freeze(); let sanitized = SanitizedTransaction::from_transaction_for_tests(transaction); let simulation = bank.simulate_transaction(&sanitized, false); - assert_eq!(TEST_UNITS, simulation.units_consumed); + assert_eq!(expected_consumed_units, simulation.units_consumed); }