def cairo_pie(): code = """ %builtins output pedersen func main(output_ptr, pedersen_ptr) -> (output_ptr, pedersen_ptr): return (output_ptr=output_ptr, pedersen_ptr=pedersen_ptr) end """ runner = get_runner_from_code(code=[(code, '')], layout='small', prime=DEFAULT_PRIME) return runner.get_cairo_pie()
def test_load_data_after_init(): code = """\ func main(): ret end """ runner = get_runner_from_code(code, layout='plain', prime=PRIME) addr = runner.segments.add() runner.load_data(addr, [42]) assert runner.vm_memory[addr] == 42
def test_small_memory_hole(): code = """\ func main(): [ap] = 0 ap += 4 [ap] = 0 ret end """ runner = get_runner_from_code(code, layout='plain', prime=PRIME) runner.check_memory_usage()
def test_missing_exit_scope(): code = """\ func main(): %{ vm_enter_scope() %} ret end """ with pytest.raises( VmExceptionBase, match=re.escape('Every enter_scope() requires a corresponding exit_scope().')): runner = get_runner_from_code(code, layout='small', prime=PRIME)
def test_bad_stop_ptr(): code = """\ %builtins output func main(output_ptr) -> (output_ptr): [ap] = 0; ap++ [ap - 1] = [output_ptr] [ap] = output_ptr + 3; ap++ # The correct return value is output_ptr + 1 ret end """ with pytest.raises( AssertionError, match='Invalid stop pointer for output. Expected: 2:1, found: 2:3'): runner = get_runner_from_code(code, layout='small', prime=PRIME)
def test_memory_hole_insufficient(): code = """\ func main(): [ap] = 0 ap += 1000 [ap] = 0 ret end """ runner = get_runner_from_code(code, layout='plain', prime=PRIME) with pytest.raises( InsufficientAllocatedCells, match=re.escape( 'There are only 8 cells to fill the memory address holes, but 999 are required.')): runner.check_memory_usage()
def run_code_in_runner(code, layout='plain'): return get_runner_from_code(code=code, layout=layout, prime=PRIME)