diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a5ad33da79..0586acd465 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -88,4 +88,5 @@ jobs: - name: Upload coverage to codecov.io uses: codecov/codecov-action@v3 with: + token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true diff --git a/src/hint_processor/hint_processor_utils.rs b/src/hint_processor/hint_processor_utils.rs index 407796a7af..431c64790f 100644 --- a/src/hint_processor/hint_processor_utils.rs +++ b/src/hint_processor/hint_processor_utils.rs @@ -217,6 +217,32 @@ mod tests { ); } + #[test] + fn get_offset_value_reference_valid() { + let mut vm = vm!(); + vm.memory = memory![((1, 0), 0)]; + let mut hint_ref = HintReference::new(0, 0, false, true); + hint_ref.offset1 = OffsetValue::Reference(Register::FP, 2_i32, false); + + assert_eq!( + get_offset_value_reference(&vm, &hint_ref, &ApTracking::new(), &hint_ref.offset1), + Ok(mayberelocatable!(1, 2)) + ); + } + + #[test] + fn get_offset_value_reference_invalid() { + let mut vm = vm!(); + vm.memory = memory![((1, 0), 0)]; + let mut hint_ref = HintReference::new(0, 0, false, true); + hint_ref.offset1 = OffsetValue::Reference(Register::FP, -2_i32, false); + + assert_eq!( + get_offset_value_reference(&vm, &hint_ref, &ApTracking::new(), &hint_ref.offset1), + Err(HintError::FailedToGetIds) + ); + } + #[test] fn get_ptr_from_reference_short_path() { let mut vm = vm!(); @@ -287,6 +313,19 @@ mod tests { ); } + #[test] + fn tracking_correction_valid() { + let mut ref_ap_tracking = ApTracking::new(); + ref_ap_tracking.group = 1; + let mut hint_ap_tracking = ApTracking::new(); + hint_ap_tracking.group = 1; + + assert_eq!( + apply_ap_tracking_correction(&relocatable!(1, 0), &ref_ap_tracking, &hint_ap_tracking), + Ok(relocatable!(1, 0)) + ); + } + #[test] fn tracking_correction_invalid_group() { let mut ref_ap_tracking = ApTracking::new(); diff --git a/src/types/instruction.rs b/src/types/instruction.rs index b9807955b5..f6f7590d23 100644 --- a/src/types/instruction.rs +++ b/src/types/instruction.rs @@ -116,4 +116,12 @@ mod tests { let encoded_instruction = Felt::new(4612671187288031229_i64); assert!(!is_call_instruction(&encoded_instruction, None)); } + + #[test] + fn instruction_size() { + let encoded_instruction = Felt::new(1226245742482522112_i64); + let instruction = + decode_instruction(encoded_instruction.to_i64().unwrap(), Some(&Felt::new(2))).unwrap(); + assert_eq!(instruction.size(), 2); + } } diff --git a/src/vm/runners/builtin_runner/output.rs b/src/vm/runners/builtin_runner/output.rs index 3bc78f6060..ac9ab26f39 100644 --- a/src/vm/runners/builtin_runner/output.rs +++ b/src/vm/runners/builtin_runner/output.rs @@ -359,4 +359,60 @@ mod tests { vm.segments.segment_used_sizes = Some(vec![4]); assert_eq!(builtin.get_used_cells(&vm.segments), Ok(4)); } + + #[test] + fn test_get_used_instances_missing_segments() { + let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); + let memory_segment_manager = MemorySegmentManager::new(); + + assert_eq!( + builtin.get_used_instances(&memory_segment_manager), + Err(MemoryError::MissingSegmentUsedSizes) + ); + } + + #[test] + fn test_get_used_instances_valid() { + let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); + let mut memory_segment_manager = MemorySegmentManager::new(); + memory_segment_manager.segment_used_sizes = Some(vec![0]); + + assert_eq!(builtin.get_used_instances(&memory_segment_manager), Ok(0)); + } + + #[test] + fn test_deduce_memory_cell_output_builtin() { + let builtin = BuiltinRunner::Output(OutputBuiltinRunner::new(true)); + let mut vm = vm!(); + + vm.memory = memory![ + ((0, 0), (0, 0)), + ((0, 1), (0, 1)), + ((2, 0), (0, 0)), + ((2, 1), 2) + ]; + + vm.segments.segment_used_sizes = Some(vec![0]); + + let pointer = Relocatable::from((2, 2)); + + assert_eq!(builtin.deduce_memory_cell(&pointer, &vm.memory), Ok(None)); + } + + #[test] + fn test_add_validation_rule() { + let builtin = OutputBuiltinRunner::new(true); + let mut vm = vm!(); + + vm.memory = memory![ + ((0, 0), (0, 0)), + ((0, 1), (0, 1)), + ((2, 0), (0, 0)), + ((2, 1), 2) + ]; + + vm.segments.segment_used_sizes = Some(vec![0]); + + assert_eq!(builtin.add_validation_rule(&mut vm.memory), Ok(())); + } } diff --git a/src/vm/runners/builtin_runner/range_check.rs b/src/vm/runners/builtin_runner/range_check.rs index 6239c7af13..0016ee71f0 100644 --- a/src/vm/runners/builtin_runner/range_check.rs +++ b/src/vm/runners/builtin_runner/range_check.rs @@ -512,6 +512,18 @@ mod tests { ); } + #[test] + fn test_base() { + let builtin = RangeCheckBuiltinRunner::new(8, 8, true); + assert_eq!(builtin.base(), 0); + } + + #[test] + fn test_ratio() { + let builtin = RangeCheckBuiltinRunner::new(8, 8, true); + assert_eq!(builtin.ratio(), 8); + } + #[test] fn get_used_cells_missing_segment_used_sizes() { let builtin = BuiltinRunner::RangeCheck(RangeCheckBuiltinRunner::new(256, 8, true)); diff --git a/src/vm/runners/builtin_runner/signature.rs b/src/vm/runners/builtin_runner/signature.rs index 395bc6abe2..886d907cad 100644 --- a/src/vm/runners/builtin_runner/signature.rs +++ b/src/vm/runners/builtin_runner/signature.rs @@ -281,6 +281,27 @@ mod tests { }, }; + #[test] + fn get_used_cells_and_allocated_size_error() { + let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); + let mut vm = vm!(); + vm.current_step = 100; + vm.segments.segment_used_sizes = Some(vec![1]); + assert_eq!( + builtin.get_used_cells_and_allocated_size(&vm), + Err(MemoryError::InsufficientAllocatedCells) + ); + } + + #[test] + fn get_used_cells_and_allocated_size_valid() { + let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::new(10), true); + let mut vm = vm!(); + vm.current_step = 110; + vm.segments.segment_used_sizes = Some(vec![1]); + assert_eq!(builtin.get_used_cells_and_allocated_size(&vm), Ok((1, 22))); + } + #[test] fn initialize_segments_for_ecdsa() { let mut builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); @@ -487,4 +508,31 @@ mod tests { let result = builtin.deduce_memory_cell(&Relocatable::from((0, 5)), &memory); assert_eq!(result, Ok(None)); } + + #[test] + fn test_ratio() { + let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); + assert_eq!(builtin.ratio(), 512); + } + + #[test] + fn test_base() { + let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); + assert_eq!(builtin.base(), 0); + } + + #[test] + fn test_get_memory_segment_addresses() { + let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); + + assert_eq!(builtin.get_memory_segment_addresses(), (0, None)); + } + + #[test] + fn deduce_memory_cell() { + let memory = Memory::new(); + let builtin = SignatureBuiltinRunner::new(&EcdsaInstanceDef::default(), true); + let result = builtin.deduce_memory_cell(&Relocatable::from((0, 5)), &memory); + assert_eq!(result, Ok(None)); + } }