-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #772 Co-authored-by: Marek Kaput <[email protected]>
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
tests/e2e/test_cairo_010_migrate/pre_010_file_unsupported_migrator_syntax.cairo09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |