Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Aug 20, 2024
1 parent b7b66b5 commit fb3c863
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 65 deletions.
32 changes: 1 addition & 31 deletions test/DelegateStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -817,36 +817,6 @@ contract ClaimRewards is DelegateStakingTest {
delegate.claimRewards(0);
}

function testFuzz_ClaimAllRewardsOnlyStaker(
address _keyper,
address _depositor,
uint256 _amount,
uint256 _jump
) public {
_amount = _boundToRealisticStake(_amount);
_jump = _boundRealisticTimeAhead(_jump);

_mintGovToken(_depositor, _amount);
_setKeyper(_keyper, true);

_stake(_depositor, _keyper, _amount);

_jumpAhead(_jump);

// first 1000 shares was the dead shares so must decrease from the expected rewards
uint256 assetsAmount = _convertToAssetsIncludeRewardsDistributed(
delegate.balanceOf(_depositor),
REWARD_RATE * _jump
);

uint256 expectedRewards = assetsAmount - _amount;

vm.prank(_depositor);
uint256 rewards = delegate.claimRewards(0);

assertEq(rewards, expectedRewards, "Wrong rewards");
}

function testFuzz_ClaimRewardBurnShares(
address _keyper,
address _depositor,
Expand All @@ -867,7 +837,7 @@ contract ClaimRewards is DelegateStakingTest {

// first 1000 shares was the dead shares so must decrease from the expected rewards
uint256 assetsAmount = _convertToAssetsIncludeRewardsDistributed(
staking.balanceOf(_depositor),
delegate.balanceOf(_depositor),
REWARD_RATE * _jump
);

Expand Down
20 changes: 13 additions & 7 deletions test/RewardsDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract OwnableFunctions is RewardsDistributorTest {
assertEq(lastUpdate, vm.getBlockTimestamp());
}

function testFuzz_DoNotSetLastUpdateIfIsNotTheFirstTime(
function testFuzz_TransferTokensIfIsAnUpdate(
address _receiver,
uint256 _emissionRate
) public {
Expand All @@ -116,14 +116,20 @@ contract OwnableFunctions is RewardsDistributorTest {
_receiver
);

uint256 balanceBefore = govToken.balanceOf(_receiver);

govToken.mint(address(rewardsDistributor), _emissionRate);

vm.warp(vm.getBlockTimestamp() + 1);
rewardsDistributor.setRewardConfiguration(_receiver, _emissionRate);

assertEq(govToken.balanceOf(_receiver), balanceBefore + _emissionRate);

(, uint256 lastUpdateAfter) = rewardsDistributor.rewardConfigurations(
_receiver
);

assertEq(lastUpdateBefore, lastUpdateAfter);
assertEq(lastUpdateBefore + 1, lastUpdateAfter);
}

function testFuzz_RevertIf_SetRewardConfigurationZeroAddress(
Expand Down Expand Up @@ -240,18 +246,18 @@ contract OwnableFunctions is RewardsDistributorTest {
) public {
vm.assume(_anyone != address(this));

govToken.mint(address(rewardsDistributor), _amount);

address token = address(rewardsDistributor.rewardToken());
vm.expectRevert(
abi.encodeWithSelector(
Ownable.OwnableUnauthorizedAccount.selector,
_anyone
)
);

vm.prank(_anyone);
rewardsDistributor.withdrawFunds(
address(rewardsDistributor.rewardToken()),
_to,
_amount
);
rewardsDistributor.withdrawFunds(token, _to, _amount);
}
}

Expand Down
27 changes: 0 additions & 27 deletions test/Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -810,33 +810,6 @@ contract ClaimRewards is StakingTest {
staking.claimRewards(0);
}

function testFuzz_ClaimAllRewardsOnlyStaker(
address _depositor,
uint256 _amount,
uint256 _jump
) public {
_amount = _boundToRealisticStake(_amount);
_jump = _boundRealisticTimeAhead(_jump);

_mintGovToken(_depositor, _amount);
_setKeyper(_depositor, true);

_stake(_depositor, _amount);

uint256 timestampBefore = vm.getBlockTimestamp();

_jumpAhead(_jump);

vm.prank(_depositor);
uint256 rewards = staking.claimRewards(0);

uint256 expectedRewards = REWARD_RATE *
(vm.getBlockTimestamp() - timestampBefore);

// need to accept a small error due to the donation attack prevention
assertApproxEqAbs(rewards, expectedRewards, 1e18, "Wrong rewards");
}

function testFuzz_ClaimRewardBurnShares(
address _depositor,
uint256 _amount,
Expand Down

0 comments on commit fb3c863

Please sign in to comment.