Skip to content

Commit

Permalink
chore: refactor skipWeeks() -> jumpToWeek()
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 committed Jan 30, 2024
1 parent d61f52d commit 677fc67
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/vesting/VestingLock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ contract VestingLockTest is Test {

/* ---------- Utils ---------- */

function skipWeeks(uint256 numberOfWeeks) public {
uint256 withdrawable = ((basicPlan.amount * numberOfWeeks) / slopeEndWeek) - vestingLock.totalUnlockedTokens();
function jumpToWeek(uint256 weekNumber) public {
uint256 withdrawable = ((basicPlan.amount * weekNumber) / slopeEndWeek) - vestingLock.totalUnlockedTokens();

mockLocking.setWeek(numberOfWeeks);
mockLocking.setWeek(weekNumber);
mockTokenVestingPlans.setRedeemableTokens(withdrawable);
mockLocking.setWithdraw(0, mentoTokenAddr);

Expand Down Expand Up @@ -146,7 +146,7 @@ contract VestingLockTest_redeem is VestingLockTest {

function test_redeem_whenBeforeCliffEndAndFirstRedeem_shouldLockAll() public {
uint256 currentWeek = 52;
skipWeeks(currentWeek);
jumpToWeek(currentWeek);

// because currentWeek is pre cliffEndWeek 105
uint32 cliff = uint32(cliffEndWeek - currentWeek);
Expand Down Expand Up @@ -184,13 +184,13 @@ contract VestingLockTest_redeem is VestingLockTest {
}

function test_redeem_whenBeforeCliffEndAndNotFirstRedeem_shouldRelockAll() public {
skipWeeks(52);
jumpToWeek(52);
vm.prank(beneficiary);
vestingLock.redeem();

assertEq(vestingLock.totalUnlockedTokens(), basicPlan.amount / 4);

skipWeeks(52 + 26); // 1.5 Years
jumpToWeek(52 + 26); // 1.5 Years

uint256 planId = vestingLock.planId();
uint32 slope = uint32(slopeEndWeek - cliffEndWeek);
Expand Down Expand Up @@ -266,13 +266,13 @@ contract VestingLockTest_redeem is VestingLockTest {
}

function test_redeem_whenAtCliffEndAndNotFirstRedeem_shouldRelockAll() public {
skipWeeks(52); // year 1
jumpToWeek(52); // year 1
vm.prank(beneficiary);
vestingLock.redeem();

assertEq(vestingLock.totalUnlockedTokens(), basicPlan.amount / 4);

skipWeeks(104); // year 2
jumpToWeek(104); // year 2

uint256 planId = vestingLock.planId();

Expand Down Expand Up @@ -348,14 +348,14 @@ contract VestingLockTest_redeem is VestingLockTest {
}

function test_redeem_whenAfterCliffEndAndNotFirstRedeem_shouldRelockReminderAndTransferAvailable() public {
skipWeeks(78); // last redeem at 1.5 Years
jumpToWeek(78); // last redeem at 1.5 Years
vm.prank(beneficiary);
vestingLock.redeem();

assertEq(vestingLock.totalUnlockedTokens(), (basicPlan.amount * 3) / 8);

uint256 currentWeek = 156; // Year 3
skipWeeks(currentWeek);
jumpToWeek(currentWeek);

uint256 planId = vestingLock.planId();
uint32 slope = uint32(slopeEndWeek - currentWeek); // slopePeriod remainder
Expand Down Expand Up @@ -388,7 +388,7 @@ contract VestingLockTest_redeem is VestingLockTest {
}

function test_redeem_whenAfterSlopeEndAndFirstRedeem_shouldTransferAll() public {
skipWeeks(208); // redeem at 4 Years
jumpToWeek(208); // redeem at 4 Years
uint256 planId = vestingLock.planId();

vm.expectCall( // ensure redeemPlans is called with correct parameters
Expand All @@ -409,11 +409,11 @@ contract VestingLockTest_redeem is VestingLockTest {
}

function test_redeem_whenAfterSlopeEndAndNotFirstRedeem_shouldRedeemFromLockAndTransferAll() public {
skipWeeks(104); // first redeem at Year 2
jumpToWeek(104); // first redeem at Year 2
vm.prank(beneficiary);
vestingLock.redeem();

skipWeeks(208); // second redeem at Year 2
jumpToWeek(208); // second redeem at Year 4

// set withdrawable amount to 20_000 since 20_000 was locked for 2 years
mockLocking.setWithdraw(20_000 * 1e18, mentoTokenAddr);
Expand Down Expand Up @@ -459,14 +459,14 @@ contract VestingLockTest_getLockedHedgeyBalance is VestingLockTest {

function test_getLockedHedgeyBalance_whenRedeemed_shouldReturnCorrectAmount() public {
vestingLock.initializeVestingPlan();
skipWeeks(104);
jumpToWeek(104);

vm.prank(beneficiary);
vestingLock.redeem();

assertEq(vestingLock.getLockedHedgeyBalance(), basicPlan.amount / 2);

skipWeeks(208);
jumpToWeek(208);

vm.prank(beneficiary);
vestingLock.redeem();
Expand Down

0 comments on commit 677fc67

Please sign in to comment.