Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

program-test consumes some units as native #34714

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 11 additions & 2 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand All @@ -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);
}
Loading