-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathreconstruct_traceback_test.py
65 lines (56 loc) · 1.6 KB
/
reconstruct_traceback_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pytest
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME
from starkware.cairo.lang.compiler.cairo_compile import compile_cairo
from starkware.cairo.lang.vm.cairo_runner import get_main_runner
from starkware.cairo.lang.vm.reconstruct_traceback import reconstruct_traceback
from starkware.cairo.lang.vm.vm_exceptions import VmException
def test_reconstruct_traceback():
code = """
func bar() {
assert 0 = 1;
return ();
}
func foo() {
bar();
return ();
}
func main() {
foo();
return ();
}
"""
codes = [(code, "filename")]
program_with_debug_info = compile_cairo(code=codes, prime=DEFAULT_PRIME, debug_info=True)
program_without_debug_info = compile_cairo(code=codes, prime=DEFAULT_PRIME, debug_info=False)
with pytest.raises(VmException) as exc:
get_main_runner(program=program_without_debug_info, hint_locals={}, layout="plain")
exception_str = str(exc.value)
# The exception before calling reconstruct_traceback().
assert (
exception_str
== """\
Error at pc=0:2:
An ASSERT_EQ instruction failed: 1 != 0.
Cairo traceback (most recent call last):
Unknown location (pc=0:8)
Unknown location (pc=0:5)\
"""
)
res = reconstruct_traceback(program=program_with_debug_info, traceback_txt=exception_str)
# The exception after calling reconstruct_traceback().
assert (
res
== """\
filename:3:5: Error at pc=0:2:
assert 0 = 1;
^***********^
An ASSERT_EQ instruction failed: 1 != 0.
Cairo traceback (most recent call last):
filename:13:5
foo();
^***^
filename:8:5
bar();
^***^\
"""
)