-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtest_exchanges.py
86 lines (67 loc) · 2.87 KB
/
test_exchanges.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
import brownie
import pytest
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
@pytest.fixture(scope="module", autouse=True)
def initial_approvals(registry_swap, alice, underlying_coins):
for coin in underlying_coins:
if coin != "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
coin.approve(registry_swap, 2**256 - 1, {"from": alice})
@pytest.mark.itercoins("send", "recv", underlying=True)
def test_exchange(alice, registry_swap, swap, underlying_coins, underlying_decimals, send, recv):
amount = 10 ** underlying_decimals[send]
send = underlying_coins[send]
recv = underlying_coins[recv]
balance = alice.balance()
if send == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
value = 10**18
else:
send._mint_for_testing(alice, amount, {"from": alice})
value = 0
registry_swap.exchange(swap, send, recv, amount, 0, {"from": alice, "value": value})
# we don't verify the amounts here, just that the expected tokens were exchanged
if send == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
assert alice.balance() < balance
else:
assert send.balanceOf(alice) == 0
if recv == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
assert alice.balance() > balance
else:
assert recv.balanceOf(alice) > 0
@pytest.mark.itercoins("send", "recv")
def test_exchange_wrapped(alice, registry_swap, swap, wrapped_coins, wrapped_decimals, send, recv):
amount = 10 ** wrapped_decimals[send]
send = wrapped_coins[send]
recv = wrapped_coins[recv]
balance = alice.balance()
if send == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
value = 10**18
else:
send._mint_for_testing(alice, amount, {"from": alice})
value = 0
registry_swap.exchange(swap, send, recv, amount, 0, {"from": alice, "value": value})
if send == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
assert alice.balance() < balance
else:
assert send.balanceOf(alice) == 0
if recv == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
assert alice.balance() > balance
else:
assert recv.balanceOf(alice) > 0
@pytest.mark.itercoins("send", "recv", underlying=True)
def test_min_expected(
alice, registry_swap, swap, underlying_coins, underlying_decimals, send, recv
):
# exchange should revert when `expected` is higher than received amount
amount = 10 ** underlying_decimals[send]
send = underlying_coins[send]
recv = underlying_coins[recv]
if send == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE":
value = 10**18
else:
send._mint_for_testing(alice, amount, {"from": alice})
value = 0
expected = registry_swap.get_exchange_amount(swap, send, recv, amount)
with brownie.reverts():
registry_swap.exchange(
swap, send, recv, amount, expected + 1, {"from": alice, "value": value}
)