forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_addmod.py
90 lines (68 loc) · 1.93 KB
/
test_addmod.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
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
def test_uint256_addmod(tx_failed, get_contract_with_gas_estimation):
uint256_code = """
@external
def _uint256_addmod(x: uint256, y: uint256, z: uint256) -> uint256:
return uint256_addmod(x, y, z)
"""
c = get_contract_with_gas_estimation(uint256_code)
assert c._uint256_addmod(1, 2, 2) == 1
assert c._uint256_addmod(32, 2, 32) == 2
assert c._uint256_addmod((2**256) - 1, 0, 2) == 1
assert c._uint256_addmod(2**255, 2**255, 6) == 4
with tx_failed():
c._uint256_addmod(1, 2, 0)
def test_uint256_addmod_ext_call(
w3, side_effects_contract, assert_side_effects_invoked, get_contract
):
code = """
interface Foo:
def foo(x: uint256) -> uint256: payable
@external
def foo(f: Foo) -> uint256:
return uint256_addmod(32, 2, extcall f.foo(32))
"""
c1 = side_effects_contract("uint256")
c2 = get_contract(code)
assert c2.foo(c1.address) == 2
assert_side_effects_invoked(c1, lambda: c2.foo(c1.address, transact={}))
def test_uint256_addmod_internal_call(get_contract_with_gas_estimation):
code = """
@external
def foo() -> uint256:
return uint256_addmod(self.a(), self.b(), self.c())
@internal
def a() -> uint256:
return 32
@internal
def b() -> uint256:
return 2
@internal
def c() -> uint256:
return 32
"""
c = get_contract_with_gas_estimation(code)
assert c.foo() == 2
def test_uint256_addmod_evaluation_order(get_contract_with_gas_estimation):
code = """
a: uint256
@external
def foo1() -> uint256:
self.a = 0
return uint256_addmod(self.a, 1, self.bar())
@external
def foo2() -> uint256:
self.a = 0
return uint256_addmod(self.a, self.bar(), 3)
@external
def foo3() -> uint256:
self.a = 0
return uint256_addmod(1, self.a, self.bar())
@internal
def bar() -> uint256:
self.a = 1
return 2
"""
c = get_contract_with_gas_estimation(code)
assert c.foo1() == 1
assert c.foo2() == 2
assert c.foo3() == 1