-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_clone.py
57 lines (45 loc) · 2.02 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
import pytest
from brownie import chain, Wei, reverts, Contract, ZERO_ADDRESS
import pytest
import web3
def test_clone_strategy(
chain, accounts, token, vault, user, standalone_strategy, strategist, amount,
RELATIVE_APPROX, tweth, gov, trade_factory, utils, ymechs_safe
):
clone_tx = standalone_strategy.cloneTokemakWeth(vault, strategist, {"from": strategist})
cloned_strategy = Contract.from_abi(
"Strategy", clone_tx.events["Cloned"]["clone"], standalone_strategy.abi
)
vault.addStrategy(cloned_strategy, 10_000, 0, 2 ** 256 - 1, 1_000, {"from": gov})
utils.prepare_trade_factory(cloned_strategy, trade_factory, ymechs_safe, gov)
# Deposit to the vault
# Deposit to the vault
user_balance_before = token.balanceOf(user)
utils.move_user_funds_to_vault(user, vault, token, amount)
# harvest
chain.sleep(1)
cloned_strategy.harvest({"from": strategist})
assert pytest.approx(cloned_strategy.estimatedTotalAssets(), rel=RELATIVE_APPROX) == amount
assert pytest.approx(tweth.balanceOf(cloned_strategy), rel=RELATIVE_APPROX) == amount
# tend()
cloned_strategy.tend({"from": strategist})
def test_clone_of_clone(
vault, strategy, strategist, trade_factory, ymechs_safe, utils
):
clone_tx = strategy.cloneTokemakWeth(vault, strategist, {"from": strategist})
cloned_strategy = Contract.from_abi(
"Strategy", clone_tx.events["Cloned"]["clone"], strategy.abi
)
# should not clone a clone
with reverts():
cloned_strategy.cloneTokemakWeth(vault, strategist, {"from": strategist})
def test_double_initialize(
vault, strategy, strategist, trade_factory, ymechs_safe, gov
):
clone_tx = strategy.cloneTokemakWeth(vault, strategist, {"from": strategist})
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(vault, strategist, {"from": strategist})