forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_default_function.py
More file actions
96 lines (74 loc) · 2.5 KB
/
test_default_function.py
File metadata and controls
96 lines (74 loc) · 2.5 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
def test_throw_on_sending(w3, assert_tx_failed, get_contract_with_gas_estimation):
code = """
x: public(int128)
@public
def __init__():
self.x = 123
"""
c = get_contract_with_gas_estimation(code)
assert c.x() == 123
assert w3.eth.getBalance(c.address) == 0
assert_tx_failed(
lambda: w3.eth.sendTransaction({'to': c.address, 'value': w3.toWei(0.1, 'ether')})
)
assert w3.eth.getBalance(c.address) == 0
def test_basic_default(w3, get_logs, get_contract_with_gas_estimation):
code = """
Sent: event({sender: indexed(address)})
@public
@payable
def __default__():
log.Sent(msg.sender)
"""
c = get_contract_with_gas_estimation(code)
logs = get_logs(w3.eth.sendTransaction({'to': c.address, 'value': 10**17}), c, 'Sent')
assert w3.eth.accounts[0] == logs[0].args.sender
assert w3.eth.getBalance(c.address) == w3.toWei(0.1, 'ether')
def test_basic_default_default_param_function(w3, get_logs, get_contract_with_gas_estimation):
code = """
Sent: event({sender: indexed(address)})
@public
@payable
def fooBar(a: int128 = 12345) -> int128:
log.Sent(ZERO_ADDRESS)
return a
@public
@payable
def __default__():
log.Sent(msg.sender)
"""
c = get_contract_with_gas_estimation(code)
logs = get_logs(w3.eth.sendTransaction({'to': c.address, 'value': 10**17}), c, 'Sent')
assert w3.eth.accounts[0] == logs[0].args.sender
assert w3.eth.getBalance(c.address) == w3.toWei(0.1, 'ether')
def test_basic_default_not_payable(w3, assert_tx_failed, get_contract_with_gas_estimation):
code = """
Sent: event({sender: indexed(address)})
@public
def __default__():
log.Sent(msg.sender)
"""
c = get_contract_with_gas_estimation(code)
assert_tx_failed(lambda: w3.eth.sendTransaction({'to': c.address, 'value': 10**17}))
def test_multi_arg_default(assert_compile_failed, get_contract_with_gas_estimation):
code = """
@payable
@public
def __default__(arg1: int128):
pass
"""
assert_compile_failed(lambda: get_contract_with_gas_estimation(code))
def test_always_public(assert_compile_failed, get_contract_with_gas_estimation):
code = """
@private
def __default__():
pass
"""
assert_compile_failed(lambda: get_contract_with_gas_estimation(code))
def test_always_public_2(assert_compile_failed, get_contract_with_gas_estimation):
code = """
Sent: event({sender: indexed(address)})
def __default__():
log.Sent(msg.sender)
"""
assert_compile_failed(lambda: get_contract_with_gas_estimation(code))