-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0_default_test.py
133 lines (97 loc) · 5.01 KB
/
0_default_test.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
import pytest
from brownie import accounts, chain, ZERO_ADDRESS, interface
from tests.conftest import CCOW, DAI, VC, IV3Factory, isPolygon, V2Router
from brownie import reverts as revs
def test_default(isPolygon, CCOW, VC, DAI, IV3Factory):
assert isPolygon
assert CCOW.address != ZERO_ADDRESS
assert interface.IERC20(VC.address).balanceOf(accounts[-2]) > 100_000
assert interface.IERC20(DAI.address).balanceOf(accounts[-1]) > 100_000
#assert IV3Factory.owner() != ZERO_ADDRESS
# assert DAI.decimals() == 18
# assert VC.decimals() == 18
def test_happy_cow(CCOW, DAI, VC):
tempId = CCOW.tempId({'from': accounts[0]})
howMuchProjectToken = 1_000_000
howMuchDAI = 20_000
DAI.transfer(accounts[1].address, 700000*10**18, {"from": accounts[-1]})
VC.approve(CCOW.address, 100000*10**18, {"from": accounts[0]})
dealId = CCOW.createDeal(VC.address, howMuchProjectToken, howMuchDAI, 356, 356, "12345678912345678912345678900012", {'from': accounts[0]}).return_value
assert dealId > 0
deal = CCOW.getCashCowById(dealId)
assert deal[0][0] == accounts[0] #deal creator
assert deal[0][1] == ZERO_ADDRESS #deal taker - deal open
assert deal[0][2] == VC.address #proposed token
assert deal[1][0] == howMuchProjectToken * 10 ** 16 #project token amount
assert deal[1][1] == howMuchDAI * 10 ** 16 #project token amount
assert tempId < CCOW.tempId({'from': accounts[0]})
DAI.approve(CCOW.address, 1000000*10**18, {"from": accounts[1]})
pool = CCOW.takeDeal(1, {'from': accounts[1]}).return_value
assert pool != ZERO_ADDRESS
deal = CCOW.getCashCowById(1)
assert deal[0][0] == accounts[0] #deal creator
assert deal[0][1] == accounts[1] #deal taker - deal open
assert deal[0][2] == VC.address #proposed token
assert deal[0][3] == pool #vest start
assert deal[1][0] == howMuchProjectToken * 10 ** 16 #project token amount
assert deal[1][1] == howMuchDAI * 10 ** 16 #denominator token amount
assert deal[1][2] > 1 #pool token amount
assert (deal[2][1] - deal[2][0]) / 86400 == 356
assert interface.IERC20(pool).balanceOf(CCOW.address) > 100_000
with revs("Deal already taken"):
CCOW.takeDeal(1, {'from': accounts[0]})
with revs("Deal already taken"):
CCOW.takeDeal(1, {'from': accounts[5]})
with revs("Deal not found"):
CCOW.takeDeal(345345, {'from': accounts[5]})
assert interface.IERC20(pool).balanceOf(CCOW.address) > 1
assert interface.IERC721(CCOW).balanceOf(accounts[1].address) == 1
assert CCOW.balanceOf(accounts[1].address, {"from": accounts[4]}) == 1
CCOW.safeTransferFrom(accounts[1].address, accounts[4].address, 1, {'from': accounts[1]})
assert CCOW.balanceOf(accounts[1].address, {"from": accounts[4]}) == 0
assert CCOW.ownerOf(1, {"from": accounts[1]}) == accounts[4].address
with revs("Cow Interrupted"):
CCOW.reclaimNoTakers(1, {'from': accounts[1]})
CCOW.reclaimNoTakers(1, {'from': accounts[0]})
CCOW.reclaimNoTakers(1, {'from': accounts[4]})
### modifier timeElapsed(uint256)
with revs("None Found"):
CCOW.VestDeal(33, {'from': accounts[6]})
with revs("Not Owner"):
CCOW.LiquidateDeal(1, {'from': accounts[1]})
with revs("Not Ready"):
CCOW.LiquidateDeal(1, {'from': accounts[4]})
chain.sleep(356 * 86400)
chain.mine(1)
with revs("None Found"):
CCOW.VestDeal(33, {'from': accounts[6]})
with revs("Not Owner"):
CCOW.LiquidateDeal(1, {'from': accounts[1]})
assert interface.IERC20(pool).balanceOf(accounts[4].address, {"from": accounts[4]}) == 0
b0_beforeLiquidation = interface.IERC20(deal[0][2]).balanceOf(accounts[4].address, {"from": accounts[4]})
b1_beforeLiquidation = DAI.balanceOf(accounts[4].address, {"from": accounts[4]})
chain.mine(1)
chain.snapshot()
CCOW.LiquidateDeal(1, {'from': accounts[4]})
assert interface.IERC20(pool).balanceOf(accounts[4].address ) >= ( deal[1][2] // 2)
assert interface.IERC20(pool).balanceOf(accounts[0].address) >= ( deal[1][2] // 2)
chain.revert()
sfToken = interface.ISuperToken(pool)
assert sfToken.balanceOf(accounts[4].address) == 0
b1 = DAI.balanceOf(CCOW.address, {"from": accounts[4]})
b2 = VC.balanceOf(CCOW.address, {"from": accounts[4]})
x = CCOW.VestDeal(1, {'from': accounts[4]}).return_value
vest = CCOW.getVest(deal[0][2], accounts[4].address, {'from': accounts[4]})
k = CCOW.getK()
willFullVestBy = vest % k
assert willFullVestBy // deal[2][1] <= 1
milk0 = interface.IERC20(deal[0][2]).balanceOf(accounts[4].address)
y = CCOW.milkVest(1, {'from': accounts[4]}).return_value
milk1 = interface.IERC20(deal[0][2]).balanceOf(accounts[4].address)
milk0 == 0
assert x and y
milk2 = interface.IERC20(deal[0][2]).balanceOf(accounts[4].address)
assert milk2 == milk1
b3 = DAI.balanceOf(CCOW.address, {"from": accounts[4]})
b4 = VC.balanceOf(CCOW.address, {"from": accounts[4]})
assert b3 == b1_beforeLiquidation + b2