Skip to content

Commit 4fec228

Browse files
test: fix broken unitary tests
1 parent 1adb62c commit 4fec228

12 files changed

+83
-211
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from tests.utils.constants import WAD
2+
3+
COLLATERAL = 10**21
4+
DEBT = 10**18
5+
RATE = 10**11
6+
TIME_DELTA = 86400
7+
8+
9+
def test_default_behavior_no_fees(controller, market_type):
10+
expected_fee = WAD if market_type == "mint" else 0
11+
assert controller.admin_percentage() == expected_fee
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test_default_behavior_no_fees(controller):
2+
"""Naive check to make sure the function is exported, actual test is in the internal tests."""
3+
assert controller.collect_fees() == 0
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
3+
import boa
4+
5+
from tests.utils import filter_logs, max_approve
6+
from tests.utils.constants import MIN_TICKS, WAD
7+
8+
COLLATERAL = 10**21
9+
DEBT = 10**18
10+
RATE = 10**11
11+
TIME_DELTA = 86400
12+
13+
14+
@pytest.mark.parametrize("pct", range(1, 101))
15+
def test_default_behavior(
16+
controller,
17+
amm,
18+
borrowed_token,
19+
collateral_token,
20+
factory,
21+
pct,
22+
market_type,
23+
):
24+
controller.eval(f"core.admin_percentage = {WAD * pct // 100}")
25+
boa.deal(collateral_token, boa.env.eoa, COLLATERAL)
26+
max_approve(collateral_token, controller)
27+
controller.create_loan(COLLATERAL, DEBT, MIN_TICKS)
28+
29+
amm.eval(f"self.rate = {RATE}")
30+
amm.eval("self.rate_time = block.timestamp")
31+
boa.env.time_travel(TIME_DELTA)
32+
33+
expected_fees = DEBT * TIME_DELTA * RATE // 10**18 * pct // 100
34+
35+
fee_receiver = factory.fee_receiver()
36+
receiver_balance_before = borrowed_token.balanceOf(fee_receiver)
37+
controller_balance_before = borrowed_token.balanceOf(controller)
38+
39+
amount = controller.collect_fees()
40+
41+
if pct > 0:
42+
assert expected_fees > 0
43+
assert amount > 0
44+
else:
45+
assert amount == 0
46+
47+
logs = filter_logs(controller, "CollectFees")
48+
assert len(logs) == 1
49+
assert logs[0].amount == amount
50+
assert logs[0].new_supply == controller.eval("core._total_debt.initial_debt")
51+
52+
receiver_balance_after = borrowed_token.balanceOf(fee_receiver)
53+
controller_balance_after = borrowed_token.balanceOf(controller)
54+
assert receiver_balance_after - receiver_balance_before == amount
55+
assert controller_balance_before - controller_balance_after == amount
56+
57+
assert controller.admin_fees() == 0
58+
assert controller.eval("core.collected") == amount
59+
assert amount == expected_fees

tests/unitary/lending/lend_controller/test_admin_percentage_lc.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/unitary/lending/lend_controller/test_borrowed_balance_lc.py renamed to tests/unitary/lending/lend_controller/test_available_balance.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def snapshot(controller, vault):
1414
"lent": controller.lent(),
1515
"repaid": controller.repaid(),
1616
"collected": controller.collected(),
17-
"processed": controller.processed(),
1817
"asset_balance": vault.net_deposits(),
1918
}
2019

@@ -34,7 +33,7 @@ def test_increases_after_deposit(controller, vault, borrowed_token):
3433

3534
assert after["borrowed"] == before["borrowed"] + DEPOSIT
3635
assert after["asset_balance"] == before["asset_balance"] + DEBT
37-
expect_same(before, after, "lent", "repaid", "collected", "processed")
36+
expect_same(before, after, "lent", "repaid", "collected")
3837

3938

4039
def test_decreases_after_withdraw(
@@ -53,7 +52,7 @@ def test_decreases_after_withdraw(
5352

5453
assert after["borrowed"] == before["borrowed"] - DEPOSIT
5554
assert after["asset_balance"] == before["asset_balance"] - DEPOSIT
56-
expect_same(before, after, "lent", "repaid", "collected", "processed")
55+
expect_same(before, after, "lent", "repaid", "collected")
5756

5857

5958
def test_decreases_after_create(controller, vault, collateral_token):
@@ -66,7 +65,6 @@ def test_decreases_after_create(controller, vault, collateral_token):
6665

6766
assert after["borrowed"] == before["borrowed"] - DEBT
6867
assert after["lent"] == before["lent"] + DEBT
69-
assert after["processed"] == before["processed"] + DEBT
7068
expect_same(before, after, "repaid", "collected", "asset_balance")
7169

7270

@@ -81,7 +79,6 @@ def test_decreases_after_borrow_more(controller, vault, collateral_token):
8179

8280
assert after["borrowed"] == before["borrowed"] - DEBT
8381
assert after["lent"] == before["lent"] + DEBT
84-
assert after["processed"] == before["processed"] + DEBT
8582
expect_same(before, after, "repaid", "collected", "asset_balance")
8683

8784

@@ -97,7 +94,7 @@ def test_increases_after_repay(controller, vault, collateral_token, borrowed_tok
9794

9895
assert after["borrowed"] == before["borrowed"] + DEBT
9996
assert after["repaid"] == before["repaid"] + DEBT
100-
expect_same(before, after, "lent", "collected", "asset_balance", "processed")
97+
expect_same(before, after, "lent", "collected", "asset_balance")
10198

10299

103100
def test_collect_fees_reduces_balance(
@@ -128,5 +125,4 @@ def test_collect_fees_reduces_balance(
128125
assert amount > 0
129126
assert after["collected"] == before["collected"] + amount
130127
assert after["borrowed"] == before["borrowed"] - amount
131-
assert after["processed"] == after["repaid"] + controller.total_debt()
132128
expect_same(before, after, "lent", "repaid", "asset_balance")

tests/unitary/lending/lend_controller/test_borrow_more_lc.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/unitary/lending/lend_controller/test_collect_fees_lc.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

tests/unitary/lending/lend_controller/test_create_loan_lc.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/unitary/lending/lend_controller/test_set_admin_fee_lc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
@pytest.mark.parametrize("new_fee", [0, WAD // 2])
99
def test_default_behavior(admin, controller, new_fee):
1010
controller.set_admin_percentage(new_fee, sender=admin)
11-
logs = filter_logs(controller, "SetAdminFee")
12-
assert len(logs) == 1 and logs[-1].admin_fee == new_fee
13-
assert controller.admin_fee() == new_fee
11+
logs = filter_logs(controller, "SetAdminPercentage")
12+
assert len(logs) == 1 and logs[-1].admin_percentage == new_fee
13+
assert controller.admin_percentage() == new_fee
1414

1515

1616
def test_more_than_max(admin, controller):
17-
with boa.reverts(dev="admin fee higher than 100%"):
17+
with boa.reverts(dev="admin percentage higher than 100%"):
1818
controller.set_admin_percentage(WAD + 1, sender=admin)
1919

2020

tests/unitary/lending/vault/test_convert_to_assets_v.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO test isn't rigorous enough
12
def test_convert_to_assets(vault, controller, amm, make_debt):
23
"""Test _convert_to_assets with is_floor=True and False."""
34
shares = 100 * 10**18

0 commit comments

Comments
 (0)