-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmasterChefV2.js
More file actions
241 lines (188 loc) · 9.74 KB
/
masterChefV2.js
File metadata and controls
241 lines (188 loc) · 9.74 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// const ether = require("@openzeppelin/test-helpers/src/ether");
const {expect} = require("chai")
const {ethers} = require("hardhat")
describe("Masterchef : ", function(){
let signer;
let masterchef;
let cake;
let syrup;
let lpToken1;
let lpToken2;
let initialSigner;
let initialMasterchef;
let finalSigner;
let finalMasterchef;
let initialCake;
let finalCake;
let initialSyrup;
let finalSyrup;
async function _deposit(){
await masterchef.add(100,lpToken1.target,true);
await lpToken1.connect(signer[0]).approve(masterchef.target,1000);
await masterchef.connect(signer[0]).deposit(1,500);
}
async function _beforeStaking(){
await _deposit();
await masterchef.connect(signer[0]).withdraw(1,500);
}
beforeEach(async() =>{
signer = await ethers.getSigners();
// console.log("Signer address : ",signer[0].address);
let Cake = await ethers.getContractFactory("CakeToken");
cake = await Cake.connect(signer[0]).deploy();
// console.log("Cake address : ",cake.target);
let Syrup = await ethers.getContractFactory("SyrupBar");
syrup = await Syrup.connect(signer[0]).deploy(cake.target);
// console.log("SyrupBar address : ",syrup.target);
let MasterChef = await ethers.getContractFactory("MasterChef");
masterchef = await MasterChef.connect(signer[0]).deploy(cake.target,syrup.target,signer[1].address,1000,10);
// console.log("Masterchef address : ",masterchef.target);
let LpToken1 = await ethers.getContractFactory("MockBEP20");
lpToken1 = await LpToken1.connect(signer[0]).deploy("lpToken1","LP2",ethers.parseEther("100000"));
// console.log("LpToken1 address : ",lpToken1.target);
lpToken2 = await LpToken1.connect(signer[0]).deploy("lpToken2","LP2",ethers.parseEther("100000"));
// console.log("lpToken2 address : ",lpToken2.target);
await cake.transferOwnership(masterchef.target);
await syrup.transferOwnership(masterchef.target);
//deposit again works only after transfer of ownership to masterchef contract
})
it("Important Addresses : ",async()=>{
console.log("Signer address : ",signer[0].address);
console.log("Cake address : ",cake.target);
console.log("SyrupBar address : ",syrup.target);
console.log("Masterchef address : ",masterchef.target);
console.log("LpToken1 address : ",lpToken1.target);
console.log("lpToken2 address : ",lpToken2.target);
})
it("add function : ",async()=>{
console.log("inside add function")
await masterchef.add(100,lpToken1.target,true);
console.log("pool length ", await masterchef.poolLength())
await masterchef.add(200,lpToken2.target,true);
console.log("pool length ", await masterchef.poolLength())
expect(await masterchef.poolLength()).to.be.equal(3n)
})
it("Deposit Function : ",async()=>{
await masterchef.add(1000,lpToken1.target,true);
console.log("BEFORE DEPOSIT")
initialSigner = await lpToken1.balanceOf(signer[0].address);
initialMasterchef = await lpToken1.balanceOf(masterchef.target);
console.log("lpToken1 balance of signer : ",initialSigner)
console.log("lpToken1 balance of masterchef : ",initialMasterchef)
await lpToken1.connect(signer[0]).approve(masterchef.target,900);
await masterchef.connect(signer[0]).deposit(1,200);
await masterchef.connect(signer[0]).deposit(1,200);
console.log("AFTER DEPOSIT")
finalSigner = await lpToken1.balanceOf(signer[0].address);
finalMasterchef = await lpToken1.balanceOf(masterchef.target);
console.log("lpToken1 balance of signer : ",finalSigner)
console.log("lpToken1 balance of masterchef : ",finalMasterchef)
expect(initialSigner).to.be.greaterThan(finalSigner);
expect(finalMasterchef).to.be.greaterThan(initialMasterchef);
expect(finalMasterchef).to.be.equal(400);
})
it("Deposit Function for error check : ",async()=>{
await masterchef.add(1000,lpToken1.target,true);
await lpToken1.connect(signer[0]).approve(masterchef.target,900);
await expect(masterchef.connect(signer[0]).deposit(0,200)).to.be.revertedWith('deposit CAKE by staking');
//using _pid = 0 to give and check error
})
it.only("Withdraw Function : ",async()=>{
await _deposit();
console.log("AFTER DEPOSIT")
initialCake = await cake.balanceOf(signer[0].address);
initialSigner = await lpToken1.balanceOf(signer[0].address);
initialMasterchef = await lpToken1.balanceOf(masterchef.target);
console.log("Cake balance of signer : ",initialCake);
console.log("lpToken1 balance of signer : ",initialSigner)
console.log("lpToken1 balance of masterchef : ",initialMasterchef)
await masterchef.connect(signer[0]).withdraw(1,200);
console.log("AFTER WITHDRAW")
finalCake = await cake.balanceOf(signer[0].address);
finalSigner = await lpToken1.balanceOf(signer[0].address);
finalMasterchef = await lpToken1.balanceOf(masterchef.target);
console.log("Cake balance of signer : ",finalCake)
console.log("lpToken1 balance of signer : ",finalSigner)
console.log("lpToken1 balance of masterchef : ",finalMasterchef)
expect(finalCake).to.be.greaterThan(initialCake);
// expect(finalCake).to.be.equal(initialCake);
expect(finalSigner).to.be.greaterThan(initialSigner);
expect(initialMasterchef).to.be.greaterThan(finalMasterchef);
})
it("Witdraw Function for error 1 check : ",async()=>{
await _deposit();
await expect(masterchef.connect(signer[0]).withdraw(0,100)).to.be.revertedWith('withdraw CAKE by unstaking');
//using _pid = 0 to give and check error
})
it("Witdraw Function for error 2 check : ",async()=>{
await _deposit();
await expect(masterchef.connect(signer[0]).withdraw(1,1000)).to.be.revertedWith('withdraw: not good');
//using _pid = 0 to give and check error
})
it("EnterStaking Function : ",async()=>{
await _beforeStaking();
console.log("BEFORE ENTERSTAKING")
initialCake = await cake.balanceOf(signer[0].address);
initialSyrup = await syrup.balanceOf(signer[0].address);
console.log("Cake balance of signer : ",initialCake);
console.log("Syrup balance of signer : ",initialSyrup);
await cake.connect(signer[0]).approve(masterchef.target,1000);
await masterchef.connect(signer[0]).enterStaking(500);
console.log("AFTER ENTERSTAKING")
finalCake = await cake.balanceOf(signer[0].address);
finalSyrup = await syrup.balanceOf(signer[0].address);
console.log("Cake balance of signer : ",finalCake)
console.log("Syrup balance of signer : ",finalSyrup)
expect(initialCake).to.be.greaterThan(finalCake);
expect(finalSyrup).to.be.greaterThan(initialSyrup);
})
it("LeaveStaking Function : ",async()=>{
await _beforeStaking();
await cake.connect(signer[0]).approve(masterchef.target,1000);
await masterchef.connect(signer[0]).enterStaking(500);
console.log("BEFORE LEAVESTAKING")
initialCake = await cake.balanceOf(signer[0].address);
initialSyrup = await syrup.balanceOf(signer[0].address);
console.log("Cake balance of signer : ",initialCake);
console.log("Syrup balance of signer : ",initialSyrup);
await masterchef.connect(signer[0]).leaveStaking(500);
console.log("AFTER LEAVESTAKING")
finalCake = await cake.balanceOf(signer[0].address);
finalSyrup = await syrup.balanceOf(signer[0].address);
console.log("Cake balance of signer : ",finalCake)
console.log("Syrup balance of signer : ",finalSyrup)
expect(finalCake).to.be.greaterThan(initialCake);
expect(initialSyrup).to.be.greaterThan(finalSyrup);
})
it("EMERGENCY Withdraw Function : ",async()=>{
await _deposit();
console.log("AFTER DEPOSIT")
initialCake = await cake.balanceOf(signer[0].address);
initialSigner = await lpToken1.balanceOf(signer[0].address);
initialMasterchef = await lpToken1.balanceOf(masterchef.target);
console.log("Cake balance of signer : ",initialCake);
console.log("lpToken1 balance of signer : ",initialSigner)
console.log("lpToken1 balance of masterchef : ",initialMasterchef)
await masterchef.connect(signer[0]).emergencyWithdraw(1);
console.log("AFTER WITHDRAW")
finalCake = await cake.balanceOf(signer[0].address);
finalSigner = await lpToken1.balanceOf(signer[0].address);
finalMasterchef = await lpToken1.balanceOf(masterchef.target);
console.log("Cake balance of signer : ",finalCake)
console.log("lpToken1 balance of signer : ",finalSigner)
console.log("lpToken1 balance of masterchef : ",finalMasterchef)
expect(finalCake).to.be.equal(0);
//Emergency withdrawal is done without caring for REWARDS
expect(finalSigner).to.be.greaterThan(initialSigner);
expect(initialMasterchef).to.be.greaterThan(finalMasterchef);
})
it("Dev Function : ",async()=>{
console.log( "Dev Address Before Dev Function Called",await masterchef.devaddr())
await masterchef.connect(signer[1]).dev(signer[2].address)
console.log("Dev Address After Dev Function Called", await masterchef.devaddr())
})
it("Dev Function for error check : ",async()=>{
await expect(masterchef.connect(signer[0]).dev(signer[2].address)).to.be.revertedWith('dev: wut?')
console.log( await masterchef.devaddr())
})
})