diff --git a/src/tests/bitwise_test.rs b/src/tests/bitwise_test.rs index 5a027c7b4c..f42b66a6b1 100644 --- a/src/tests/bitwise_test.rs +++ b/src/tests/bitwise_test.rs @@ -1,14 +1,4 @@ -use crate::stdlib::prelude::*; - -use crate::{ - hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, - types::program::Program, - vm::{ - runners::cairo_runner::CairoRunner, trace::trace_entry::TraceEntry, vm_core::VirtualMachine, - }, -}; - -use assert_matches::assert_matches; +use crate::tests::run_program_with_trace; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; @@ -16,259 +6,54 @@ use wasm_bindgen_test::*; #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bitwise_integration_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/bitwise_builtin_test.json"), - Some("main"), - ) - .unwrap(); - let mut hint_processor = BuiltinHintProcessor::new_empty(); - let mut cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap(); - let mut vm = VirtualMachine::new(true); - let end = cairo_runner.initialize(&mut vm).unwrap(); - assert_matches!( - cairo_runner.run_until_pc(end, &mut vm, &mut hint_processor), - Ok(()), - "Execution failed" - ); - assert_matches!( - cairo_runner.relocate(&mut vm, true), - Ok(()), - "Execution failed" - ); - - let python_vm_relocated_trace: Vec = vec![ - TraceEntry { - pc: 27, - ap: 72, - fp: 72, - }, - TraceEntry { - pc: 28, - ap: 73, - fp: 72, - }, - TraceEntry { - pc: 30, - ap: 74, - fp: 72, - }, - TraceEntry { - pc: 32, - ap: 75, - fp: 72, - }, - TraceEntry { - pc: 9, - ap: 77, - fp: 77, - }, - TraceEntry { - pc: 10, - ap: 77, - fp: 77, - }, - TraceEntry { - pc: 11, - ap: 77, - fp: 77, - }, - TraceEntry { - pc: 13, - ap: 78, - fp: 77, - }, - TraceEntry { - pc: 14, - ap: 79, - fp: 77, - }, - TraceEntry { - pc: 34, - ap: 79, - fp: 72, - }, - TraceEntry { - pc: 36, - ap: 79, - fp: 72, - }, - TraceEntry { - pc: 37, - ap: 80, - fp: 72, - }, - TraceEntry { - pc: 39, - ap: 81, - fp: 72, - }, - TraceEntry { - pc: 41, - ap: 82, - fp: 72, - }, - TraceEntry { - pc: 15, - ap: 84, - fp: 84, - }, - TraceEntry { - pc: 16, - ap: 84, - fp: 84, - }, - TraceEntry { - pc: 17, - ap: 84, - fp: 84, - }, - TraceEntry { - pc: 19, - ap: 85, - fp: 84, - }, - TraceEntry { - pc: 20, - ap: 86, - fp: 84, - }, - TraceEntry { - pc: 43, - ap: 86, - fp: 72, - }, - TraceEntry { - pc: 45, - ap: 86, - fp: 72, - }, - TraceEntry { - pc: 46, - ap: 87, - fp: 72, - }, - TraceEntry { - pc: 48, - ap: 88, - fp: 72, - }, - TraceEntry { - pc: 50, - ap: 89, - fp: 72, - }, - TraceEntry { - pc: 21, - ap: 91, - fp: 91, - }, - TraceEntry { - pc: 22, - ap: 91, - fp: 91, - }, - TraceEntry { - pc: 23, - ap: 91, - fp: 91, - }, - TraceEntry { - pc: 25, - ap: 92, - fp: 91, - }, - TraceEntry { - pc: 26, - ap: 93, - fp: 91, - }, - TraceEntry { - pc: 52, - ap: 93, - fp: 72, - }, - TraceEntry { - pc: 54, - ap: 93, - fp: 72, - }, - TraceEntry { - pc: 55, - ap: 94, - fp: 72, - }, - TraceEntry { - pc: 57, - ap: 95, - fp: 72, - }, - TraceEntry { - pc: 59, - ap: 96, - fp: 72, - }, - TraceEntry { - pc: 1, - ap: 98, - fp: 98, - }, - TraceEntry { - pc: 2, - ap: 98, - fp: 98, - }, - TraceEntry { - pc: 3, - ap: 98, - fp: 98, - }, - TraceEntry { - pc: 5, - ap: 99, - fp: 98, - }, - TraceEntry { - pc: 6, - ap: 100, - fp: 98, - }, - TraceEntry { - pc: 7, - ap: 101, - fp: 98, - }, - TraceEntry { - pc: 8, - ap: 102, - fp: 98, - }, - TraceEntry { - pc: 61, - ap: 102, - fp: 72, - }, - TraceEntry { - pc: 63, - ap: 102, - fp: 72, - }, - TraceEntry { - pc: 65, - ap: 102, - fp: 72, - }, - TraceEntry { - pc: 67, - ap: 102, - fp: 72, - }, - TraceEntry { - pc: 68, - ap: 103, - fp: 72, - }, + let program_data = include_bytes!("../../cairo_programs/bitwise_builtin_test.json"); + let trace = [ + (27, 72, 72), + (28, 73, 72), + (30, 74, 72), + (32, 75, 72), + (9, 77, 77), + (10, 77, 77), + (11, 77, 77), + (13, 78, 77), + (14, 79, 77), + (34, 79, 72), + (36, 79, 72), + (37, 80, 72), + (39, 81, 72), + (41, 82, 72), + (15, 84, 84), + (16, 84, 84), + (17, 84, 84), + (19, 85, 84), + (20, 86, 84), + (43, 86, 72), + (45, 86, 72), + (46, 87, 72), + (48, 88, 72), + (50, 89, 72), + (21, 91, 91), + (22, 91, 91), + (23, 91, 91), + (25, 92, 91), + (26, 93, 91), + (52, 93, 72), + (54, 93, 72), + (55, 94, 72), + (57, 95, 72), + (59, 96, 72), + (1, 98, 98), + (2, 98, 98), + (3, 98, 98), + (5, 99, 98), + (6, 100, 98), + (7, 101, 98), + (8, 102, 98), + (61, 102, 72), + (63, 102, 72), + (65, 102, 72), + (67, 102, 72), + (68, 103, 72), ]; - for (i, entry) in python_vm_relocated_trace.iter().enumerate() { - assert_eq!(&vm.get_relocated_trace().unwrap()[i], entry); - } + run_program_with_trace(program_data.as_slice(), &trace); } diff --git a/src/tests/cairo_run_test.rs b/src/tests/cairo_run_test.rs index 5f1ffd1a3b..96a4c70b69 100644 --- a/src/tests/cairo_run_test.rs +++ b/src/tests/cairo_run_test.rs @@ -1,1402 +1,1268 @@ -use crate::stdlib::prelude::*; - -use crate::cairo_run::{self, CairoRunConfig}; -use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; +use crate::tests::*; #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn fibonacci() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/fibonacci.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/fibonacci.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn array_sum() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/array_sum.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/array_sum.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn big_struct() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/big_struct.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/big_struct.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn call_function_assign_param_by_name() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/call_function_assign_param_by_name.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = + include_bytes!("../../cairo_programs/call_function_assign_param_by_name.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn function_return() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/function_return.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/function_return.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn function_return_if_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/function_return_if_print.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/function_return_if_print.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn function_return_to_variable() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/function_return_to_variable.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/function_return_to_variable.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn if_and_prime() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/if_and_prime.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/if_and_prime.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn if_in_function() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/if_in_function.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/if_in_function.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn if_list() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/if_list.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/if_list.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn jmp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/jmp.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/jmp.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn jmp_if_condition() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/jmp_if_condition.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/jmp_if_condition.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn pointers() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/pointers.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/pointers.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/print.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/print.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn program_return() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/return.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/return.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn reversed_register_instructions() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/reversed_register_instructions.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/reversed_register_instructions.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn simple_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/simple_print.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/simple_print.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_addition_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/test_addition_if.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/test_addition_if.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_reverse_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/test_reverse_if.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/test_reverse_if.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_subtraction_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/test_subtraction_if.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/test_subtraction_if.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn use_imported_module() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/use_imported_module.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/use_imported_module.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bitwise_output() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bitwise_output.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/bitwise_output.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bitwise_recursion() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bitwise_recursion.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/bitwise_recursion.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/integration.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/integration.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn integration_with_alloc_locals() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/integration_with_alloc_locals.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/integration_with_alloc_locals.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compare_arrays() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_arrays.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/compare_arrays.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compare_greater_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_greater_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/compare_greater_array.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compare_lesser_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_lesser_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/compare_lesser_array.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_le_felt_hint() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_le_felt_hint.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/assert_le_felt_hint.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_250_bit_element_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_250_bit_element_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/assert_250_bit_element_array.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn abs_value_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/abs_value_array.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/abs_value_array.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn compare_different_arrays() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/compare_different_arrays.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/compare_different_arrays.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_nn() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_nn.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/assert_nn.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sqrt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/sqrt.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/sqrt.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_not_zero() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_not_zero.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/assert_not_zero.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn split_int() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/split_int.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/split_int.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn split_int_big() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/split_int_big.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/split_int_big.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn split_felt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/split_felt.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/split_felt.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn math_cmp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/math_cmp.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/math_cmp.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsigned_div_rem() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/unsigned_div_rem.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/unsigned_div_rem.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signed_div_rem() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/signed_div_rem.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/signed_div_rem.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn assert_lt_felt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/assert_lt_felt.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/assert_lt_felt.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memcpy_test() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/memcpy_test.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/memcpy_test.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memset() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/memset.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/memset.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn pow() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/pow.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/pow.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/dict.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_update() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_update.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/dict_update.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/uint256.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/uint256.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn find_element() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/find_element.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/find_element.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn search_sorted_lower() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/search_sorted_lower.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/search_sorted_lower.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn usort() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/usort.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/usort.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn squash_dict() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/squash_dict.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/squash_dict.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_squash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_squash.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/dict_squash.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_add() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/set_add.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/set_add.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn secp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/secp.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/secp.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn signature() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/signature.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/signature.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn secp_ec() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/secp_ec.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/secp_ec.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_hello_world_hash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/blake2s_hello_world_hash.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/blake2s_hello_world_hash.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn finalize_blake2s() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/finalize_blake2s.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/finalize_blake2s.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/unsafe_keccak.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/unsafe_keccak.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_felts() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/blake2s_felts.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/blake2s_felts.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unsafe_keccak_finalize() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/unsafe_keccak_finalize.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/unsafe_keccak_finalize.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn keccak_add_uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/keccak_add_uint256.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/keccak_add_uint256.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/_keccak.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/_keccak.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn keccak_copy_inputs() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/keccak_copy_inputs.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/keccak_copy_inputs.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn cairo_finalize_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/cairo_finalize_keccak.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/cairo_finalize_keccak.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn operations_with_data_structures() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/operations_with_data_structures.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/operations_with_data_structures.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn sha256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/sha256.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/sha256.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn math_cmp_and_pow_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/math_cmp_and_pow_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = + include_bytes!("../../cairo_programs/math_cmp_and_pow_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn uint256_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/uint256_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/uint256_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn set_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/set_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/set_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn memory_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/memory_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/memory_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/dict_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn secp_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/secp_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/secp_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn keccak_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/keccak_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/keccak_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn blake2s_integration_tests() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/blake2s_integration_tests.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/blake2s_integration_tests.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn relocate_segments() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/relocate_segments.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/relocate_segments.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn dict_store_cast_ptr() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/dict_store_cast_ptr.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/dict_store_cast_ptr.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn common_signature() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/common_signature.json"); - cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ) - .expect("Couldn't run program"); + let program_data = include_bytes!("../../cairo_programs/common_signature.json"); + run_program_simple(program_data.as_slice()); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bad_usort() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/bad_usort.json"); - let expected_error_message = "unexpected verify multiplicity fail: positions length != 0"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); + let program_data = include_bytes!("../../cairo_programs/bad_programs/bad_usort.json"); + let error_msg = "unexpected verify multiplicity fail: positions length != 0"; + run_program_with_error(program_data.as_slice(), error_msg); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bad_dict_new() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/bad_dict_new.json"); - let expected_error_message = "Dict Error: Tried to create a dict whithout an initial dict"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); + let program_data = include_bytes!("../../cairo_programs/bad_programs/bad_dict_new.json"); + let error_msg = "Dict Error: Tried to create a dict whithout an initial dict"; + run_program_with_error(program_data.as_slice(), error_msg); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn bad_dict_update() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/bad_dict_update.json"); - let expected_error_message = + let program_data = include_bytes!("../../cairo_programs/bad_programs/bad_dict_update.json"); + let error_msg = "Dict Error: Got the wrong value for dict_update, expected value: 3, got: 5 for key: 2"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); + run_program_with_error(program_data.as_slice(), error_msg); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn error_msg_attr() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr.json"); - let expected_error_message = "SafeUint256: addition overflow"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); + let program_data = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr.json"); + let error_msg = "SafeUint256: addition overflow"; + run_program_with_error(program_data.as_slice(), error_msg); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn error_msg_attr_tempvar() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_tempvar.json"); + let program_data = + include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_tempvar.json"); #[cfg(feature = "std")] - let expected_error_message = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n assert x = 2;\n ^***********^\n"; + let error_msg = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n assert x = 2;\n ^***********^\n"; #[cfg(not(feature = "std"))] - let expected_error_message = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); + let error_msg = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n"; + run_program_with_error(program_data.as_slice(), error_msg); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn error_msg_attr_struct() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let file = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_struct.json"); - let expected_error_message = "Error message: Cats cannot have more than nine lives: {cat} (Cannot evaluate ap-based or complex references: ['cat'])"; - let res = cairo_run::cairo_run( - file, - &CairoRunConfig { - layout: "all_cairo", - ..Default::default() - }, - &mut hint_executor, - ); - assert!(&res - .err() - .unwrap() - .to_string() - .contains(expected_error_message)); + let program_data = + include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_struct.json"); + let error_msg = "Error message: Cats cannot have more than nine lives: {cat} (Cannot evaluate ap-based or complex references: ['cat'])"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_test() { + let program_data = include_bytes!("../../cairo_programs/fibonacci.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_array_sum() { + let program_data = include_bytes!("../../cairo_programs/array_sum.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_big_struct() { + let program_data = include_bytes!("../../cairo_programs/big_struct.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_call_function_assign_param_by_name() { + let program_data = + include_bytes!("../../cairo_programs/call_function_assign_param_by_name.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_function_return() { + let program_data = include_bytes!("../../cairo_programs/function_return.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_function_return_if_print() { + let program_data = include_bytes!("../../cairo_programs/function_return_if_print.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_function_return_to_variable() { + let program_data = include_bytes!("../../cairo_programs/function_return_to_variable.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_if_and_prime() { + let program_data = include_bytes!("../../cairo_programs/if_and_prime.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_if_in_function() { + let program_data = include_bytes!("../../cairo_programs/if_in_function.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_if_list() { + let program_data = include_bytes!("../../cairo_programs/if_list.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_jmp() { + let program_data = include_bytes!("../../cairo_programs/jmp.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_jmp_if_condition() { + let program_data = include_bytes!("../../cairo_programs/jmp_if_condition.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_pointers() { + let program_data = include_bytes!("../../cairo_programs/pointers.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_print() { + let program_data = include_bytes!("../../cairo_programs/print.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_return() { + let program_data = include_bytes!("../../cairo_programs/return.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_reversed_register_instructions() { + let program_data = include_bytes!("../../cairo_programs/reversed_register_instructions.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_simple_print() { + let program_data = include_bytes!("../../cairo_programs/simple_print.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_test_addition_if() { + let program_data = include_bytes!("../../cairo_programs/test_addition_if.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_test_reverse_if() { + let program_data = include_bytes!("../../cairo_programs/test_reverse_if.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_test_subtraction_if() { + let program_data = include_bytes!("../../cairo_programs/test_subtraction_if.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_use_imported_module() { + let program_data = include_bytes!("../../cairo_programs/use_imported_module.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_bitwise_output() { + let program_data = include_bytes!("../../cairo_programs/bitwise_output.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_bitwise_recursion() { + let program_data = include_bytes!("../../cairo_programs/bitwise_recursion.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_integration() { + let program_data = include_bytes!("../../cairo_programs/integration.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_integration_with_alloc_locals() { + let program_data = include_bytes!("../../cairo_programs/integration_with_alloc_locals.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_compare_arrays() { + let program_data = include_bytes!("../../cairo_programs/compare_arrays.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_compare_greater_array() { + let program_data = include_bytes!("../../cairo_programs/compare_greater_array.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_compare_lesser_array() { + let program_data = include_bytes!("../../cairo_programs/compare_lesser_array.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_assert_le_felt_hint() { + let program_data = include_bytes!("../../cairo_programs/assert_le_felt_hint.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_assert_250_bit_element_array() { + let program_data = include_bytes!("../../cairo_programs/assert_250_bit_element_array.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_abs_value() { + let program_data = include_bytes!("../../cairo_programs/abs_value_array.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_compare_different_arrays() { + let program_data = include_bytes!("../../cairo_programs/compare_different_arrays.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_assert_nn() { + let program_data = include_bytes!("../../cairo_programs/assert_nn.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_sqrt() { + let program_data = include_bytes!("../../cairo_programs/sqrt.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_assert_not_zero() { + let program_data = include_bytes!("../../cairo_programs/assert_not_zero.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_split_int() { + let program_data = include_bytes!("../../cairo_programs/split_int.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_split_int_big() { + let program_data = include_bytes!("../../cairo_programs/split_int_big.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_split_felt() { + let program_data = include_bytes!("../../cairo_programs/split_felt.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_math_cmp() { + let program_data = include_bytes!("../../cairo_programs/math_cmp.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_unsigned_div_rem() { + let program_data = include_bytes!("../../cairo_programs/unsigned_div_rem.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_signed_div_rem() { + let program_data = include_bytes!("../../cairo_programs/signed_div_rem.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_assert_lt_felt() { + let program_data = include_bytes!("../../cairo_programs/assert_lt_felt.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_memcpy() { + let program_data = include_bytes!("../../cairo_programs/memcpy_test.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_memset() { + let program_data = include_bytes!("../../cairo_programs/memset.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_pow() { + let program_data = include_bytes!("../../cairo_programs/pow.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict() { + let program_data = include_bytes!("../../cairo_programs/dict.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict_update() { + let program_data = include_bytes!("../../cairo_programs/dict_update.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_uint256() { + let program_data = include_bytes!("../../cairo_programs/uint256.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_find_element() { + let program_data = include_bytes!("../../cairo_programs/find_element.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_search_sorted_lower() { + let program_data = include_bytes!("../../cairo_programs/search_sorted_lower.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_usort() { + let program_data = include_bytes!("../../cairo_programs/usort.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_usort_bad() { + let program_data = include_bytes!("../../cairo_programs/bad_programs/bad_usort.json"); + let error_msg = "unexpected verify multiplicity fail: positions length != 0"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict_write_bad() { + let program_data = include_bytes!("../../cairo_programs/bad_programs/bad_dict_new.json"); + let error_msg = "Dict Error: Tried to create a dict whithout an initial dict"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict_update_bad() { + let program_data = include_bytes!("../../cairo_programs/bad_programs/bad_dict_update.json"); + let error_msg = + "Dict Error: Got the wrong value for dict_update, expected value: 3, got: 5 for key: 2"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_squash_dict() { + let program_data = include_bytes!("../../cairo_programs/squash_dict.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict_squash() { + let program_data = include_bytes!("../../cairo_programs/dict_squash.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_set_add() { + let program_data = include_bytes!("../../cairo_programs/set_add.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_secp() { + let program_data = include_bytes!("../../cairo_programs/secp.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_signature() { + let program_data = include_bytes!("../../cairo_programs/signature.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_secp_ec() { + let program_data = include_bytes!("../../cairo_programs/secp_ec.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_blake2s_hello_world_hash() { + let program_data = include_bytes!("../../cairo_programs/blake2s_hello_world_hash.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_finalize_blake2s() { + let program_data = include_bytes!("../../cairo_programs/finalize_blake2s.json"); + run_program_simple(program_data.as_slice()); +} +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_unsafe_keccak() { + let program_data = include_bytes!("../../cairo_programs/unsafe_keccak.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_blake2s_felts() { + let program_data = include_bytes!("../../cairo_programs/blake2s_felts.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_unsafe_keccak_finalize() { + let program_data = include_bytes!("../../cairo_programs/unsafe_keccak_finalize.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_keccak_add_uint256() { + let program_data = include_bytes!("../../cairo_programs/keccak_add_uint256.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_private_keccak() { + let program_data = include_bytes!("../../cairo_programs/_keccak.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_keccak_copy_inputs() { + let program_data = include_bytes!("../../cairo_programs/keccak_copy_inputs.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_finalize_keccak() { + let program_data = include_bytes!("../../cairo_programs/cairo_finalize_keccak.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_operations_with_data() { + let program_data = include_bytes!("../../cairo_programs/operations_with_data_structures.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_sha256() { + let program_data = include_bytes!("../../cairo_programs/sha256.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_math_cmp_and_pow_integration() { + let program_data = + include_bytes!("../../cairo_programs/math_cmp_and_pow_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_uint256_integration() { + let program_data = include_bytes!("../../cairo_programs/uint256_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_set_integration() { + let program_data = include_bytes!("../../cairo_programs/set_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_memory_module_integration() { + let program_data = include_bytes!("../../cairo_programs/memory_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict_integration() { + let program_data = include_bytes!("../../cairo_programs/dict_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_secp_integration() { + let program_data = include_bytes!("../../cairo_programs/secp_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_keccak_integration() { + let program_data = include_bytes!("../../cairo_programs/keccak_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_blake2s_integration() { + let program_data = include_bytes!("../../cairo_programs/blake2s_integration_tests.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_relocate_segments() { + let program_data = include_bytes!("../../cairo_programs/relocate_segments.json"); + run_program_small(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_error_msg_attr() { + let program_data = include_bytes!("../../cairo_programs/bad_programs/error_msg_attr.json"); + let error_msg = "SafeUint256: addition overflow"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_error_msg_attr_ap_based_reference() { + let program_data = + include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_tempvar.json"); + #[cfg(feature = "std")] + let error_msg = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n assert x = 2;\n ^***********^\n"; + #[cfg(not(feature = "std"))] + let error_msg = "Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_error_msg_attr_complex_reference() { + let program_data = + include_bytes!("../../cairo_programs/bad_programs/error_msg_attr_struct.json"); + let error_msg = "Error message: Cats cannot have more than nine lives: {cat} (Cannot evaluate ap-based or complex references: ['cat'])"; + run_program_with_error(program_data.as_slice(), error_msg); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_dict_store_cast_pointer() { + let program_data = include_bytes!("../../cairo_programs/dict_store_cast_ptr.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_verify_signature_hint() { + let program_data = include_bytes!("../../cairo_programs/common_signature.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_poseidon_builtin() { + let program_data = include_bytes!("../../cairo_programs/poseidon_builtin.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_ec_op() { + let program_data = include_bytes!("../../cairo_programs/ec_op.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_poseidon_hash() { + let program_data = include_bytes!("../../cairo_programs/poseidon_hash.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_chained_run_ec_op() { + let program_data = include_bytes!("../../cairo_programs/chained_ec_op.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_keccak_builtin() { + let program_data = include_bytes!("../../cairo_programs/keccak_builtin.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_keccak_uint256() { + let program_data = include_bytes!("../../cairo_programs/keccak_uint256.json"); + run_program_simple(program_data.as_slice()); +} + +#[test] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] +fn cairo_run_recover_y() { + let program_data = include_bytes!("../../cairo_programs/recover_y.json"); + run_program_simple(program_data.as_slice()); } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 47c3be4d51..3597d2a022 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,3 +1,14 @@ +use crate::stdlib::prelude::*; + +use crate::{ + cairo_run::{cairo_run, CairoRunConfig}, + hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, + vm::trace::trace_entry::TraceEntry, +}; + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; + mod bitwise_test; mod cairo_run_test; mod pedersen_test; @@ -5,3 +16,55 @@ mod struct_test; #[cfg(feature = "skip_next_instruction_hint")] mod skip_instruction_test; + +//For simple programs that should just succeed and have no special needs. +pub(self) fn run_program_simple(data: &[u8]) { + run_program(data, Some("all_cairo"), None, None) +} + +//For simple programs that should just succeed but using small layout. +pub(self) fn run_program_small(data: &[u8]) { + run_program(data, Some("small"), None, None) +} + +pub(self) fn run_program_with_trace(data: &[u8], trace: &[(usize, usize, usize)]) { + run_program(data, Some("all_cairo"), Some(trace), None) +} + +pub(self) fn run_program_with_error(data: &[u8], error: &str) { + run_program(data, Some("all_cairo"), None, Some(error)) +} + +pub(self) fn run_program( + data: &[u8], + layout: Option<&str>, + trace: Option<&[(usize, usize, usize)]>, + error: Option<&str>, +) { + let mut hint_executor = BuiltinHintProcessor::new_empty(); + let cairo_run_config = CairoRunConfig { + layout: layout.unwrap_or("all_cairo"), + relocate_mem: true, + trace_enabled: true, + ..Default::default() + }; + let res = cairo_run(data, &cairo_run_config, &mut hint_executor); + if let Some(error) = error { + assert!(res.is_err()); + assert!(res.err().unwrap().to_string().contains(error)); + return; + } + let (_runner, vm) = res.expect("Execution failed"); + if let Some(trace) = trace { + let expected_trace: Vec<_> = trace + .iter() + .copied() + .map(|(pc, ap, fp)| TraceEntry { pc, ap, fp }) + .collect(); + let trace = vm.get_relocated_trace().unwrap(); + assert_eq!(trace.len(), expected_trace.len()); + for (entry, expected) in trace.iter().zip(expected_trace.iter()) { + assert_eq!(entry, expected); + } + } +} diff --git a/src/tests/pedersen_test.rs b/src/tests/pedersen_test.rs index bb7ed344a1..e3ecda4571 100644 --- a/src/tests/pedersen_test.rs +++ b/src/tests/pedersen_test.rs @@ -1,13 +1,4 @@ -use crate::stdlib::prelude::*; - -use crate::vm::trace::trace_entry::TraceEntry; -use crate::{ - hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, - types::program::Program, - vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine}, -}; - -use assert_matches::assert_matches; +use crate::tests::run_program_with_trace; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; @@ -15,98 +6,22 @@ use wasm_bindgen_test::*; #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn pedersen_integration_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/pedersen_test.json"), - Some("main"), - ) - .unwrap(); - let mut hint_processor = BuiltinHintProcessor::new_empty(); - let mut cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap(); - let mut vm = VirtualMachine::new(true); - let end = cairo_runner.initialize(&mut vm).unwrap(); - assert_matches!( - cairo_runner.run_until_pc(end, &mut vm, &mut hint_processor), - Ok(()) - ); - assert!( - cairo_runner.relocate(&mut vm, true) == Ok(()), - "Execution failed" - ); - - let python_vm_relocated_trace: Vec = vec![ - TraceEntry { - pc: 7, - ap: 25, - fp: 25, - }, - TraceEntry { - pc: 8, - ap: 26, - fp: 25, - }, - TraceEntry { - pc: 10, - ap: 27, - fp: 25, - }, - TraceEntry { - pc: 12, - ap: 28, - fp: 25, - }, - TraceEntry { - pc: 1, - ap: 30, - fp: 30, - }, - TraceEntry { - pc: 2, - ap: 30, - fp: 30, - }, - TraceEntry { - pc: 3, - ap: 30, - fp: 30, - }, - TraceEntry { - pc: 5, - ap: 31, - fp: 30, - }, - TraceEntry { - pc: 6, - ap: 32, - fp: 30, - }, - TraceEntry { - pc: 14, - ap: 32, - fp: 25, - }, - TraceEntry { - pc: 15, - ap: 32, - fp: 25, - }, - TraceEntry { - pc: 17, - ap: 33, - fp: 25, - }, - TraceEntry { - pc: 18, - ap: 34, - fp: 25, - }, - TraceEntry { - pc: 19, - ap: 35, - fp: 25, - }, + let program_data = include_bytes!("../../cairo_programs/pedersen_test.json"); + let expected_trace = [ + (7, 25, 25), + (8, 26, 25), + (10, 27, 25), + (12, 28, 25), + (1, 30, 30), + (2, 30, 30), + (3, 30, 30), + (5, 31, 30), + (6, 32, 30), + (14, 32, 25), + (15, 32, 25), + (17, 33, 25), + (18, 34, 25), + (19, 35, 25), ]; - assert_eq!( - vm.get_relocated_trace().ok(), - Some(&python_vm_relocated_trace) - ); + run_program_with_trace(program_data.as_slice(), expected_trace.as_slice()); } diff --git a/src/tests/skip_instruction_test.rs b/src/tests/skip_instruction_test.rs index 77badd08ee..7ca52944c8 100644 --- a/src/tests/skip_instruction_test.rs +++ b/src/tests/skip_instruction_test.rs @@ -1,10 +1,4 @@ -use crate::{ - hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, - types::program::Program, - vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine}, -}; - -use assert_matches::assert_matches; +use crate::tests::run_program_simple; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; @@ -12,21 +6,8 @@ use wasm_bindgen_test::*; #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn skip_next_instruction_test() { - let program = Program::from_bytes( - include_bytes!( - "../../cairo_programs/noretrocompat/test_skip_next_instruction.noretrocompat.json" - ), - Some("main"), - ) - .unwrap(); - - let mut hint_processor = BuiltinHintProcessor::new_empty(); - - let mut cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap(); - let mut vm = VirtualMachine::new(false); - let end = cairo_runner.initialize(&mut vm).unwrap(); - assert_matches!( - cairo_runner.run_until_pc(end, &mut vm, &mut hint_processor), - Ok(()) + let program_data = include_bytes!( + "../../cairo_programs/noretrocompat/test_skip_next_instruction.noretrocompat.json" ); + run_program_simple(program_data.as_slice()); } diff --git a/src/tests/struct_test.rs b/src/tests/struct_test.rs index 391357367b..4b34770010 100644 --- a/src/tests/struct_test.rs +++ b/src/tests/struct_test.rs @@ -1,12 +1,4 @@ -use crate::vm::trace::trace_entry::TraceEntry; -use crate::{ - hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, - types::program::Program, vm::vm_core::VirtualMachine, -}; - -use crate::vm::runners::cairo_runner::CairoRunner; - -use assert_matches::assert_matches; +use crate::tests::run_program_with_trace; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; @@ -14,30 +6,7 @@ use wasm_bindgen_test::*; #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn struct_integration_test() { - let program = Program::from_bytes( - include_bytes!("../../cairo_programs/struct.json"), - Some("main"), - ) - .unwrap(); - let mut hint_processor = BuiltinHintProcessor::new_empty(); - let mut cairo_runner = CairoRunner::new(&program, "all_cairo", false).unwrap(); - let mut vm = VirtualMachine::new(true); - let end = cairo_runner.initialize(&mut vm).unwrap(); - - assert_matches!( - cairo_runner.run_until_pc(end, &mut vm, &mut hint_processor), - Ok(()), - "Execution failed" - ); - assert!( - cairo_runner.relocate(&mut vm, true) == Ok(()), - "Execution failed" - ); - let relocated_entry = TraceEntry { - pc: 1, - ap: 4, - fp: 4, - }; - - assert_eq!(vm.get_relocated_trace().ok(), Some(&vec![relocated_entry])); + let program_data = include_bytes!("../../cairo_programs/struct.json"); + let expected_trace = [(1, 4, 4)]; + run_program_with_trace(program_data.as_slice(), expected_trace.as_slice()); } diff --git a/tests/cairo_run_test.rs b/tests/cairo_run_test.rs deleted file mode 100644 index 510e0494fe..0000000000 --- a/tests/cairo_run_test.rs +++ /dev/null @@ -1,1522 +0,0 @@ -use cairo_vm::cairo_run; -use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen_test::*; - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_test() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/fibonacci.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_array_sum() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/array_sum.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_big_struct() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/big_struct.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_call_function_assign_param_by_name() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/call_function_assign_param_by_name.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_function_return() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/function_return.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_function_return_if_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/function_return_if_print.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_function_return_to_variable() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/function_return_to_variable.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_if_and_prime() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/if_and_prime.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_if_in_function() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/if_in_function.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_if_list() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/if_list.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_jmp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/jmp.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_jmp_if_condition() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/jmp_if_condition.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_pointers() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/pointers.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/print.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_return() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/return.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_reversed_register_instructions() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/reversed_register_instructions.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_simple_print() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/simple_print.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_test_addition_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/test_addition_if.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_test_reverse_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/test_reverse_if.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_test_subtraction_if() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/test_subtraction_if.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_use_imported_module() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/use_imported_module.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_bitwise_output() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/bitwise_output.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_bitwise_recursion() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/bitwise_recursion.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/integration.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_integration_with_alloc_locals() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/integration_with_alloc_locals.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_compare_arrays() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_arrays.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_compare_greater_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_greater_array.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_compare_lesser_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_lesser_array.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_assert_le_felt_hint() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_le_felt_hint.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_assert_250_bit_element_array() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_250_bit_element_array.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_abs_value() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/abs_value_array.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_compare_different_arrays() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/compare_different_arrays.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_assert_nn() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_nn.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_sqrt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/sqrt.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_assert_not_zero() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_not_zero.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_split_int() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/split_int.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_split_int_big() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/split_int_big.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_split_felt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/split_felt.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_math_cmp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/math_cmp.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_unsigned_div_rem() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/unsigned_div_rem.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_signed_div_rem() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/signed_div_rem.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_assert_lt_felt() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/assert_lt_felt.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_memcpy() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/memcpy_test.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_memset() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/memset.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_pow() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/pow.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict_update() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_update.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/uint256.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_find_element() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/find_element.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_search_sorted_lower() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/search_sorted_lower.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_usort() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/usort.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_usort_bad() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_usort.json"), - &cairo_run_config, - &mut hint_executor, - ); - assert!(err.is_err()); - assert!(err - .err() - .unwrap() - .to_string() - .contains("unexpected verify multiplicity fail: positions length != 0")); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict_write_bad() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - assert!(cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_new.json"), - &cairo_run_config, - &mut hint_executor, - ) - .is_err()); - - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_new.json"), - &cairo_run_config, - &mut hint_executor, - ) - .err(); - assert!(err - .unwrap() - .to_string() - .contains("Dict Error: Tried to create a dict whithout an initial dict")); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict_update_bad() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - assert!(cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_update.json"), - &cairo_run_config, - &mut hint_executor, - ) - .is_err()); - - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/bad_dict_update.json"), - &cairo_run_config, - &mut hint_executor, - ) - .err(); - assert!(err.unwrap().to_string().contains( - "Dict Error: Got the wrong value for dict_update, expected value: 3, got: 5 for key: 2" - )); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_squash_dict() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/squash_dict.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict_squash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_squash.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_set_add() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/set_add.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_secp() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/secp.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_signature() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/signature.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_secp_ec() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/secp_ec.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_blake2s_hello_world_hash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/blake2s_hello_world_hash.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_finalize_blake2s() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/finalize_blake2s.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_unsafe_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/unsafe_keccak.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_blake2s_felts() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/blake2s_felts.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_unsafe_keccak_finalize() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/unsafe_keccak_finalize.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_keccak_add_uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_add_uint256.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_private_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/_keccak.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_keccak_copy_inputs() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_copy_inputs.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_finalize_keccak() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/cairo_finalize_keccak.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_operations_with_data() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/operations_with_data_structures.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_sha256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/sha256.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_math_cmp_and_pow_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/math_cmp_and_pow_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_uint256_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/uint256_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_set_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/set_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_memory_module_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/memory_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_secp_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/secp_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_keccak_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_blake2s_integration() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/blake2s_integration_tests.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_relocate_segments() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/relocate_segments.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_error_msg_attr() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/error_msg_attr.json"), - &cairo_run_config, - &mut hint_executor, - ) - .err() - .unwrap(); - - assert!(err.to_string().contains("SafeUint256: addition overflow")); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_error_msg_attr_ap_based_reference() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/error_msg_attr_tempvar.json"), - &cairo_run_config, - &mut hint_executor, - ) - .err() - .unwrap(); - - #[cfg(feature = "std")] - assert_eq!(err.to_string(), String::from("Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n assert x = 2;\n ^***********^\n")); - - #[cfg(not(feature = "std"))] - assert_eq!(err.to_string(), String::from("Error message: SafeUint256: addition overflow: {x} (Cannot evaluate ap-based or complex references: ['x'])\ncairo_programs/bad_programs/error_msg_attr_tempvar.cairo:4:9: Error at pc=0:2:\nAn ASSERT_EQ instruction failed: 3 != 2.\n")); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_error_msg_attr_complex_reference() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - let err = cairo_run::cairo_run( - include_bytes!("../cairo_programs/bad_programs/error_msg_attr_struct.json"), - &cairo_run_config, - &mut hint_executor, - ) - .err() - .unwrap(); - assert!(err.to_string().contains("Error message: Cats cannot have more than nine lives: {cat} (Cannot evaluate ap-based or complex references: ['cat'])")) -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_dict_store_cast_pointer() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "small", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/dict_store_cast_ptr.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_verify_signature_hint() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/common_signature.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_poseidon_builtin() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/poseidon_builtin.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_ec_op() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/ec_op.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_poseidon_hash() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/poseidon_hash.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_chained_run_ec_op() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/chained_ec_op.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_keccak_builtin() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_builtin.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_keccak_uint256() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/keccak_uint256.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -} - -#[test] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] -fn cairo_run_recover_y() { - let mut hint_executor = BuiltinHintProcessor::new_empty(); - let cairo_run_config = cairo_run::CairoRunConfig { - layout: "all_cairo", - ..cairo_vm::cairo_run::CairoRunConfig::default() - }; - cairo_run::cairo_run( - include_bytes!("../cairo_programs/recover_y.json"), - &cairo_run_config, - &mut hint_executor, - ) - .expect("Couldn't run program"); -}