diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ca28d4..ad8b0f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,8 @@ jobs: )" >> $GITHUB_ENV - name: Run coverage - run: forge coverage --report summary --report lcov --ir-minimum + run: forge coverage --report summary --report lcov --ir-minimum \ + --nmc IntegrationTest # To ignore coverage for certain directories modify the paths in this step as needed. The # below default ignores coverage results for the test and script directories. Alternatively, diff --git a/test/DelegateStaking.t.sol b/test/DelegateStaking.t.sol index ecd1330..29ed6fd 100644 --- a/test/DelegateStaking.t.sol +++ b/test/DelegateStaking.t.sol @@ -711,4 +711,84 @@ contract Stake is DelegateStakingTest { "Alice earn more than Bob after the attack" ); } + + function testFuzz_KeyperCanDelegateToHimself( + address _keyper, + uint256 _amount + ) public { + _amount = _boundToRealisticStake(_amount); + + _mintGovToken(_keyper, _amount); + _setKeyper(_keyper, true); + + uint256 stakeId = _stake(_keyper, _keyper, _amount); + + (address keyper, , , ) = delegate.stakes(stakeId); + + assertEq(keyper, _keyper, "Wrong keyper"); + } +} + +contract ClaimRewards is DelegateStakingTest { + function testFuzz_UpdateStakerGovTokenBalanceWhenClaimingRewards( + address _keyper, + address _depositor, + uint256 _amount, + uint256 _jump + ) public { + _amount = _boundToRealisticStake(_amount); + _jump = _boundRealisticTimeAhead(_jump); + + _mintGovToken(_depositor, _amount); + _setKeyper(_keyper, true); + + uint256 stakeId = _stake(_depositor, _keyper, _amount); + + _jumpAhead(_jump); + + vm.startPrank(_depositor); + uint256 rewards = delegate.claimRewards(0); + + uint256 expectedRewards = REWARD_RATE * (_jump); + + // need to accept a small error due to the donation attack prevention + assertApproxEqAbs( + govToken.balanceOf(_depositor), + expectedRewards, + 1e18, + "Wrong balance" + ); + } + + function testFuzz_GovTokenBalanceUnchangedWhenClaimingRewardsOnlyStaker( + 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); + + uint256 contractBalanceBefore = govToken.balanceOf(address(delegate)); + + _jumpAhead(_jump); + + vm.prank(_depositor); + delegate.claimRewards(0); + + uint256 contractBalanceAfter = govToken.balanceOf(address(delegate)); + + // small percentage lost to the vault due to the donation attack prevention + assertApproxEqAbs( + contractBalanceAfter - contractBalanceBefore, + 0, + 1e18, + "Wrong balance" + ); + } }