generated from Badger-Finance/badger-strategy-mix-v1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_no_loss.py
62 lines (43 loc) · 1.51 KB
/
test_no_loss.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
import brownie
from brownie import *
from helpers.constants import MaxUint256
from helpers.SnapshotManager import SnapshotManager
from config import DEFAULT_WITHDRAWAL_FEE
MAX_BASIS = 10000
def test_is_profitable(deployed):
deployer = deployed.deployer
vault = deployed.vault
controller = deployed.controller
strategy = deployed.strategy
want = deployed.want
randomUser = accounts[6]
initial_balance = want.balanceOf(deployer)
settKeeper = accounts.at(vault.keeper(), force=True)
snap = SnapshotManager(vault, strategy, controller, "StrategySnapshot")
# Deposit
assert want.balanceOf(deployer) > 0
depositAmount = int(want.balanceOf(deployer) * 0.8)
assert depositAmount > 0
want.approve(vault.address, MaxUint256, {"from": deployer})
snap.settDeposit(depositAmount, {"from": deployer})
# Earn
with brownie.reverts("onlyAuthorizedActors"):
vault.earn({"from": randomUser})
min = vault.min()
max = vault.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 - (DEFAULT_WITHDRAWAL_FEE / 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