|
3 | 3 | /* eslint-disable no-undef */ |
4 | 4 |
|
5 | 5 | const { parseUnits } = require("@ethersproject/units"); |
6 | | -const { expect } = require("chai"); |
| 6 | +const { expect, assert } = require("chai"); |
7 | 7 |
|
8 | 8 | const zeroAddress = "0x0000000000000000000000000000000000000000"; |
9 | 9 | const helper = require("./../helpers/helpers"); |
10 | 10 | const devEnv = require("./utils/setEnv"); |
11 | 11 |
|
12 | | -const MIN_LOWER = 2; |
13 | | -const MIN_UPPER = 7; |
| 12 | +const MIN_LOWER = helper.getSeconds(2); |
| 13 | +const MIN_UPPER = helper.getSeconds(5); |
14 | 14 |
|
15 | 15 | let accounts, owner, user, streamReceiver; |
16 | 16 | let env; |
@@ -370,16 +370,24 @@ describe("#3 - StrollManager: Register TopUps", function () { |
370 | 370 | strategy.address, |
371 | 371 | dai.address, |
372 | 372 | expiry + 1000, |
373 | | - 20, |
374 | | - 20 |
| 373 | + helper.getSeconds(20), |
| 374 | + helper.getSeconds(20) |
375 | 375 | ); |
376 | 376 | const topUp = await strollManager.getTopUp( |
377 | 377 | user.address, |
378 | 378 | daix.address, |
379 | 379 | dai.address |
380 | 380 | ); |
381 | | - assert.equal(topUp.lowerLimit, 20, "wrong lowerLimit on update"); |
382 | | - assert.equal(topUp.upperLimit, 20, "wrong upperLimit on update"); |
| 381 | + assert.equal( |
| 382 | + topUp.lowerLimit, |
| 383 | + helper.getSeconds(20), |
| 384 | + "wrong lowerLimit on update" |
| 385 | + ); |
| 386 | + assert.equal( |
| 387 | + topUp.upperLimit, |
| 388 | + helper.getSeconds(20), |
| 389 | + "wrong upperLimit on update" |
| 390 | + ); |
383 | 391 | assert.equal(topUp.expiry, expiry + 1000, "wrong expiry on update"); |
384 | 392 | }); |
385 | 393 | }); |
@@ -799,4 +807,68 @@ describe("#6 - perform Top Up", function () { |
799 | 807 | strollManager.performTopUp(user.address, daix.address, dai.address) |
800 | 808 | ).to.be.revertedWith(`TopUpNotRequired("${result}")`); |
801 | 809 | }); |
| 810 | + it("Case #6.4 - TopUp using max values (global limits)", async () => { |
| 811 | + const flowRate = parseUnits("300", 18).div( |
| 812 | + helper.getBigNumber(helper.getSeconds(30)) |
| 813 | + ); |
| 814 | + await strollManager |
| 815 | + .connect(user) |
| 816 | + .createTopUp( |
| 817 | + daix.address, |
| 818 | + strategy.address, |
| 819 | + dai.address, |
| 820 | + helper.getTimeStampNow() + helper.getSeconds(365), |
| 821 | + helper.getSeconds(5), |
| 822 | + helper.getSeconds(5) |
| 823 | + ); |
| 824 | + |
| 825 | + let tx = await strollManager.setLimits( |
| 826 | + helper.getSeconds(6), |
| 827 | + helper.getSeconds(8) |
| 828 | + ); |
| 829 | + const limitsChangedEvent = await helper.getEvents(tx, "LimitsChanged"); |
| 830 | + assert.equal( |
| 831 | + limitsChangedEvent[0].args.lowerLimit, |
| 832 | + helper.getSeconds(6), |
| 833 | + "wrong lower limit" |
| 834 | + ); |
| 835 | + assert.equal( |
| 836 | + limitsChangedEvent[0].args.upperLimit, |
| 837 | + helper.getSeconds(8), |
| 838 | + "wrong upper limit" |
| 839 | + ); |
| 840 | + |
| 841 | + // approve superToken |
| 842 | + await dai.connect(user).approve(daix.address, parseUnits("10000", 18)); |
| 843 | + // approve strategy |
| 844 | + await dai.connect(user).approve(strategy.address, parseUnits("10000", 18)); |
| 845 | + // get some superToken |
| 846 | + await daix.connect(user).upgrade(parseUnits("20", 18)); |
| 847 | + await createStream(daix, user, streamReceiver, flowRate.toString(), "0x"); |
| 848 | + |
| 849 | + let balance = await daix.balanceOf(user.address); |
| 850 | + console.log("Balance before increase time: ", balance.toString()); |
| 851 | + |
| 852 | + await helper.increaseTime(3600 * 24 * 5); |
| 853 | + |
| 854 | + balance = await daix.balanceOf(user.address); |
| 855 | + console.log("Balance after increase time: ", balance.toString()); |
| 856 | + |
| 857 | + tx = await strollManager.performTopUp( |
| 858 | + user.address, |
| 859 | + daix.address, |
| 860 | + dai.address |
| 861 | + ); |
| 862 | + |
| 863 | + const TopUpEvent = await helper.getEvents(tx, "PerformedTopUp"); |
| 864 | + const after = await daix.balanceOf(user.address); |
| 865 | + |
| 866 | + console.log("After: ", after.toString()); |
| 867 | + |
| 868 | + expect(after.sub(balance)).to.be.closeTo( |
| 869 | + TopUpEvent[0].args.topUpAmount, |
| 870 | + parseUnits("0.01", 18) |
| 871 | + ); |
| 872 | + assert.isAbove(after, balance, "balance should go up"); |
| 873 | + }); |
802 | 874 | }); |
0 commit comments