From 9aa95cf0648b5d65e27ca252f94d20336637f643 Mon Sep 17 00:00:00 2001 From: Tomasz Rejowski <34059895+Arcticae@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:02:45 +0200 Subject: [PATCH] Add e2e cairo-migrate tests (#809) Closes #772 Co-authored-by: Marek Kaput --- tests/e2e/test_cairo_010_migrate.py | 36 +++++++++++++++++++ .../post_010_file.cairo | 20 +++++++++++ .../pre_010_file.cairo09 | 29 +++++++++++++++ ...0_file_unsupported_migrator_syntax.cairo09 | 16 +++++++++ 4 files changed, 101 insertions(+) create mode 100644 tests/e2e/test_cairo_010_migrate.py create mode 100644 tests/e2e/test_cairo_010_migrate/post_010_file.cairo create mode 100644 tests/e2e/test_cairo_010_migrate/pre_010_file.cairo09 create mode 100644 tests/e2e/test_cairo_010_migrate/pre_010_file_unsupported_migrator_syntax.cairo09 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