Skip to content

Commit facbb13

Browse files
adding a use_prev_hash_test
1 parent a00b69f commit facbb13

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

crates/cairo-program-runner-lib/src/hints/execute_task_hints.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub fn append_fact_topologies(
149149
Ok(())
150150
}
151151

152+
// TODO(idanh): can't find this hint anywhere in the starkware main repo, consider removing it.
152153
/// Implements
153154
/// # Validate hash.
154155
/// from starkware.cairo.bootloaders.hash_program import compute_program_hash_chain
@@ -202,6 +203,7 @@ pub const ALL_BUILTINS: [BuiltinName; 11] = [
202203
BuiltinName::mul_mod,
203204
];
204205

206+
// TODO(idanh): This function seems to be unused, consider removing it.
205207
fn check_cairo_pie_builtin_usage(
206208
vm: &mut VirtualMachine,
207209
builtin_name: &BuiltinName,
@@ -509,6 +511,7 @@ pub fn execute_task_exit_scope(
509511
Ok(HintExtension::default())
510512
}
511513

514+
// TODO(idanh): can't find this hint anywhere in the starkware main repo, consider removing it.
512515
/// Implements
513516
/// # Validate hash.
514517
/// from starkware.cairo.bootloaders.hash_program import compute_program_hash_chain
@@ -585,8 +588,8 @@ mod tests {
585588
use super::*;
586589
use crate::hints::codes::*;
587590
use crate::hints::types::{Cairo0Executable, Task};
588-
use crate::test_utils::prepare_vm_for_load_program_loading_test;
589591
use crate::test_utils::{get_hint_codes_at_pc, prepare_non_continuous_ids_data_for_test};
592+
use crate::test_utils::{prepare_ids_data_for_test, prepare_vm_for_load_program_loading_test};
590593
use cairo_vm::any_box;
591594
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
592595
use cairo_vm::hint_processor::hint_processor_definition::HintProcessorLogic;
@@ -1108,5 +1111,29 @@ mod tests {
11081111
assert_eq!(n_selected_builtins, n_builtins);
11091112
}
11101113

1111-
//TODO(Idanh): Add tests for the untested hints in this file.
1114+
#[rstest(use_prev_hash, case(0), case(1))]
1115+
fn test_determine_use_prev_hash(use_prev_hash: i32) {
1116+
// This test checks that the determine_use_prev_hash hint works correctly.
1117+
// It sets up the VM state to before the hint is called, and checks that
1118+
// the use_prev_hash variable is set correctly after the hint is called in the VM's memory.
1119+
let mut vm = VirtualMachine::new(false, false);
1120+
vm.add_memory_segment();
1121+
vm.add_memory_segment();
1122+
vm.set_fp(1);
1123+
vm.set_ap(1);
1124+
let mut exec_scopes = ExecutionScopes::new();
1125+
exec_scopes.insert_value(vars::USE_PREV_HASH, use_prev_hash);
1126+
let ids_data = prepare_ids_data_for_test(&["use_prev_hash"]);
1127+
let ap_tracking = ApTracking::new();
1128+
determine_use_prev_hash(&mut vm, &mut exec_scopes, &ids_data, &ap_tracking)
1129+
.expect("Hint failed unexpectedly");
1130+
1131+
// Check that the use_prev_hash variable is set correctly in the execution scope
1132+
assert_eq!(
1133+
vm.get_integer(Relocatable::from((1, 0)))
1134+
.unwrap()
1135+
.into_owned(),
1136+
Felt252::from(use_prev_hash)
1137+
);
1138+
}
11121139
}

0 commit comments

Comments
 (0)