Skip to content

Commit

Permalink
Add e2e cairo-migrate tests (#809)
Browse files Browse the repository at this point in the history
Closes #772

Co-authored-by: Marek Kaput <[email protected]>
  • Loading branch information
Arcticae and mkaput committed Sep 12, 2022
1 parent d453d21 commit a24ee37
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/e2e/test_cairo_010_migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from distutils.file_util import copy_file
from pathlib import Path
from subprocess import CalledProcessError

import pytest


@pytest.mark.usefixtures("init")
def test_migrating_file_to_010(
protostar, datadir: Path
):
copy_file(
src=str(datadir / "pre_010_file.cairo09"),
dst="./src/main.cairo",
)

protostar(
["cairo-migrate", "src"]
)

assert Path("src/main.cairo").read_text() == (datadir / "post_010_file.cairo").read_text()


@pytest.mark.usefixtures("init")
def test_failing_migrate_to_010(
protostar, datadir: Path
):
copy_file(
src=str(datadir / "pre_010_file_unsupported_migrator_syntax.cairo09"),
dst="./src/main.cairo",
)

output = protostar(["cairo-migrate", "src"], expect_exit_code=1)

assert "Migrate exception" in output
assert "Comments inside expressions are not supported" in output
20 changes: 20 additions & 0 deletions tests/e2e/test_cairo_010_migrate/post_010_file.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin

@storage_var
func storage_felt() -> (res: felt) {
}

@external
func set_var{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(val: felt) {
storage_felt.write(val);

return ();
}

@view
func view_val{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (res: felt) {
let (val_now) = storage_felt.read();
return (res=val_now);
}
29 changes: 29 additions & 0 deletions tests/e2e/test_cairo_010_migrate/pre_010_file.cairo09
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin

@storage_var
func storage_felt() -> (res: felt):
end

@external
func set_var{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
}(val: felt):
storage_felt.write(val)

return ()
end


@view
func view_val{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
}() -> (res: felt):
let (val_now) = storage_felt.read()
return (res=val_now)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin

@external
func set_var{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
}(val: felt):
storage_felt.write(
val # This is a comment which will crash auto-formatter
)

return ()
end

0 comments on commit a24ee37

Please sign in to comment.