forked from yearn/brownie-wrapper-mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_affiliate_using_live_vault.py
174 lines (142 loc) · 7.02 KB
/
test_affiliate_using_live_vault.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import brownie
import pytest
from eth_account import Account
AMOUNT = 100
def test_config_live(gov, live_token, live_vault, live_registry, live_affiliate_token):
assert live_affiliate_token.token() == live_token
assert live_affiliate_token.name() == "Affiliate " + live_token.symbol()
assert live_affiliate_token.symbol() == "af" + live_token.symbol()
assert (
live_affiliate_token.decimals()
== live_vault.decimals()
== live_token.decimals()
)
assert live_registry.numVaults(live_token) > 0
assert live_affiliate_token.bestVault() == live_vault
assert live_affiliate_token.allVaults() == [live_vault]
def test_setAffiliate_live(affiliate, live_affiliate_token, rando):
new_affiliate = rando
# No one can set affiliate but affiliate
with brownie.reverts():
live_affiliate_token.setAffiliate(new_affiliate, {"from": new_affiliate})
# Affiliate doesn't change until it's accepted
live_affiliate_token.setAffiliate(new_affiliate, {"from": affiliate})
assert live_affiliate_token.affiliate() == affiliate
# Only new affiliate can accept a change of affiliate
with brownie.reverts():
live_affiliate_token.acceptAffiliate({"from": affiliate})
# Affiliate doesn't change until it's accepted
live_affiliate_token.acceptAffiliate({"from": new_affiliate})
assert live_affiliate_token.affiliate() == new_affiliate
# No one can set affiliate but affiliate
with brownie.reverts():
live_affiliate_token.setAffiliate(new_affiliate, {"from": affiliate})
# Only new affiliate can accept a change of affiliate
with brownie.reverts():
live_affiliate_token.acceptAffiliate({"from": affiliate})
def test_setRegistry_live(
rando, affiliate, live_gov, live_affiliate_token, new_registry, gov
):
with brownie.reverts():
live_affiliate_token.setRegistry(rando, {"from": rando})
with brownie.reverts():
live_affiliate_token.setRegistry(rando, {"from": affiliate})
# Cannot set to an invalid registry
with brownie.reverts():
live_affiliate_token.setRegistry(rando, {"from": live_gov})
# yGov must be the gov on the new registry too
new_registry.setGovernance(rando, {"from": gov})
new_registry.acceptGovernance({"from": rando})
with brownie.reverts():
live_affiliate_token.setRegistry(new_registry, {"from": live_gov})
new_registry.setGovernance(live_gov, {"from": rando})
new_registry.acceptGovernance({"from": live_gov})
live_affiliate_token.setRegistry(new_registry, {"from": live_gov})
def test_deposit_live(live_token, live_vault, live_affiliate_token, live_whale, rando):
live_token.transfer(rando, 10000, {"from": live_whale})
assert live_affiliate_token.balanceOf(rando) == live_vault.balanceOf(rando) == 0
# NOTE: Must approve affiliate_token to deposit
live_token.approve(live_affiliate_token, 10000, {"from": rando})
live_affiliate_token.deposit(10000, {"from": rando})
assert live_affiliate_token.balanceOf(rando) == 10000
assert live_vault.balanceOf(rando) == 0
def test_deposit_max_live(
live_token, live_vault, live_affiliate_token, live_whale, rando
):
live_token.transfer(rando, 10000, {"from": live_whale})
assert live_affiliate_token.balanceOf(rando) == live_vault.balanceOf(rando) == 0
# NOTE: Must approve affiliate_token to deposit
live_token.approve(live_affiliate_token, 10000, {"from": rando})
live_affiliate_token.deposit({"from": rando})
assert live_affiliate_token.balanceOf(rando) == 10000
assert live_vault.balanceOf(rando) == 0
assert live_affiliate_token.totalSupply() == 10000
# NOTE: This test will fail.
# NOTE: Because the live vault is already using the most recent apiVersion, we cannot deploy and endorse a new vault for this token
"""
def test_migrate_live(live_token, live_registry, create_vault, live_affiliate_token, gov, live_gov, live_whale, rando, affiliate):
vault1 = create_vault(releaseDelta=3, token=live_token)
vault1.setGovernance(live_gov, {"from": gov})
vault1.acceptGovernance({"from": live_gov})
live_registry.newRelease(vault1, {"from": live_gov})
live_registry.endorseVault(vault1, {"from": live_gov})
live_token.transfer(rando, 10000, {"from": live_whale})
live_token.approve(live_affiliate_token, 10000, {"from": rando})
live_affiliate_token.deposit(10000, {"from": rando})
assert live_affiliate_token.balanceOf(rando) == 10000
assert vault1.balanceOf(live_affiliate_token) == 10000
vault2 = create_vault(releaseDelta=0, token=live_token)
live_registry.newRelease(vault2, {"from": live_gov})
live_registry.endorseVault(vault2, {"from": live_gov})
with brownie.reverts():
live_affiliate_token.migrate({"from": rando})
# Only affiliate can call this method
live_affiliate_token.migrate({"from": affiliate})
assert live_affiliate_token.balanceOf(rando) == 10000
assert vault1.balanceOf(live_affiliate_token) == 0
assert vault2.balanceOf(live_affiliate_token) == 10000
"""
def test_transfer_live(live_token, live_affiliate_token, live_whale, rando, affiliate):
# NOTE: Reset balance to 0
preTestBal = live_token.balanceOf(rando)
if preTestBal > 0:
live_token.transfer(live_whale, preTestBal, {"from": rando})
live_token.transfer(rando, 10000, {"from": live_whale})
live_token.approve(live_affiliate_token, 10000, {"from": rando})
live_affiliate_token.deposit(10000, {"from": rando})
# NOTE: Just using `affiliate` as a random address
live_affiliate_token.transfer(affiliate, 10000, {"from": rando})
assert live_affiliate_token.balanceOf(rando) == 0
assert live_affiliate_token.balanceOf(affiliate) == 10000
assert live_token.balanceOf(rando) == live_token.balanceOf(affiliate) == 0
def test_withdraw_live(live_token, live_affiliate_token, live_whale, rando):
# NOTE: Reset balance to 0
preTestBal = live_token.balanceOf(rando)
if preTestBal > 0:
live_token.transfer(live_whale, preTestBal, {"from": rando})
live_token.transfer(rando, 10000, {"from": live_whale})
live_token.approve(live_affiliate_token, 10000, {"from": rando})
live_affiliate_token.deposit(10000, {"from": rando})
# NOTE: Must approve affiliate_token to withdraw
live_affiliate_token.withdraw(10000, {"from": rando})
assert live_affiliate_token.balanceOf(rando) == 0
# NOTE: Potential for tiny dust loss
assert 10000 - 10 <= live_token.balanceOf(rando) <= 10000
def test_permit_live(chain, rando, live_affiliate_token, sign_token_permit):
owner = Account.create()
deadline = chain[-1].timestamp + 3600
signature = sign_token_permit(
live_affiliate_token, owner, str(rando), allowance=AMOUNT, deadline=deadline
)
assert live_affiliate_token.allowance(owner.address, rando) == 0
live_affiliate_token.permit(
owner.address,
rando,
AMOUNT,
deadline,
signature.v,
signature.r,
signature.s,
{"from": rando},
)
assert live_affiliate_token.allowance(owner.address, rando) == AMOUNT