Skip to content

Commit

Permalink
Move, rename, and fix test to ensure rewards earned are less than rec…
Browse files Browse the repository at this point in the history
…eived
  • Loading branch information
apbendi committed Feb 7, 2024
1 parent b45f672 commit cd3d5db
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions test/UniStaker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,39 @@ contract UnclaimedRewards is UniStakerRewardsTest {
assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings);
assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings);
}

function testFuzz_CalculatesEarningsThatAreLessThanOrEqualToRewardsReceived(
address _depositor1,
address _depositor2,
address _delegatee,
uint256 _stakeAmount1,
uint256 _stakeAmount2,
uint256 _rewardAmount,
uint256 _durationPercent
) public {
vm.assume(_depositor1 != _depositor2);

(_stakeAmount1, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount1, _rewardAmount);
_stakeAmount2 = _boundToRealisticStake(_stakeAmount2);
_durationPercent = bound(_durationPercent, 0, 100);

// A user deposits staking tokens
_boundMintAndStake(_depositor1, _stakeAmount1, _delegatee);
// The contract is notified of a reward
_mintTransferAndNotifyReward(_rewardAmount);
// A portion of the duration passes
_jumpAheadByPercentOfRewardDuration(_durationPercent);
// Another user deposits stake
_boundMintAndStake(_depositor2, _stakeAmount2, _delegatee);
// The rest of the duration elapses
_jumpAheadByPercentOfRewardDuration(100 - _durationPercent);

uint256 _earned1 = uniStaker.unclaimedRewards(_depositor1);
uint256 _earned2 = uniStaker.unclaimedRewards(_depositor2);

// Rewards earned by depositors should always at most equal to the actual reward amount
assertLteWithinOnePercent(_earned1 + _earned2, _rewardAmount);
}
}

contract ClaimReward is UniStakerRewardsTest {
Expand Down Expand Up @@ -3412,42 +3445,6 @@ contract ClaimReward is UniStakerRewardsTest {
vm.prank(_depositor);
uniStaker.claimReward();
}

function testFuzz_AlwaysHasEnoughRewardsForTwoBeneficiariesToClaim(
address _depositor1,
address _depositor2,
address _delegatee,
uint256 _stakeAmount1,
uint256 _stakeAmount2,
uint256 _rewardAmount,
uint256 _durationPercent
) public {
(_stakeAmount1, _rewardAmount) = _boundToRealisticStakeAndReward(_stakeAmount1, _rewardAmount);
_stakeAmount2 = _boundToRealisticStake(_stakeAmount2);
_durationPercent = bound(_durationPercent, 0, 100);

// A user deposits staking tokens
_boundMintAndStake(_depositor1, _stakeAmount1, _delegatee);
// The contract is notified of a reward
_mintTransferAndNotifyReward(_rewardAmount);
// A portion of the duration passes
_jumpAheadByPercentOfRewardDuration(_durationPercent);
// Another user deposits stake
_boundMintAndStake(_depositor1, _stakeAmount1, _delegatee);
// The rest of the duration elapses
_jumpAheadByPercentOfRewardDuration(100 - _durationPercent);

uint256 _earned1 = uniStaker.unclaimedRewards(_depositor1);
uint256 _earned2 = uniStaker.unclaimedRewards(_depositor2);

// vm.prank(_depositor1);
// uniStaker.claimReward();

// vm.prank(_depositor2);
// uniStaker.claimReward();

//assertEq(_rewardAmount, _earned1 + _earned2);
}
}

contract _FetchOrDeploySurrogate is UniStakerRewardsTest {
Expand Down

0 comments on commit cd3d5db

Please sign in to comment.