generated from yearn/brownie-strategy-mix
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_clone.py
133 lines (105 loc) · 3.36 KB
/
test_clone.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import pytest
from brownie import chain, Wei, reverts, Contract, ZERO_ADDRESS
def move_funds(vault, dest_vault, strategy, gov, weth, weth_whale):
print(strategy.name())
strategy.harvest({"from": gov})
assert strategy.balanceOfWant() == 0
assert strategy.valueOfInvestment() > 0
prev_value = strategy.valueOfInvestment()
weth.transfer(dest_vault, Wei("10 ether"), {"from": weth_whale})
assert strategy.valueOfInvestment() > prev_value
strategy.harvest({"from": gov})
chain.sleep(3600 * 11)
chain.mine(1)
total_gain = vault.strategies(strategy).dict()["totalGain"]
assert total_gain > 0
assert vault.strategies(strategy).dict()["totalLoss"] == 0
vault.revokeStrategy(strategy, {"from": gov})
tx = strategy.harvest({"from": gov})
total_gain += tx.events["Harvested"]["profit"]
chain.sleep(3600 * 8)
chain.mine(1)
assert vault.strategies(strategy).dict()["totalGain"] == total_gain
assert vault.strategies(strategy).dict()["totalLoss"] == 0
assert vault.strategies(strategy).dict()["totalDebt"] == 0
def test_original_strategy(
origin_vault,
destination_vault,
strategy,
strategist,
rewards,
keeper,
gov,
token,
weth_whale,
):
move_funds(origin_vault, destination_vault, strategy, gov, token, weth_whale)
def test_cloned_strategy(
origin_vault,
destination_vault,
strategy,
strategist,
rewards,
keeper,
gov,
token,
weth_whale,
):
clone_tx = strategy.cloneRouter(
origin_vault, strategist, rewards, keeper, destination_vault, "ClonedStrategy"
)
cloned_strategy = Contract.from_abi(
"Strategy", clone_tx.events["Cloned"]["clone"], strategy.abi
)
origin_vault.updateStrategyDebtRatio(strategy, 0, {"from": gov})
# Return the funds to the vault
strategy.harvest({"from": gov})
origin_vault.addStrategy(cloned_strategy, 10_000, 0, 2 ** 256 - 1, 0, {"from": gov})
move_funds(
origin_vault,
destination_vault,
cloned_strategy,
gov,
token,
weth_whale,
)
def test_clone_of_clone(
origin_vault, destination_vault, strategist, rewards, keeper, strategy
):
clone_tx = strategy.cloneRouter(
origin_vault, strategist, rewards, keeper, destination_vault, "ClonedStrategy"
)
cloned_strategy = Contract.from_abi(
"Strategy", clone_tx.events["Cloned"]["clone"], strategy.abi
)
# should not clone a clone
with reverts():
cloned_strategy.cloneRouter(
origin_vault,
strategist,
rewards,
keeper,
destination_vault,
"New Strategy",
{"from": strategist},
)
def test_double_initialize(
origin_vault, destination_vault, strategist, rewards, keeper, strategy
):
clone_tx = strategy.cloneRouter(
origin_vault, strategist, rewards, keeper, destination_vault, "ClonedStrategy"
)
cloned_strategy = Contract.from_abi(
"Strategy", clone_tx.events["Cloned"]["clone"], strategy.abi
)
# should not be able to call initialize twice
with reverts("Strategy already initialized"):
cloned_strategy.initialize(
origin_vault,
strategist,
rewards,
keeper,
destination_vault,
"name",
{"from": strategist},
)