-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestBComptroller.spec.ts
665 lines (502 loc) · 26.7 KB
/
TestBComptroller.spec.ts
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
import * as b from "../types/index";
import { BProtocolEngine, BProtocol } from "../test-utils/BProtocolEngine";
import { CompoundUtils } from "../test-utils/CompoundUtils";
import { takeSnapshot, revertToSnapShot } from "../test-utils/SnapshotUtils";
import { BAccounts } from "../test-utils/BAccounts";
import BN from "bn.js";
const { ZERO_ADDRESS } = require("@openzeppelin/test-helpers/src/constants");
const { expectEvent, expectRevert } = require("@openzeppelin/test-helpers");
const BComptroller: b.BComptrollerContract = artifacts.require("BComptroller");
const BErc20: b.BErc20Contract = artifacts.require("BErc20");
const BEther: b.BEtherContract = artifacts.require("BEther");
const chai = require("chai");
const expect = chai.expect;
const ZERO = new BN(0);
contract("BComptroller", async (accounts) => {
let snapshotId: string;
const engine = new BProtocolEngine(accounts);
const a: BAccounts = new BAccounts(accounts);
let bProtocol: BProtocol;
let bComptroller: b.BComptrollerInstance;
let comptroller: b.ComptrollerInstance;
let compoundUtil: CompoundUtils;
before(async () => {
await engine.deployCompound();
bProtocol = await engine.deployBProtocol();
bComptroller = bProtocol.bComptroller;
compoundUtil = bProtocol.compound.compoundUtil;
comptroller = bProtocol.compound.comptroller;
compoundUtil = bProtocol.compound.compoundUtil;
});
beforeEach(async () => {
snapshotId = await takeSnapshot();
});
afterEach(async () => {
await revertToSnapShot(snapshotId);
});
describe("BComptroller: constructor", async () => {
it("should have addresses set", async () => {
expect(await bComptroller.comptroller()).to.be.not.equal(ZERO_ADDRESS);
expect(await bComptroller.comptroller()).to.be.equal(comptroller.address);
});
});
describe("BComptroller.setRegistry()", async () => {
it("should set registry address", async () => {
const _registry = a.dummy1;
const _bComptroller = await BComptroller.new(a.other);
expect(await _bComptroller.registry()).to.be.equal(ZERO_ADDRESS);
await _bComptroller.setRegistry(_registry);
expect(await _bComptroller.registry()).to.be.equal(_registry);
});
it("should fail when registry address already set", async () => {
const _registry = a.dummy1;
const _bComptroller = await BComptroller.new(a.other);
await _bComptroller.setRegistry(_registry);
expect(await _bComptroller.registry()).to.be.equal(_registry);
await expectRevert(_bComptroller.setRegistry(a.dummy2), "BComptroller: registry-already-set");
expect(await _bComptroller.registry()).to.be.equal(_registry);
});
});
describe("BComptroller.newBToken()", async () => {
describe("BErc20:", async () => {
it("should create new BErc20 for cZRX", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const ZRX_addr = compoundUtil.getTokens("ZRX");
const bZRX_addr = await bComptroller.newBToken.call(cZRX_addr);
const tx = await bComptroller.newBToken(cZRX_addr);
expectEvent(tx, "NewBToken", { cToken: cZRX_addr, bToken: bZRX_addr });
const bZRX: b.BErc20Instance = await BErc20.at(bZRX_addr);
expect(await bZRX.cToken()).to.be.equal(cZRX_addr);
expect(await bZRX.registry()).to.be.equal(bProtocol.registry.address);
expect(await bZRX.underlying()).to.be.equal(ZRX_addr);
expect(await bComptroller.c2b(cZRX_addr)).to.be.equal(bZRX_addr);
expect(await bComptroller.b2c(bZRX_addr)).to.be.equal(cZRX_addr);
});
it("should fail when BErc20 for cZRX already exists", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const bZRX = await engine.deployNewBErc20("cZRX");
const bZRX_addr = bZRX.address;
expect(await bComptroller.c2b(cZRX_addr)).to.be.equal(bZRX_addr);
expect(await bComptroller.b2c(bZRX_addr)).to.be.equal(cZRX_addr);
await expectRevert(
bProtocol.bComptroller.newBToken(cZRX_addr),
"BComptroller: BToken-already-exists",
);
expect(await bComptroller.c2b(cZRX_addr)).to.be.equal(bZRX_addr);
expect(await bComptroller.b2c(bZRX_addr)).to.be.equal(cZRX_addr);
});
it("should fail when cToken is not listed on Compound", async () => {
expect(await bComptroller.c2b(a.dummy1)).to.be.equal(ZERO_ADDRESS);
await expectRevert(
bComptroller.newBToken(a.dummy1),
"BComptroller: cToken-not-listed-on-compound",
);
expect(await bComptroller.c2b(a.dummy1)).to.be.equal(ZERO_ADDRESS);
});
it("should deploy BErc20 for multiple cToken", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const bZRX_addr = await bComptroller.newBToken.call(cZRX_addr);
const bZRX = await engine.deployNewBErc20("cZRX");
expect(await bComptroller.c2b(cZRX_addr)).to.be.equal(bZRX_addr);
expect(await bComptroller.b2c(bZRX_addr)).to.be.equal(cZRX_addr);
expect(await bZRX.cToken()).to.be.equal(cZRX_addr);
const cBAT_addr = compoundUtil.getContracts("cBAT");
const bBAT_addr = await bComptroller.newBToken.call(cBAT_addr);
const bBAT = await engine.deployNewBErc20("cBAT");
expect(await bComptroller.c2b(cBAT_addr)).to.be.equal(bBAT_addr);
expect(await bComptroller.b2c(bBAT_addr)).to.be.equal(cBAT_addr);
expect(await bBAT.cToken()).to.be.equal(cBAT_addr);
});
});
describe("BEther:", async () => {
it("should deploy BEther", async () => {
const cETH_addr = compoundUtil.getContracts("cETH");
expect(await bComptroller.c2b(cETH_addr)).to.be.equal(ZERO_ADDRESS);
const bETH_addr = await bComptroller.newBToken.call(cETH_addr);
const tx = await bComptroller.newBToken(cETH_addr);
expectEvent(tx, "NewBToken", { cToken: cETH_addr, bToken: bETH_addr });
const bETH = await BEther.at(bETH_addr);
expect(await bETH.cToken()).to.be.equal(cETH_addr);
expect(await bETH.registry()).to.be.equal(bProtocol.registry.address);
expect(await bComptroller.c2b(cETH_addr)).to.be.equal(bETH_addr);
expect(await bComptroller.b2c(bETH_addr)).to.be.equal(cETH_addr);
});
it("should not have 'underlying' contract public variable", async () => {
const cETH_addr = compoundUtil.getContracts("cETH");
const bETH_BEther = await engine.deployNewBEther();
expect(await bETH_BEther.cToken()).to.be.equal(cETH_addr);
expect(await bETH_BEther.registry()).to.be.equal(bProtocol.registry.address);
// convert to BErc20 TypeScript object
const bETH_BErc20 = await BErc20.at(bETH_BEther.address);
await expectRevert.unspecified(bETH_BErc20.underlying());
});
it("should fail when BEther already deployed", async () => {
const cETH_addr = compoundUtil.getContracts("cETH");
const bETH_addr = await bComptroller.newBToken.call(cETH_addr);
const bETH = await engine.deployNewBEther();
expect(await bComptroller.c2b(cETH_addr)).to.be.equal(bETH_addr);
expect(await bComptroller.b2c(bETH_addr)).to.be.equal(cETH_addr);
await expectRevert(
bComptroller.newBToken(cETH_addr),
"BComptroller: BToken-already-exists",
);
expect(await bComptroller.c2b(cETH_addr)).to.be.equal(bETH_addr);
expect(await bComptroller.b2c(bETH_addr)).to.be.equal(cETH_addr);
});
});
});
describe("BComptroller.isBToken()", async () => {
it("should return true when BErc20 token supported", async () => {
const bBAT = await engine.deployNewBErc20("cBAT");
expect(await bComptroller.isBToken(bBAT.address)).to.be.equal(true);
});
it("should return true when BEther token supported", async () => {
const bETH = await engine.deployNewBEther();
expect(await bComptroller.isBToken(bETH.address)).to.be.equal(true);
});
it("should return false when BToken not supported", async () => {
expect(await bComptroller.isBToken(a.dummy1)).to.be.equal(false);
});
});
describe("BComptroller.enterMarket()", async () => {
let cZRX_addr: string;
let bZRX_addr: string;
let cETH_addr: string;
let bETH_addr: string;
beforeEach(async () => {
cZRX_addr = compoundUtil.getContracts("cZRX");
cETH_addr = compoundUtil.getContracts("cETH");
await bComptroller.newBToken(cZRX_addr);
await bComptroller.newBToken(cETH_addr);
bZRX_addr = await bComptroller.c2b(cZRX_addr);
bETH_addr = await bComptroller.c2b(cETH_addr);
});
it("user (doesn't have an avatar) can enter an existing CErc20 market on compound", async () => {
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
expect(avatar1).to.be.not.equal(ZERO_ADDRESS);
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(ZERO_ADDRESS);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
const err = await bComptroller.enterMarket.call(bZRX_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bZRX_addr, { from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
});
it("user (doesn't have an avatar) can enter an existing CEther market on compound", async () => {
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
expect(avatar1).to.be.not.equal(ZERO_ADDRESS);
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(ZERO_ADDRESS);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
const err = await bComptroller.enterMarket.call(bETH_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bETH_addr, { from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("user (have an avatar) can enter an existing CErc20 market on compound", async () => {
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
expect(avatar1).to.be.not.equal(ZERO_ADDRESS);
await bProtocol.registry.newAvatar({ from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
const err = await bComptroller.enterMarket.call(bZRX_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bZRX_addr, { from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
});
it("user (have an avatar) can enter an existing CEther market on compound", async () => {
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
expect(avatar1).to.be.not.equal(ZERO_ADDRESS);
await bProtocol.registry.newAvatar({ from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
const err = await bComptroller.enterMarket.call(bETH_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bETH_addr, { from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("user can enter a CErc20 market again", async () => {
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
await bProtocol.registry.newAvatar({ from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
let err = await bComptroller.enterMarket.call(bZRX_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bZRX_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
err = await bComptroller.enterMarket.call(bZRX_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bZRX_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
});
it("user can enter a CEther market again", async () => {
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
await bProtocol.registry.newAvatar({ from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
const err = await bComptroller.enterMarket.call(bETH_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.enterMarket(bETH_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
await bComptroller.enterMarket(bETH_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("should fail when BErc20 not exists for given market", async () => {
const cBAT_addr = compoundUtil.getContracts("cBAT");
await expectRevert(
bComptroller.enterMarket(cBAT_addr, { from: a.user1 }),
"BComptroller: CToken-not-exist-for-bToken",
);
});
});
describe("BComptroller.enterMarkets()", async () => {
let cZRX_addr: string;
let bZRX_addr: string;
let cETH_addr: string;
let bETH_addr: string;
beforeEach(async () => {
cZRX_addr = compoundUtil.getContracts("cZRX");
cETH_addr = compoundUtil.getContracts("cETH");
await bComptroller.newBToken(cZRX_addr);
await bComptroller.newBToken(cETH_addr);
bZRX_addr = await bComptroller.c2b(cZRX_addr);
bETH_addr = await bComptroller.c2b(cETH_addr);
});
it("user (doesn't have an avatar) can enter multiple existing markets on compound", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const cETH_addr = compoundUtil.getContracts("cETH");
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
expect(avatar1).to.be.not.equal(ZERO_ADDRESS);
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(ZERO_ADDRESS);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
const errArr = await bComptroller.enterMarkets.call([bZRX_addr, bETH_addr], {
from: a.user1,
});
await Promise.all(errArr.map((e) => expect(e).to.be.bignumber.equal(ZERO)));
await bComptroller.enterMarkets([bZRX_addr, bETH_addr], { from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("user (have an avatar) can enter multiple existing markets on compound", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const cETH_addr = compoundUtil.getContracts("cETH");
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
expect(avatar1).to.be.not.equal(ZERO_ADDRESS);
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(ZERO_ADDRESS);
await bProtocol.registry.newAvatar({ from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
const errArr = await bComptroller.enterMarkets.call([bZRX_addr, bETH_addr], {
from: a.user1,
});
await Promise.all(errArr.map((e) => expect(e).to.be.bignumber.equal(ZERO)));
await bComptroller.enterMarkets([bZRX_addr, bETH_addr], { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("user can enter into multiple market again", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const avatar1 = await bProtocol.registry.newAvatar.call({ from: a.user1 });
await bProtocol.registry.newAvatar({ from: a.user1 });
expect(await bProtocol.registry.avatarOf(a.user1)).to.be.equal(avatar1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
const errArr = await bComptroller.enterMarkets.call([bZRX_addr, bZRX_addr], {
from: a.user1,
});
await Promise.all(errArr.map((e) => expect(e).to.be.bignumber.equal(ZERO)));
await bComptroller.enterMarkets([bZRX_addr, bZRX_addr], { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
});
it("should fail when BToken not exists for a given market", async () => {
const cBAT_addr = compoundUtil.getContracts("cBAT");
await expectRevert(
bComptroller.enterMarkets([cBAT_addr], { from: a.user1 }),
"BComptroller: CToken-not-exist-for-bToken",
);
});
});
describe("BComptroller.exitMarket()", async () => {
let cZRX_addr: string;
let bZRX_addr: string;
let cETH_addr: string;
let bETH_addr: string;
beforeEach(async () => {
cZRX_addr = compoundUtil.getContracts("cZRX");
cETH_addr = compoundUtil.getContracts("cETH");
await bComptroller.newBToken(cZRX_addr);
await bComptroller.newBToken(cETH_addr);
bZRX_addr = await bComptroller.c2b(cZRX_addr);
bETH_addr = await bComptroller.c2b(cETH_addr);
await bComptroller.enterMarkets([bZRX_addr, bETH_addr], { from: a.user1 });
});
it("should fail when user not have avatar", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
await expectRevert.unspecified(bComptroller.exitMarket(cZRX_addr, { from: a.user2 }));
});
it("user can exit from a market he is in", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const cETH_addr = compoundUtil.getContracts("cETH");
const avatar1 = await bProtocol.registry.avatarOf(a.user1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
const err = await bComptroller.exitMarket.call(bZRX_addr, { from: a.user1 });
expect(err).to.be.bignumber.equal(ZERO);
await bComptroller.exitMarket(bZRX_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
});
describe("BComptroller.getAccountLiquidity()", async () => {
let cZRX_addr: string;
let bZRX_addr: string;
let cETH_addr: string;
let bETH_addr: string;
beforeEach(async () => {
cZRX_addr = compoundUtil.getContracts("cZRX");
cETH_addr = compoundUtil.getContracts("cETH");
await bComptroller.newBToken(cZRX_addr);
await bComptroller.newBToken(cETH_addr);
bZRX_addr = await bComptroller.c2b(cZRX_addr);
bETH_addr = await bComptroller.c2b(cETH_addr);
await bComptroller.enterMarkets([bZRX_addr, bETH_addr], { from: a.user1 });
});
it("should get account liquidity of a user");
it("should get account shortFall of a user");
it("should get zero when user does not have any liquidity", async () => {
const result = await bComptroller.getAccountLiquidity(a.user1);
const err = result[0];
const liquidity = result[1];
const shortFall = result[2];
expect(err).to.be.bignumber.equal(ZERO);
expect(liquidity).to.be.bignumber.equal(ZERO);
expect(shortFall).to.be.bignumber.equal(ZERO);
});
});
describe("BComptroller.claimComp(holder)", async () => {
it("user claims his COMP tokens from Compound");
it("user gets nothing, when not earned COMP tokens on Compound");
});
describe("BComptroller.claimComp(holder, bTokens[])", async () => {
it("user claims his COMP tokens from Compound");
it("user gets COMP tokens he earned on different markets");
it("user gets nothing, when not earned COMP tokens on Compound");
});
describe("BComptroller.claimComp(holders[], bTokens[], borrowers, suppliers)", async () => {
it("user initiate claims for multiple Avatars");
it("user initiate claims for multiple Avatars with borrowers");
it("user initiate claims for multiple Avatars with suppliers");
it("user initiate claims for multiple Avatars with both borrowers and suppliers");
});
describe("BComptroller.oracle()", async () => {
it("should get oracle add of compound", async () => {
expect(await bComptroller.oracle()).to.be.equal(await comptroller.oracle());
});
});
describe("Contract public storage:", async () => {
describe("BComptroller.comptroller()", async () => {
it("should set comptroller at construction", async () => {
const _comptroller = a.dummy1;
const _bComptroller = await BComptroller.new(_comptroller);
expect(await _bComptroller.comptroller()).to.be.equal(_comptroller);
});
});
describe("BComptroller.registry()", async () => {
it("should not have registry set at construction", async () => {
const _comptroller = a.dummy1;
const _bComptroller = await BComptroller.new(_comptroller);
expect(await _bComptroller.registry()).to.be.equal(ZERO_ADDRESS);
});
});
describe("BComptroller.c2b()", async () => {
it("should return cToken for existing bToken", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const bZRX = await engine.deployNewBErc20("cZRX");
expect(await bComptroller.c2b(cZRX_addr)).to.be.equal(bZRX.address);
});
it("should return 0x0 for non existing cToken", async () => {
expect(await bComptroller.c2b(a.dummy1)).to.be.equal(ZERO_ADDRESS);
});
});
describe("BComptroller.b2c()", async () => {
it("should return bToken for existing cToken", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const bZRX = await engine.deployNewBErc20("cZRX");
expect(await bComptroller.b2c(bZRX.address)).to.be.equal(cZRX_addr);
});
it("should return 0x0 cToken for non existing bToken", async () => {
expect(await bComptroller.b2c(a.dummy1)).to.be.equal(ZERO_ADDRESS);
});
});
});
describe("BComptroller: Integration tests:", async () => {
let cZRX_addr: string;
let bZRX_addr: string;
let cETH_addr: string;
let bETH_addr: string;
beforeEach(async () => {
cZRX_addr = compoundUtil.getContracts("cZRX");
cETH_addr = compoundUtil.getContracts("cETH");
await bComptroller.newBToken(cZRX_addr);
await bComptroller.newBToken(cETH_addr);
bZRX_addr = await bComptroller.c2b(cZRX_addr);
bETH_addr = await bComptroller.c2b(cETH_addr);
});
it("user enterMakert, exitMarket then enterMarket", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const cETH_addr = compoundUtil.getContracts("cETH");
await bProtocol.registry.newAvatar({ from: a.user1 });
const avatar1 = await bProtocol.registry.avatarOf(a.user1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
await bComptroller.enterMarkets([bZRX_addr, bETH_addr], { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
await bComptroller.exitMarket(bZRX_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
await bComptroller.enterMarket(bZRX_addr, { from: a.user1 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("on behalf: user enterMakert, exitMarket then enterMarket", async () => {
const cZRX_addr = compoundUtil.getContracts("cZRX");
const cETH_addr = compoundUtil.getContracts("cETH");
await bProtocol.registry.newAvatar({ from: a.user1 });
const avatar1 = await bProtocol.registry.avatarOf(a.user1);
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(false);
await bProtocol.registry.delegateAvatar(a.user2, { from: a.user1 });
await expectRevert(
bComptroller.enterMarketsOnAvatar(avatar1, [bZRX_addr, bETH_addr], { from: a.user3 }),
"BComptroller: delegatee-not-authorized",
);
await bComptroller.enterMarketsOnAvatar(avatar1, [bZRX_addr, bETH_addr], { from: a.user2 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
await expectRevert(
bComptroller.exitMarketOnAvatar(avatar1, bZRX_addr, { from: a.user3 }),
"BComptroller: delegatee-not-authorized",
);
await bComptroller.exitMarketOnAvatar(avatar1, bZRX_addr, { from: a.user2 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(false);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
await expectRevert(
bComptroller.enterMarketOnAvatar(avatar1, bZRX_addr, { from: a.user3 }),
"BComptroller: delegatee-not-authorized",
);
await bComptroller.enterMarketOnAvatar(avatar1, bZRX_addr, { from: a.user2 });
expect(await comptroller.checkMembership(avatar1, cZRX_addr)).to.be.equal(true);
expect(await comptroller.checkMembership(avatar1, cETH_addr)).to.be.equal(true);
});
it("TODO: what should happen when token all max approval is used?");
});
describe("BComptroller.getAllMarkets()", async () => {
it("should get all markets", async () => {
const markets = await bComptroller.getAllMarkets();
expect(markets.length > 0).to.be.equal(true);
});
});
});