generated from Badger-Finance/badger-strategy-mix-v1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_profitable.py
69 lines (50 loc) · 1.66 KB
/
test_profitable.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 brownie
from brownie import *
from helpers.constants import MaxUint256
from helpers.SnapshotManager import SnapshotManager
from config import sett_config, FEES
import pytest
from conftest import deploy
MAX_BASIS = 10000
@pytest.mark.parametrize(
"sett_id",
sett_config.native,
)
def test_is_profitable(sett_id):
deployed = deploy(sett_config.native[sett_id])
deployer = deployed.deployer
sett = deployed.sett
controller = deployed.controller
strategy = deployed.strategy
want = deployed.want
randomUser = accounts[6]
initial_balance = want.balanceOf(deployer)
settKeeper = accounts.at(sett.keeper(), force=True)
snap = SnapshotManager(sett, strategy, controller, "StrategySnapshot")
# Deposit
assert want.balanceOf(deployer) > 0
depositAmount = int(want.balanceOf(deployer) * 0.8)
assert depositAmount > 0
want.approve(sett.address, MaxUint256, {"from": deployer})
snap.settDeposit(depositAmount, {"from": deployer})
# Earn
with brownie.reverts("onlyAuthorizedActors"):
sett.earn({"from": randomUser})
min = sett.min()
max = sett.max()
remain = max - min
snap.settEarn({"from": settKeeper})
chain.sleep(15)
chain.mine(1)
snap.settWithdrawAll({"from": deployer})
ending_balance = want.balanceOf(deployer)
initial_balance_with_fees = initial_balance * (
1 - (strategy.withdrawalFee() / MAX_BASIS)
)
print("Initial Balance")
print(initial_balance)
print("initial_balance_with_fees")
print(initial_balance_with_fees)
print("Ending Balance")
print(ending_balance)
assert ending_balance > initial_balance_with_fees