forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bytes.py
More file actions
110 lines (102 loc) · 1.74 KB
/
test_bytes.py
File metadata and controls
110 lines (102 loc) · 1.74 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pytest
from pytest import (
raises,
)
from vyper import (
compiler,
)
from vyper.exceptions import (
InvalidLiteralException,
TypeMismatchException,
)
fail_list = [
"""
@public
def baa():
x: bytes[50]
y: bytes[50]
z = x + y
""",
"""
@public
def baa():
x: bytes[50]
y: int128
y = x
""",
"""
@public
def baa():
x: bytes[50]
y: int128
x = y
""",
"""
@public
def baa():
x: bytes[50]
y: bytes[60]
x = y
""",
"""
@public
def foo(x: bytes[100]) -> bytes[75]:
return x
""",
"""
@public
def foo(x: bytes[100]) -> int128:
return x
""",
"""
@public
def foo(x: int128) -> bytes[75]:
return x
""",
"""
@public
def foo() -> bytes[10]:
x: bytes[10] = '0x1234567890123456789012345678901234567890'
x = 0x1234567890123456789012345678901234567890
return x
""",
"""
@public
def foo() -> bytes[10]:
return "badmintonzz"
""",
("""
@public
def test() -> bytes[1]:
a: bytes[1] = 0b0000001 # needs mutliple of 8 bits.
return a
""", InvalidLiteralException)
]
@pytest.mark.parametrize('bad_code', fail_list)
def test_bytes_fail(bad_code):
if isinstance(bad_code, tuple):
with raises(bad_code[1]):
compiler.compile_code(bad_code[0])
else:
with raises(TypeMismatchException):
compiler.compile_code(bad_code)
valid_list = [
"""
@public
def foo(x: bytes[100]) -> bytes[100]:
return x
""",
"""
@public
def foo(x: bytes[100]) -> bytes[150]:
return x
""",
"""
@public
def baa():
x: bytes[50]
"""
]
@pytest.mark.parametrize('good_code', valid_list)
def test_bytes_success(good_code):
assert compiler.compile_code(good_code) is not None