generated from PaulRBerg/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update staking contract for v2.2
- Loading branch information
1 parent
5d37aae
commit c0c3f5e
Showing
10 changed files
with
122 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity >=0.8.19; | ||
|
||
import { StakeSablierNFT_Fork_Test } from "../StakeSablierNFT.t.sol"; | ||
|
||
contract ClaimRewards_Test is StakeSablierNFT_Fork_Test { | ||
function test_ClaimRewards_WhenNonStaker() external { | ||
// Change the caller to a staker. | ||
resetPrank({ msgSender: users.joe.addr }); | ||
|
||
// Expect no transfer. | ||
vm.expectCall({ | ||
callee: address(rewardToken), | ||
data: abi.encodeCall(rewardToken.transfer, (users.joe.addr, 0)), | ||
count: 0 | ||
}); | ||
|
||
// Claim rewards. | ||
stakingContract.claimRewards(); | ||
} | ||
|
||
modifier givenStaked() { | ||
// Change the caller to a staker. | ||
resetPrank({ msgSender: users.alice.addr }); | ||
|
||
vm.warp(block.timestamp + 1 days); | ||
_; | ||
} | ||
|
||
function test_ClaimRewards() external givenStaked { | ||
uint256 expectedReward = 1 days * rewardRate; | ||
uint256 initialBalance = rewardToken.balanceOf(users.alice.addr); | ||
|
||
// Claim the rewards. | ||
stakingContract.claimRewards(); | ||
|
||
// Assert balance increased by the expected reward. | ||
uint256 finalBalance = rewardToken.balanceOf(users.alice.addr); | ||
assertApproxEqAbs(finalBalance - initialBalance, expectedReward, 0.0001e18); | ||
|
||
// Assert rewards has been set to 0. | ||
assertEq(stakingContract.rewards(users.alice.addr), 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
claimRewards.t.sol | ||
├── given the caller is not a staker | ||
│ └── it should not transfer the rewards | ||
└── given the caller is a staker | ||
└── it should transfer the rewards |
Oops, something went wrong.