diff --git a/tests/e2e/test_cairo_010_migrate.py b/tests/e2e/test_cairo_010_migrate.py new file mode 100644 index 0000000000..7859d52e8a --- /dev/null +++ b/tests/e2e/test_cairo_010_migrate.py @@ -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 diff --git a/tests/e2e/test_cairo_010_migrate/post_010_file.cairo b/tests/e2e/test_cairo_010_migrate/post_010_file.cairo new file mode 100644 index 0000000000..602b315ab4 --- /dev/null +++ b/tests/e2e/test_cairo_010_migrate/post_010_file.cairo @@ -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); +} diff --git a/tests/e2e/test_cairo_010_migrate/pre_010_file.cairo09 b/tests/e2e/test_cairo_010_migrate/pre_010_file.cairo09 new file mode 100644 index 0000000000..fee07df00d --- /dev/null +++ b/tests/e2e/test_cairo_010_migrate/pre_010_file.cairo09 @@ -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 diff --git a/tests/e2e/test_cairo_010_migrate/pre_010_file_unsupported_migrator_syntax.cairo09 b/tests/e2e/test_cairo_010_migrate/pre_010_file_unsupported_migrator_syntax.cairo09 new file mode 100644 index 0000000000..8c859af859 --- /dev/null +++ b/tests/e2e/test_cairo_010_migrate/pre_010_file_unsupported_migrator_syntax.cairo09 @@ -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