@@ -2,6 +2,8 @@ const { expect } = require("chai");
2
2
const { expectRevert, expectEvent, constants, BN } = require ( "@openzeppelin/test-helpers" ) ;
3
3
const { increaseTime, lastBlock } = require ( "../Utils/Ethereum" ) ;
4
4
const { deployAndGetIStaking, initializeStakingModulesAt } = require ( "../Utils/initializer" ) ;
5
+ const hre = require ( "hardhat" ) ;
6
+ const { ethers } = hre ;
5
7
6
8
const StakingLogic = artifacts . require ( "IStaking" ) ;
7
9
const StakingProxy = artifacts . require ( "StakingProxy" ) ;
@@ -22,6 +24,11 @@ const TOTAL_SUPPLY = "10000000000000000000000000";
22
24
const ONE_MILLON = "1000000000000000000000000" ;
23
25
const ONE_ETHER = "1000000000000000000" ;
24
26
27
+ const increaseTimeEthers = async ( time ) => {
28
+ await ethers . provider . send ( "evm_increaseTime" , [ time ] ) ;
29
+ await ethers . provider . send ( "evm_mine" ) ;
30
+ } ;
31
+
25
32
contract ( "FourYearVesting" , ( accounts ) => {
26
33
let root , a1 , a2 , a3 ;
27
34
let token , staking , stakingLogic , stakingProxy , feeSharingProxy ;
@@ -313,7 +320,7 @@ contract("FourYearVesting", (accounts) => {
313
320
} ) ;
314
321
} ) ;
315
322
316
- describe ( "stakeTokens; using Ganache " , ( ) => {
323
+ describe ( "stakeTokens" , ( ) => {
317
324
// Check random scenarios
318
325
let vesting ;
319
326
it ( "should stake 1,000,000 SOV with a duration of 156 weeks and a 4 week cliff" , async ( ) => {
@@ -377,8 +384,8 @@ contract("FourYearVesting", (accounts) => {
377
384
378
385
// negative cases
379
386
380
- // start-10 to avoid coming to active checkpoint
381
- let periodFromKickoff = Math . floor ( ( start - 10 - kickoffTS . toNumber ( ) ) / ( 2 * WEEK ) ) ;
387
+ // start-100 to avoid coming to active checkpoint
388
+ let periodFromKickoff = Math . floor ( ( start - 100 - kickoffTS . toNumber ( ) ) / ( 2 * WEEK ) ) ;
382
389
let startBuf = periodFromKickoff * 2 * WEEK + kickoffTS . toNumber ( ) ;
383
390
let userStakingCheckpoints = await staking . userStakingCheckpoints (
384
391
vesting . address ,
@@ -435,7 +442,7 @@ contract("FourYearVesting", (accounts) => {
435
442
remainingStakeAmount = await vesting . remainingStakeAmount ( ) ;
436
443
}
437
444
438
- await increaseTime ( 52 * WEEK ) ;
445
+ await increaseTimeEthers ( 52 * WEEK ) ;
439
446
await token . approve ( vesting . address , amount ) ;
440
447
await expectRevert ( vesting . stakeTokens ( amount , 0 ) , "create new vesting address" ) ;
441
448
} ) ;
@@ -565,7 +572,7 @@ contract("FourYearVesting", (accounts) => {
565
572
remainingStakeAmount = await vesting . remainingStakeAmount ( ) ;
566
573
assert . equal ( remainingStakeAmount , 0 ) ;
567
574
568
- let block = await web3 . eth . getBlock ( "latest" ) ;
575
+ let block = await ethers . provider . getBlock ( "latest" ) ;
569
576
let timestamp = block . timestamp ;
570
577
571
578
let start = timestamp + cliff ;
@@ -625,7 +632,7 @@ contract("FourYearVesting", (accounts) => {
625
632
let amountAfterStake = await token . balanceOf ( root ) ;
626
633
627
634
// time travel
628
- await increaseTime ( 104 * WEEK ) ;
635
+ await increaseTimeEthers ( 104 * WEEK ) ;
629
636
630
637
// withdraw
631
638
tx = await vesting . withdrawTokens ( root ) ;
@@ -675,7 +682,7 @@ contract("FourYearVesting", (accounts) => {
675
682
let amountAfterStake = await token . balanceOf ( root ) ;
676
683
677
684
// time travel
678
- await increaseTime ( 34 * WEEK ) ;
685
+ await increaseTimeEthers ( 34 * WEEK ) ;
679
686
680
687
// withdraw
681
688
tx = await vesting . withdrawTokens ( root ) ;
@@ -712,7 +719,7 @@ contract("FourYearVesting", (accounts) => {
712
719
let amountAfterStake = await token . balanceOf ( root ) ;
713
720
714
721
// time travel
715
- await increaseTime ( 20 * WEEK ) ;
722
+ await increaseTimeEthers ( 20 * WEEK ) ;
716
723
await token . approve ( vesting . address , toStake ) ;
717
724
await expectRevert ( vesting . stakeTokens ( toStake , 0 ) , "create new vesting address" ) ;
718
725
@@ -760,7 +767,7 @@ contract("FourYearVesting", (accounts) => {
760
767
let amountOld = await token . balanceOf ( root ) ;
761
768
762
769
// time travel
763
- await increaseTime ( 2 * WEEK ) ;
770
+ await increaseTimeEthers ( 2 * WEEK ) ;
764
771
765
772
// withdraw
766
773
tx = await vesting . withdrawTokens ( a2 , { from : a1 } ) ;
@@ -775,7 +782,7 @@ contract("FourYearVesting", (accounts) => {
775
782
await expectRevert ( vesting . withdrawTokens ( root , { from : a3 } ) , "unauthorized" ) ;
776
783
777
784
await expectRevert ( vesting . withdrawTokens ( root , { from : root } ) , "unauthorized" ) ;
778
- await increaseTime ( 30 * WEEK ) ;
785
+ await increaseTimeEthers ( 30 * WEEK ) ;
779
786
await expectRevert ( vesting . withdrawTokens ( root , { from : a2 } ) , "unauthorized" ) ;
780
787
} ) ;
781
788
@@ -1013,7 +1020,7 @@ contract("FourYearVesting", (accounts) => {
1013
1020
} ) ;
1014
1021
1015
1022
it ( "should extend duration of first 5 staking periods" , async ( ) => {
1016
- await increaseTime ( 20 * WEEK ) ;
1023
+ await increaseTimeEthers ( 20 * WEEK ) ;
1017
1024
tx = await vesting . extendStaking ( ) ;
1018
1025
data = await staking . getStakes . call ( vesting . address ) ;
1019
1026
expect ( data . stakes [ 0 ] ) . to . be . bignumber . equal ( data . stakes [ 15 ] ) ;
@@ -1024,7 +1031,7 @@ contract("FourYearVesting", (accounts) => {
1024
1031
} ) ;
1025
1032
1026
1033
it ( "should extend duration of next 5 staking periods" , async ( ) => {
1027
- await increaseTime ( 20 * WEEK ) ;
1034
+ await increaseTimeEthers ( 20 * WEEK ) ;
1028
1035
tx = await vesting . extendStaking ( ) ;
1029
1036
data = await staking . getStakes . call ( vesting . address ) ;
1030
1037
expect ( data . stakes [ 0 ] ) . to . be . bignumber . equal ( data . stakes [ 15 ] ) ;
@@ -1035,7 +1042,7 @@ contract("FourYearVesting", (accounts) => {
1035
1042
} ) ;
1036
1043
1037
1044
it ( "should extend duration of next 3 staking periods only" , async ( ) => {
1038
- await increaseTime ( 20 * WEEK ) ;
1045
+ await increaseTimeEthers ( 20 * WEEK ) ;
1039
1046
tx = await vesting . extendStaking ( ) ;
1040
1047
data = await staking . getStakes . call ( vesting . address ) ;
1041
1048
expect ( data . stakes [ 0 ] ) . to . be . bignumber . equal ( data . stakes [ 15 ] ) ;
@@ -1053,7 +1060,7 @@ contract("FourYearVesting", (accounts) => {
1053
1060
1054
1061
it ( "should withdraw unlocked tokens for four year vesting after first year" , async ( ) => {
1055
1062
// time travel
1056
- await increaseTime ( 104 * WEEK ) ;
1063
+ await increaseTimeEthers ( 104 * WEEK ) ;
1057
1064
1058
1065
// withdraw
1059
1066
tx = await vesting . withdrawTokens ( root ) ;
@@ -1124,7 +1131,7 @@ contract("FourYearVesting", (accounts) => {
1124
1131
expect ( delegatee ) . equal ( root ) ;
1125
1132
}
1126
1133
1127
- await increaseTime ( 80 * WEEK ) ;
1134
+ await increaseTimeEthers ( 80 * WEEK ) ;
1128
1135
let tx = await vesting . extendStaking ( ) ;
1129
1136
// delegate
1130
1137
tx = await vesting . delegate ( a1 ) ;
0 commit comments