Skip to content

Commit

Permalink
✅ Adjust tests to non escrowed rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Jul 16, 2024
1 parent b4b69a7 commit d33ee53
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 254 deletions.
31 changes: 17 additions & 14 deletions test/foundry/integration/stakingV2.migration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ contract StakingV2MigrationTests is StakingTestHelpers {
Migration Tests
//////////////////////////////////////////////////////////////*/

// @custom:todo FAIL. Reason: AmountZero()
function test_Migrate_Then_Move_Funds_From_V1_To_V2_And_Generate_New_Rewards() public {
// Stake tokens in StakingV1
fundAccountAndStakeV1(user1, 10 ether);
Expand Down Expand Up @@ -99,15 +98,25 @@ contract StakingV2MigrationTests is StakingTestHelpers {
warpAndMint(2 weeks);
warpAndMint(2 weeks);

// checks everything is staked
assertEq(kwenta.balanceOf(user1), 0);
assertEq(kwenta.balanceOf(user2), 0);
assertEq(kwenta.balanceOf(user3), 0);

// get rewards
getStakingRewardsV2(user1);
getStakingRewardsV2(user2);
getStakingRewardsV2(user3);

// assert v2 rewards have been earned
assertGt(kwenta.balanceOf(user1), 0);
assertGt(kwenta.balanceOf(user2), 0);
assertGt(kwenta.balanceOf(user3), 0);

// stake the rewards
stakeAllUnstakedEscrowV2(user1);
stakeAllUnstakedEscrowV2(user2);
stakeAllUnstakedEscrowV2(user3);
stakeFundsV2(user1, kwenta.balanceOf(user1));
stakeFundsV2(user2, kwenta.balanceOf(user2));
stakeFundsV2(user3, kwenta.balanceOf(user3));

// check StakingRewardsV1 balance unchanged
assertEq(stakingRewardsV1.nonEscrowedBalanceOf(user1), 0);
Expand Down Expand Up @@ -136,11 +145,6 @@ contract StakingV2MigrationTests is StakingTestHelpers {
user2NonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(user2);
user3NonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(user3);

// assert v2 rewards have been earned
assertGt(rewardEscrowV2.escrowedBalanceOf(user1), 0);
assertGt(rewardEscrowV2.escrowedBalanceOf(user2), 0);
assertGt(rewardEscrowV2.escrowedBalanceOf(user3), 0);

// v2 staked balance is equal to escrowed + non-escrowed balance
assertEq(stakingRewardsV2.balanceOf(user1), user1EscrowStakedV2 + user1NonEscrowedStakeV2);
assertEq(stakingRewardsV2.balanceOf(user2), user2EscrowStakedV2 + user2NonEscrowedStakeV2);
Expand All @@ -152,7 +156,6 @@ contract StakingV2MigrationTests is StakingTestHelpers {
assertEq(rewardEscrowV2.escrowedBalanceOf(user3), user3EscrowStakedV2);
}

// @custom:todo FAIL. Reason: AmountZero()
function test_Migrate_Then_Move_Funds_From_V1_To_V2_And_Generate_New_Rewards_Fuzz(
uint32 maxFundingAmount,
uint8 numberOfStakers
Expand Down Expand Up @@ -245,8 +248,11 @@ contract StakingV2MigrationTests is StakingTestHelpers {
// get rewards
getStakingRewardsV2(stakers[i]);

// assert v2 rewards have been earned
assertGt(kwenta.balanceOf(stakers[i]), 0);

// stake the rewards
stakeAllUnstakedEscrowV2(stakers[i]);
stakeFundsV2(stakers[i], kwenta.balanceOf(stakers[i]));
}

// check StakingRewardsV1 balance unchanged
Expand All @@ -266,9 +272,6 @@ contract StakingV2MigrationTests is StakingTestHelpers {
uint256 userEscrowStakedV2 = stakingRewardsV2.escrowedBalanceOf(stakers[i]);
uint256 userNonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(stakers[i]);

// assert v2 rewards have been earned
assertGt(rewardEscrowV2.escrowedBalanceOf(stakers[i]), 0);

// v2 staked balance is equal to escrowed + non-escrowed balance
assertEq(
stakingRewardsV2.balanceOf(stakers[i]), userEscrowStakedV2 + userNonEscrowedStakeV2
Expand Down
19 changes: 7 additions & 12 deletions test/foundry/integration/stakingV2.upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
Upgrade StakingRewardsV2
//////////////////////////////////////////////////////////////*/

// @custom:todo FAIL. Reason: assertion failed
function test_Upgrade_StakingRewardsV2_To_V3() public {
address stakingRewardsV3Implementation = deployStakingRewardsV3Implementation();

Expand All @@ -106,7 +105,6 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
testStakingV2StillWorking();
}

// @custom:todo FAIL. Reason: assertion failed
function test_Upgrade_And_Call_StakingRewardsV2_To_V3() public {
address stakingRewardsV3Implementation = deployStakingRewardsV3Implementation();

Expand All @@ -126,7 +124,6 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
Upgrade RewardEscrowV2
//////////////////////////////////////////////////////////////*/

// @custom:todo FAIL. Reason: assertion failed
function test_Upgrade_RewardEscrowV2_To_V3() public {
address rewardEscrowV3Implementation =
address(new MockRewardEscrowV3(address(kwenta), address(0x1)));
Expand All @@ -141,7 +138,6 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
testStakingV2StillWorking();
}

// @custom:todo FAIL. Reason: assertion failed
function test_Upgrade_And_Call_RewardEscrowV2_To_V3() public {
address rewardEscrowV3Implementation =
address(new MockRewardEscrowV3(address(kwenta), address(0x1)));
Expand All @@ -162,7 +158,6 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
UPGRADE ESCROW MIGRATOR
//////////////////////////////////////////////////////////////*/

// @custom:todo FAIL. Reason: assertion failed
function test_Upgrade_EscrowMigrator_To_V2() public {
address escrowMigratorV2Impl = deployEscrowMigratorImpl();

Expand Down Expand Up @@ -201,9 +196,7 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
{
stakingRewardsV3Implementation = address(
new MockStakingRewardsV3(
address(kwenta),
address(rewardEscrowV2),
address(rewardsNotifier)
address(kwenta), address(rewardEscrowV2), address(rewardsNotifier)
)
);
}
Expand Down Expand Up @@ -239,14 +232,16 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup {
// claim the rewards
getStakingRewardsV2(user1);
assertEq(1 ether, stakingRewardsV2.balanceOf(user1));
assertEq(2, rewardEscrowV2.balanceOf(user1));
assertEq(1 ether + 1 weeks, rewardEscrowV2.escrowedBalanceOf(user1));
assertEq(1 ether + 1 weeks, rewardEscrowV2.unstakedEscrowedBalanceOf(user1));
assertEq(1 weeks, kwenta.balanceOf(user1));
assertEq(1, rewardEscrowV2.balanceOf(user1));
assertEq(1 ether, rewardEscrowV2.escrowedBalanceOf(user1));
assertEq(1 ether, rewardEscrowV2.unstakedEscrowedBalanceOf(user1));

// stake the rewards
stakeAllUnstakedEscrowV2(user1);
stakeFundsV2(user1, 1 weeks);
assertEq(2 ether + 1 weeks, stakingRewardsV2.balanceOf(user1));
assertEq(1 ether + 1 weeks, stakingRewardsV2.escrowedBalanceOf(user1));
assertEq(1 ether, stakingRewardsV2.escrowedBalanceOf(user1));
assertEq(0, rewardEscrowV2.unstakedEscrowedBalanceOf(user1));
}

Expand Down
21 changes: 6 additions & 15 deletions test/foundry/unit/StakingRewardsV2/StakingRewardsV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup {
stakingRewardsV2.getRewardOnBehalf(address(this));
}

// @custom:todo FAIL. Reason: AmountZero()
function test_Cannot_Compound_When_Paused() public {
// fund and stake
fundAndApproveAccountV2(address(this), TEST_VALUE);
Expand All @@ -340,7 +339,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup {
stakingRewardsV2.compound();
}

// @custom:todo FAIL. Reason: AmountZero()
function test_Cannot_Compound_On_Behalf_When_Paused() public {
// approve operator
stakingRewardsV2.approveOperator(user1, true);
Expand Down Expand Up @@ -383,13 +381,7 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup {

function test_Can_Recover_Non_Staking_Token() public {
// create mockToken
IERC20 mockToken = new Kwenta(
"Mock",
"MOCK",
INITIAL_SUPPLY,
address(this),
treasury
);
IERC20 mockToken = new Kwenta("Mock", "MOCK", INITIAL_SUPPLY, address(this), treasury);

// transfer in non staking tokens
vm.prank(treasury);
Expand Down Expand Up @@ -740,15 +732,14 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup {
getReward
//////////////////////////////////////////////////////////////*/

// @custom:todo FAIL; Reason: assertion failed
function test_getReward_Increases_Balance_In_Escrow() public {
function test_getReward_Increases_Balance() public {
fundAndApproveAccountV2(address(this), TEST_VALUE);

uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this));

// stake
stakingRewardsV2.stake(TEST_VALUE);

uint256 initialBalance = kwenta.balanceOf(address(this));

// configure reward rate
vm.prank(address(rewardsNotifier));
stakingRewardsV2.notifyRewardAmount(TEST_VALUE);
Expand All @@ -759,8 +750,8 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup {
// get reward
stakingRewardsV2.getReward();

// check reward escrow balance increased
assertGt(rewardEscrowV2.escrowedBalanceOf(address(this)), initialEscrowBalance);
// check reward balance increased
assertGt(kwenta.balanceOf(address(this)), initialBalance);
}

/*//////////////////////////////////////////////////////////////
Expand Down
38 changes: 13 additions & 25 deletions test/foundry/unit/StakingRewardsV2/StakingRewardsV2Compound.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup {
Compound Function
//////////////////////////////////////////////////////////////*/

// custom:todo FAIL. Reason: AmountZero()
function test_compound() public {
fundAndApproveAccountV2(address(this), TEST_VALUE);
uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this));

// stake
stakingRewardsV2.stake(TEST_VALUE);

uint256 initialBalance = kwenta.balanceOf(address(this));

// configure reward rate
addNewRewardsToStakingRewardsV2(TEST_VALUE);

Expand All @@ -28,30 +28,24 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup {
// compound rewards
stakingRewardsV2.compound();

// check reward escrow balance increased
uint256 finalEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this));
assertGt(finalEscrowBalance, initialEscrowBalance);

// check all escrowed rewards were staked
uint256 totalRewards = finalEscrowBalance - initialEscrowBalance;
assertEq(totalRewards, stakingRewardsV2.escrowedBalanceOf(address(this)));
assertEq(totalRewards + TEST_VALUE, stakingRewardsV2.balanceOf(address(this)));
assertEq(rewardEscrowV2.unstakedEscrowedBalanceOf(address(this)), 0);
// check all rewards were staked and that staker balance increased
uint256 finalBalance = kwenta.balanceOf(address(this));
assertEq(initialBalance, finalBalance);
assertGt(stakingRewardsV2.balanceOf(address(this)), TEST_VALUE);
}

// custom:todo FAIL. Reason: AmountZero()
function test_compound_Fuzz(uint32 initialStake, uint32 newRewards) public {
vm.assume(initialStake > 0);
// need reward to be greater than duration so that reward rate is above 0
vm.assume(newRewards > stakingRewardsV2.rewardsDuration());

fundAndApproveAccountV2(address(this), initialStake);

uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this));

// stake
stakingRewardsV2.stake(initialStake);

uint256 initialBalance = kwenta.balanceOf(address(this));

// configure reward rate
addNewRewardsToStakingRewardsV2(newRewards);

Expand All @@ -61,15 +55,10 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup {
// compound rewards
stakingRewardsV2.compound();

// check reward escrow balance increased
uint256 finalEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this));
assertGt(finalEscrowBalance, initialEscrowBalance);

// check all escrowed rewards were staked
uint256 totalRewards = finalEscrowBalance - initialEscrowBalance;
assertEq(totalRewards, stakingRewardsV2.escrowedBalanceOf(address(this)));
assertEq(totalRewards + initialStake, stakingRewardsV2.balanceOf(address(this)));
assertEq(rewardEscrowV2.unstakedEscrowedBalanceOf(address(this)), 0);
// check all rewards were staked and that staker balance increased
uint256 finalBalance = kwenta.balanceOf(address(this));
assertEq(initialBalance, finalBalance);
assertGt(stakingRewardsV2.balanceOf(address(this)), initialStake);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -98,7 +87,6 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup {
Events
//////////////////////////////////////////////////////////////*/

// custom:todo FAIL. Reason: log != expected log
function test_compound_Events() public {
fundAndApproveAccountV2(address(this), TEST_VALUE);

Expand All @@ -115,7 +103,7 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup {
vm.expectEmit(true, true, false, true);
emit RewardPaid(address(this), 1 weeks);
vm.expectEmit(true, true, false, true);
emit EscrowStaked(address(this), 1 weeks);
emit Staked(address(this), 1 weeks);

// compound rewards
stakingRewardsV2.compound();
Expand Down
Loading

0 comments on commit d33ee53

Please sign in to comment.