Skip to content

Commit

Permalink
clean test
Browse files Browse the repository at this point in the history
  • Loading branch information
SegueII committed Nov 14, 2024
1 parent 4dca79f commit 9474c17
Showing 1 changed file with 5 additions and 125 deletions.
130 changes: 5 additions & 125 deletions contracts/contracts/test/L2Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,6 @@ contract L2StakingTest is L2StakingBaseTest {
assertEq(aliceRewards[1], aliceReward2);
assertEq(aliceRewards[2], aliceReward3);

// console.logString("......................");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");

// *************** epoch = 4 ******************** //
time = REWARD_EPOCH * 5;
hevm.roll(blocksCountOfEpoch * 5);
Expand All @@ -1286,22 +1280,11 @@ contract L2StakingTest is L2StakingBaseTest {
aliceReward2 = distribute.queryUnclaimed(secondStaker, alice);
aliceReward3 = distribute.queryUnclaimed(thirdStaker, alice);

// console.logString("......................");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");

hevm.startPrank(alice);
uint256 balanceBefore = morphToken.balanceOf(alice);
l2Staking.claimReward(address(0), 0);
uint256 balanceAfter = morphToken.balanceOf(alice);

// console.logString("......................");
// console.logUint(balanceBefore);
// console.logUint(balanceAfter);
// console.logString("......................");

assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2 + aliceReward3);
hevm.stopPrank();
}
Expand Down Expand Up @@ -1374,12 +1357,7 @@ contract L2StakingTest is L2StakingBaseTest {
assertTrue(aliceReward1 > 0);
assertTrue(aliceReward2 > 0);
assertTrue(aliceReward3 > 0);
// console.logString("......................");
// console.logString("reward before claim");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");

assertEq(delegetees[0], firstStaker);
assertEq(delegetees[1], secondStaker);
assertEq(delegetees[2], thirdStaker);
Expand All @@ -1392,11 +1370,6 @@ contract L2StakingTest is L2StakingBaseTest {
l2Staking.claimReward(address(0), 0);
uint256 balanceAfter = morphToken.balanceOf(alice);
assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2 + aliceReward3);
// console.logString("......................");
// console.logString("claim all result");
// console.logUint(balanceBefore);
// console.logUint(balanceAfter);
// console.logString("......................");
hevm.stopPrank();

(delegetees, aliceRewards) = distribute.queryAllUnclaimed(alice);
Expand All @@ -1406,12 +1379,7 @@ contract L2StakingTest is L2StakingBaseTest {
assertTrue(aliceReward1 == 0);
assertTrue(aliceReward2 == 0);
assertTrue(aliceReward3 == 0);
// console.logString("......................");
// console.logString("query 0 epoch later");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");

assertEq(delegetees[0], firstStaker);
assertEq(delegetees[1], secondStaker);
assertEq(delegetees[2], thirdStaker);
Expand All @@ -1432,12 +1400,7 @@ contract L2StakingTest is L2StakingBaseTest {
assertTrue(aliceReward1 > 0);
assertTrue(aliceReward2 > 0);
assertTrue(aliceReward3 > 0);
// console.logString("......................");
// console.logString("query 1 epoch later");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");

assertEq(delegetees[0], firstStaker);
assertEq(delegetees[1], secondStaker);
assertEq(delegetees[2], thirdStaker);
Expand All @@ -1458,12 +1421,7 @@ contract L2StakingTest is L2StakingBaseTest {
assertTrue(aliceReward1 > 0);
assertTrue(aliceReward2 > 0);
assertTrue(aliceReward3 > 0);
// console.logString("......................");
// console.logString("query 2 epoch later");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");

assertEq(delegetees[0], firstStaker);
assertEq(delegetees[1], secondStaker);
assertEq(delegetees[2], thirdStaker);
Expand All @@ -1476,8 +1434,6 @@ contract L2StakingTest is L2StakingBaseTest {
l2Staking.claimReward(address(0), 0);
balanceAfter = morphToken.balanceOf(alice);
assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2 + aliceReward3);
// console.logUint(balanceBefore);
// console.logUint(balanceAfter);
hevm.stopPrank();

// *************** epoch = 4 ******************** //
Expand All @@ -1499,9 +1455,7 @@ contract L2StakingTest is L2StakingBaseTest {
assertTrue(aliceReward1 > 0);
assertTrue(aliceReward2 > 0);
assertTrue(aliceReward3 > 0);
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);

assertEq(delegetees[0], firstStaker);
assertEq(delegetees[1], secondStaker);
assertEq(delegetees[2], thirdStaker);
Expand All @@ -1514,8 +1468,6 @@ contract L2StakingTest is L2StakingBaseTest {
l2Staking.claimReward(address(0), 0);
balanceAfter = morphToken.balanceOf(alice);
assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2 + aliceReward3);
// console.logUint(balanceBefore);
// console.logUint(balanceAfter);
hevm.stopPrank();
}

Expand Down Expand Up @@ -1573,19 +1525,13 @@ contract L2StakingTest is L2StakingBaseTest {
hevm.roll(blocksCountOfEpoch * (3));
hevm.warp(time);
_updateDistribute(1);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

uint256 aliceReward1 = distribute.queryUnclaimed(firstStaker, alice);
uint256 aliceReward2 = distribute.queryUnclaimed(secondStaker, alice);
uint256 aliceReward3 = distribute.queryUnclaimed(thirdStaker, alice);
hevm.startPrank(alice);
uint256 balanceBefore = morphToken.balanceOf(alice);
// console.logString("......................");
// console.logUint(balanceBefore);
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);

l2Staking.claimReward(address(0), 0);
hevm.expectRevert("all reward claimed");
Expand All @@ -1596,8 +1542,6 @@ contract L2StakingTest is L2StakingBaseTest {
l2Staking.claimReward(thirdStaker, 0);
uint256 balanceAfter = morphToken.balanceOf(alice);

// console.logUint(balanceAfter);
// console.logString("......................");
assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2 + aliceReward3);
hevm.stopPrank();

Expand All @@ -1606,7 +1550,6 @@ contract L2StakingTest is L2StakingBaseTest {
hevm.roll(blocksCountOfEpoch * (4));
hevm.warp(time);
_updateDistribute(2);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

hevm.startPrank(alice);
Expand All @@ -1615,97 +1558,67 @@ contract L2StakingTest is L2StakingBaseTest {
l2Staking.undelegateStake(thirdStaker);
hevm.stopPrank();

// console.logString("......................");
// console.logString("......................");
aliceReward1 = distribute.queryUnclaimed(firstStaker, alice);
aliceReward2 = distribute.queryUnclaimed(secondStaker, alice);
aliceReward3 = distribute.queryUnclaimed(thirdStaker, alice);
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logUint(aliceReward3);
// console.logString("......................");
// console.logString("......................");

// *********************************** //
time = REWARD_EPOCH * (5);
hevm.roll(blocksCountOfEpoch * (5));
hevm.warp(time);
_updateDistribute(3);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

// *********************************** //
time = REWARD_EPOCH * (6);
hevm.roll(blocksCountOfEpoch * (6));
hevm.warp(time);
_updateDistribute(4);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

// *********************************** //
time = REWARD_EPOCH * (7);
hevm.roll(blocksCountOfEpoch * (7));
hevm.warp(time);
_updateDistribute(5);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

// *********************************** //
time = REWARD_EPOCH * (8);
hevm.roll(blocksCountOfEpoch * (8));
hevm.warp(time);
_updateDistribute(6);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

uint256 aliceRewardNew1 = distribute.queryUnclaimed(firstStaker, alice);
uint256 aliceRewardNew2 = distribute.queryUnclaimed(secondStaker, alice);
uint256 aliceRewardNew3 = distribute.queryUnclaimed(thirdStaker, alice);

hevm.startPrank(alice);
// console.logString("......................");
balanceBefore = morphToken.balanceOf(alice);
uint256 balanceBeforeTmp = balanceBefore;
// console.logUint(balanceBefore);
// console.logString("......................");

// l2Staking.claimReward(address(0), 0);

// console.logString("......................");

// console.logUint(aliceRewardNew1);
balanceBeforeTmp = morphToken.balanceOf(alice);
l2Staking.claimReward(firstStaker, 0);
hevm.expectRevert("no remaining reward");
l2Staking.claimReward(firstStaker, 0);
balanceAfter = morphToken.balanceOf(alice);
// console.logUint(balanceAfter);
assertEq(balanceAfter, balanceBeforeTmp + aliceRewardNew1);

// console.logString("......................");

// console.logUint(aliceRewardNew2);
balanceBeforeTmp = morphToken.balanceOf(alice);
l2Staking.claimReward(secondStaker, 0);
hevm.expectRevert("no remaining reward");
l2Staking.claimReward(secondStaker, 0);
balanceAfter = morphToken.balanceOf(alice);
// console.logUint(balanceAfter);
assertEq(balanceAfter, balanceBeforeTmp + aliceRewardNew2);

// console.logString("......................");

// console.logUint(aliceRewardNew3);
balanceBeforeTmp = morphToken.balanceOf(alice);
l2Staking.claimReward(thirdStaker, 0);
hevm.expectRevert("no remaining reward");
l2Staking.claimReward(thirdStaker, 0);
balanceAfter = morphToken.balanceOf(alice);
// console.logUint(balanceAfter);
assertEq(balanceAfter, balanceBeforeTmp + aliceRewardNew3);

// console.logString("......................");

assertEq(balanceAfter, balanceBefore + aliceRewardNew1 + aliceRewardNew2 + aliceRewardNew3);

hevm.expectRevert("invalid delegator or no remaining reward");
Expand Down Expand Up @@ -1771,15 +1684,13 @@ contract L2StakingTest is L2StakingBaseTest {
hevm.roll(blocksCountOfEpoch * (3));
hevm.warp(time);
_updateDistribute(1);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

// *********************************** //
time = REWARD_EPOCH * (4);
hevm.roll(blocksCountOfEpoch * (4));
hevm.warp(time);
_updateDistribute(2);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

hevm.startPrank(alice);
Expand All @@ -1793,18 +1704,12 @@ contract L2StakingTest is L2StakingBaseTest {
hevm.roll(blocksCountOfEpoch * (5));
hevm.warp(time);
_updateDistribute(3);
// console.logUint(morphToken.inflationMintedEpochs());
// *********************************** //

uint256 aliceReward1 = distribute.queryUnclaimed(firstStaker, alice);
uint256 aliceReward2 = distribute.queryUnclaimed(secondStaker, alice);
uint256 aliceReward3 = distribute.queryUnclaimed(thirdStaker, alice);
uint256 balanceBefore = morphToken.balanceOf(alice);
console.logString("......................");
console.logUint(balanceBefore);
console.logUint(aliceReward1);
console.logUint(aliceReward2);
console.logUint(aliceReward3);

hevm.startPrank(alice);
l2Staking.claimReward(address(0), 0);
Expand All @@ -1824,8 +1729,6 @@ contract L2StakingTest is L2StakingBaseTest {
l2Staking.claimReward(thirdStaker, 0);
uint256 balanceAfter = morphToken.balanceOf(alice);

console.logUint(balanceAfter);
console.logString("......................");
assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2 + aliceReward3);
hevm.stopPrank();
}
Expand Down Expand Up @@ -1934,13 +1837,10 @@ contract L2StakingTest is L2StakingBaseTest {
hevm.stopPrank();

uint256 alice2Reward = distribute.queryUnclaimed(firstStaker, alice2);
console.log("alice2Reward: ", alice2Reward);
hevm.startPrank(alice2);
uint256 alice2BalanceBefore = morphToken.balanceOf(alice2);
// console.log("alice2BalanceBefore: ", alice2BalanceBefore);
l2Staking.claimReward(firstStaker, 0);
uint256 alice2BalanceAfter = morphToken.balanceOf(alice2);
// console.log("alice2BalanceAfter: ", alice2BalanceAfter);
assertEq(alice2BalanceAfter, alice2BalanceBefore + alice2Reward);
hevm.stopPrank();

Expand Down Expand Up @@ -2013,11 +1913,6 @@ contract L2StakingTest is L2StakingBaseTest {
assertEq(aliceRewards[0], aliceReward1);
assertEq(aliceRewards[1], aliceReward2);

// console.logString("......................");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logString("......................");

// *************** epoch = 4 ******************** //
time = REWARD_EPOCH * 5;
hevm.roll(blocksCountOfEpoch * 5);
Expand All @@ -2033,11 +1928,6 @@ contract L2StakingTest is L2StakingBaseTest {
IL2Staking.Undelegation[] memory undelegations = l2Staking.getUndelegations(alice);
assertEq(undelegations.length, 2);

// console.logString("......................");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logString("......................");

// *************** epoch = 5 ******************** //
time = REWARD_EPOCH * 6;
hevm.roll(blocksCountOfEpoch * 6);
Expand All @@ -2047,22 +1937,12 @@ contract L2StakingTest is L2StakingBaseTest {
aliceReward1 = distribute.queryUnclaimed(firstStaker, alice);
aliceReward2 = distribute.queryUnclaimed(secondStaker, alice);

// console.logString("......................");
// console.logUint(aliceReward1);
// console.logUint(aliceReward2);
// console.logString("......................");

hevm.startPrank(alice);
uint256 balanceBefore = morphToken.balanceOf(alice);
l2Staking.claimReward(firstStaker, 0);
l2Staking.claimReward(secondStaker, 0);
uint256 balanceAfter = morphToken.balanceOf(alice);

// console.logString("......................");
// console.logUint(balanceBefore);
// console.logUint(balanceAfter);
// console.logString("......................");

assertEq(balanceAfter, balanceBefore + aliceReward1 + aliceReward2);
hevm.stopPrank();
}
Expand Down

0 comments on commit 9474c17

Please sign in to comment.