Skip to content

Commit

Permalink
WIP: test format natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Feb 5, 2025
1 parent b97ec73 commit 3ea9d7a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Staker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall {
/// @notice Emitted when a reward notifier address is enabled or disabled.
event RewardNotifierSet(address indexed account, bool isEnabled);

event EarningPowerBumped(DepositIdentifier indexed depositId, uint256 oldEarningPower, uint256 newEarningPower, address tipReceiver, uint256 tipAmount);
/// @notice Emitted when a deposit's earning power is changed via bumping.
event EarningPowerBumped(
DepositIdentifier indexed depositId,
uint256 oldEarningPower,
uint256 newEarningPower,
address tipReceiver,
uint256 tipAmount
);

/// @notice Thrown when an account attempts a call for which it lacks appropriate permission.
/// @param reason Human readable code explaining why the call is unauthorized.
Expand Down Expand Up @@ -499,7 +506,9 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall {
revert Staker__InsufficientUnclaimedRewards();
}

emit EarningPowerBumped(_depositId, deposit.earningPower, _newEarningPower, _tipReceiver, _requestedTip);
emit EarningPowerBumped(
_depositId, deposit.earningPower, _newEarningPower, _tipReceiver, _requestedTip
);

// Update global earning power & deposit earning power based on this bump
totalEarningPower =
Expand Down
48 changes: 46 additions & 2 deletions test/Staker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2865,6 +2865,48 @@ contract BumpEarningPower is StakerRewardsTest {
assertEq(govStaker.unclaimedReward(_depositId), _unclaimedRewards - _requestedTip);
}

function testFuzz_EmitsAnEarningPowerBumpedEventWhenEarningPowerIsBumpedUp(
address _depositor,
address _delegatee,
uint256 _stakeAmount,
uint256 _rewardAmount,
address _bumpCaller,
address _tipReceiver,
uint256 _requestedTip,
uint96 _earningPowerIncrease
) public {
vm.assume(_tipReceiver != address(0) && _tipReceiver != address(govStaker));
_stakeAmount = _boundToRealisticStake(_stakeAmount);
_rewardAmount = _boundToRealisticReward(_rewardAmount);
uint256 _initialTipReceiverBalance = rewardToken.balanceOf(_tipReceiver);
_earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max));

// A user deposits staking tokens
(, Staker.DepositIdentifier _depositId) =
_boundMintAndStake(_depositor, _stakeAmount, _delegatee);
// The contract is notified of a reward
_mintTransferAndNotifyReward(_rewardAmount);
// The full duration passes
_jumpAheadByPercentOfRewardDuration(101);
// Tip must be less than the max bump, but also less than rewards for the sake of this test
_requestedTip = bound(_requestedTip, 0, _min(maxBumpTip, govStaker.unclaimedReward(_depositId)));

// The staker's earning power increases
earningPowerCalculator.__setEarningPowerForDelegatee(
_delegatee, _stakeAmount + _earningPowerIncrease
);
uint256 _oldEarningPower = _stakeAmount;
uint256 _newEarningPower = _stakeAmount + _earningPowerIncrease;

// Bump earning power is called
vm.prank(_bumpCaller);
vm.expectEmit();
emit Staker.EarningPowerBumped(
_depositId, _oldEarningPower, _newEarningPower, _tipReceiver, _requestedTip
);
govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip);
}

function testFuzz_BumpsTheDepositsEarningPowerDown(
address _depositor,
address _delegatee,
Expand Down Expand Up @@ -3055,7 +3097,7 @@ contract BumpEarningPower is StakerRewardsTest {
assertEq(govStaker.unclaimedReward(_depositId), _unclaimedReward - _requestedTip);
}

function testFuzz_EmitsAnEarningPowerBumpedEvent(
function testFuzz_EmitsAnEarningPowerBumpedEventWhenEarningPowerIsBumpedDown(
address _depositor,
address _delegatee,
uint256 _stakeAmount,
Expand Down Expand Up @@ -3091,7 +3133,9 @@ contract BumpEarningPower is StakerRewardsTest {
// Bump earning power is called
vm.prank(_bumpCaller);
vm.expectEmit();
emit Staker.EarningPowerBumped(_depositId, _oldEarningPower, _newEarningPower, _tipReceiver, _requestedTip);
emit Staker.EarningPowerBumped(
_depositId, _oldEarningPower, _newEarningPower, _tipReceiver, _requestedTip
);
govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip);
}

Expand Down

0 comments on commit 3ea9d7a

Please sign in to comment.