-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtest_exchange_best_rate.py
69 lines (53 loc) · 2.13 KB
/
test_exchange_best_rate.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
import pytest
from brownie import ETH_ADDRESS, ZERO_ADDRESS
@pytest.fixture(scope="module")
def provider(AddressProvider):
yield AddressProvider.at("0x0000000022D53366457F9d5E68Ec105046FC4383")
@pytest.fixture(scope="module")
def registry_swap(Swaps, alice, provider, calculator, underlying_coins, wrapped_coins):
yield Swaps.deploy(provider, ZERO_ADDRESS, {"from": alice})
@pytest.mark.itercoins("send", "recv", underlying=True)
def test_exchange(
alice, bob, registry_swap, swap, underlying_coins, underlying_decimals, send, recv
):
amount = 10 ** underlying_decimals[send]
send = underlying_coins[send]
recv = underlying_coins[recv]
balance = bob.balance()
value = 10**18 if send == ETH_ADDRESS else 0
if send != ETH_ADDRESS:
send.approve(registry_swap, 2**256 - 1, {"from": alice})
send._mint_for_testing(alice, amount, {"from": alice})
registry_swap.exchange_with_best_rate(
send, recv, amount, 0, bob, {"from": alice, "value": value}
)
# we don't verify the amounts here, just that the expected tokens were exchanged
if send == ETH_ADDRESS:
assert alice.balance() < balance
else:
assert send.balanceOf(alice) == 0
if recv == ETH_ADDRESS:
assert bob.balance() > balance
else:
assert recv.balanceOf(bob) > 0
@pytest.mark.itercoins("send", "recv")
def test_exchange_wrapped(alice, bob, registry_swap, wrapped_coins, wrapped_decimals, send, recv):
amount = 10 ** wrapped_decimals[send]
send = wrapped_coins[send]
recv = wrapped_coins[recv]
balance = alice.balance()
value = 10**18 if send == ETH_ADDRESS else 0
if send != ETH_ADDRESS:
send.approve(registry_swap, 2**256 - 1, {"from": alice})
send._mint_for_testing(alice, amount, {"from": alice})
registry_swap.exchange_with_best_rate(
send, recv, amount, 0, bob, {"from": alice, "value": value}
)
if send == ETH_ADDRESS:
assert alice.balance() < balance
else:
assert send.balanceOf(alice) == 0
if recv == ETH_ADDRESS:
assert bob.balance() > balance
else:
assert recv.balanceOf(bob) > 0