def test_cairo_pie_memory_invalid_address(cairo_pie: CairoPie): # Write to an invalid address. cairo_pie.memory[RelocatableValue( segment_index=cairo_pie.metadata.ret_pc_segment.index, offset=0)] = 0 with pytest.raises( AssertionError, match='Invalid memory cell address.'): cairo_pie.run_validity_checks()
def test_cairo_pie_memory_negative_address(cairo_pie: CairoPie): # Write to a negative address. cairo_pie.memory.set_without_checks(RelocatableValue( segment_index=cairo_pie.metadata.program_segment.index, offset=-5), 0) with pytest.raises( AssertionError, match='Invalid memory cell address.'): cairo_pie.run_validity_checks()
def test_cairo_pie_memory_invalid_value(cairo_pie: CairoPie): # Write a value after the execution segment. output_end = RelocatableValue( segment_index=cairo_pie.metadata.execution_segment.index, offset=cairo_pie.metadata.execution_segment.size) cairo_pie.memory[output_end] = output_end + 2 # It should fail because the address is outside the segment expected size. with pytest.raises( AssertionError, match='Invalid memory cell address.'): cairo_pie.run_validity_checks() # Increase the size. cairo_pie.metadata.execution_segment.size += 1 # Now it should fail because of the value. with pytest.raises(AssertionError, match='Invalid memory cell value.'): cairo_pie.run_validity_checks()
def test_cairo_pie_validity_invalid_builtin_list_execution_resources(cairo_pie: CairoPie): cairo_pie.execution_resources.builtin_instance_counter['tmp_builtin'] = \ cairo_pie.execution_resources.builtin_instance_counter['output_builtin'] with pytest.raises( AssertionError, match='Builtin list mismatch in execution_resources.'): cairo_pie.run_validity_checks()
def test_cairo_pie_validity_invalid_builtin_segments(cairo_pie: CairoPie): cairo_pie.metadata.builtin_segments['tmp'] = cairo_pie.metadata.builtin_segments['output'] with pytest.raises( AssertionError, match='Builtin list mismatch in builtin_segments.'): cairo_pie.run_validity_checks()
def test_cairo_pie_validity_invalid_builtin_list(cairo_pie: CairoPie): cairo_pie.program.builtins.append('output') with pytest.raises( AssertionError, match='Invalid builtin list.'): cairo_pie.run_validity_checks()
def test_cairo_pie_validity_invalid_program_size(cairo_pie: CairoPie): cairo_pie.metadata.program_segment.size += 1 with pytest.raises( AssertionError, match='Program length does not match the program segment size.'): cairo_pie.run_validity_checks()