generated from yearn/brownie-strategy-mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_shutdown.py
63 lines (47 loc) · 2.02 KB
/
test_shutdown.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
# TODO: Add tests that show proper operation of this strategy through "emergencyExit"
# Make sure to demonstrate the "worst case losses" as well as the time it takes
from brownie import ZERO_ADDRESS
import pytest
def test_vault_shutdown_can_withdraw(
chain, token, vault, strategy, user, amount, RELATIVE_APPROX
):
## Deposit in Vault
token.approve(vault.address, amount, {"from": user})
vault.deposit(amount, {"from": user})
assert token.balanceOf(vault.address) == amount
if token.balanceOf(user) > 0:
token.transfer(ZERO_ADDRESS, token.balanceOf(user), {"from": user})
# Harvest 1: Send funds through the strategy
strategy.harvest()
chain.sleep(3600 * 7)
chain.mine(1)
assert pytest.approx(strategy.estimatedTotalAssets(), rel=RELATIVE_APPROX) == amount
## Set Emergency
vault.setEmergencyShutdown(True)
## Withdraw (does it work, do you get what you expect)
vault.withdraw({"from": user})
assert pytest.approx(token.balanceOf(user), rel=RELATIVE_APPROX) == amount
def test_basic_shutdown(
chain, token, vault, strategy, user, strategist, amount, RELATIVE_APPROX
):
# Deposit to the vault
token.approve(vault.address, amount, {"from": user})
vault.deposit(amount, {"from": user})
assert token.balanceOf(vault.address) == amount
# Harvest 1: Send funds through the strategy
strategy.harvest()
chain.mine(100)
assert pytest.approx(strategy.estimatedTotalAssets(), rel=RELATIVE_APPROX) == amount
## Earn interest
chain.sleep(3600 * 24 * 1) ## Sleep 1 day
chain.mine(1)
# Harvest 2: Realize profit
strategy.harvest()
chain.sleep(3600 * 6) # 6 hrs needed for profits to unlock
chain.mine(1)
## Set emergency
strategy.setEmergencyExit({"from": strategist})
strategy.harvest() ## Remove funds from strategy
assert token.balanceOf(strategy) == 0
assert token.balanceOf(vault) >= amount ## The vault has all funds
## NOTE: May want to tweak this based on potential loss during migration