forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_send.py
More file actions
107 lines (92 loc) · 1.77 KB
/
Copy pathtest_send.py
File metadata and controls
107 lines (92 loc) · 1.77 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
import pytest
from pytest import (
raises,
)
from vyper import (
compiler,
)
from vyper.exceptions import (
TypeMismatchException,
)
fail_list = [
"""
@public
def foo():
send(1, 2)
""",
"""
@public
def foo():
send(1, 2)
""",
"""
@public
def foo():
send(0x1234567890123456789012345678901234567890, 2.5)
""",
"""
@public
def foo():
send(0x1234567890123456789012345678901234567890, 0x1234567890123456789012345678901234567890)
""",
"""
x: int128
@public
def foo():
send(0x1234567890123456789012345678901234567890, self.x)
""",
"""
x: wei_value
@public
def foo():
send(0x1234567890123456789012345678901234567890, self.x + 1.5)
""",
"""
x: decimal
@public
def foo():
send(0x1234567890123456789012345678901234567890, self.x)
"""
]
@pytest.mark.parametrize('bad_code', fail_list)
def test_send_fail(bad_code):
with raises(TypeMismatchException):
compiler.compile_code(bad_code)
valid_list = [
"""
x: wei_value
@public
def foo():
send(0x1234567890123456789012345678901234567890, self.x + 1)
""",
"""
x: decimal
@public
def foo():
send(0x1234567890123456789012345678901234567890, as_wei_value(floor(self.x), "wei"))
""",
"""
x: wei_value
@public
def foo():
send(0x1234567890123456789012345678901234567890, self.x)
""",
"""
@public
def foo():
send(0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe, 5)
""",
"""
# Test custom send method
@private
def send(a: address, w: wei_value):
send(0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe, 1)
@public
@payable
def foo():
self.send(msg.sender, msg.value)
"""
]
@pytest.mark.parametrize('good_code', valid_list)
def test_block_success(good_code):
assert compiler.compile_code(good_code) is not None