Skip to content

Commit

Permalink
fix a bug in RNTStake
Browse files Browse the repository at this point in the history
  • Loading branch information
XieJunhua committed May 12, 2024
1 parent 675515b commit 82f806b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Week4/RNTStake.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ contract RNTStake {
function deposit(uint256 amount) external refreshReward {
require(rnt.balanceOf(msg.sender) >= amount);
rnt.transferFrom(msg.sender, address(this), amount);
deposits[msg.sender] = Staking({ lastRewardTime: block.timestamp, depositAmount: amount, rewardAmount: 0 });

deposits[msg.sender] = Staking({
lastRewardTime: block.timestamp,
depositAmount: deposits[msg.sender].depositAmount + amount,
rewardAmount: deposits[msg.sender].rewardAmount
});
emit Deposit(msg.sender, amount);
}

Expand Down
16 changes: 12 additions & 4 deletions test/RNTStake.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ contract RNTStakeTest is Test {

function testDeposit() public {
deposit(alice, 1e4);
vm.warp(block.timestamp + 5 days);
deposit(alice, 1e4);

(uint256 lastRewardTime, uint256 depositAmount, uint256 rewardAmount) = rntStake.deposits(alice);

assertEq(depositAmount, 2e4);
assertEq(lastRewardTime, block.timestamp);
assertEq(rewardAmount, 5 * 1e4);
}

function testclaim() public {
Expand Down Expand Up @@ -77,10 +85,10 @@ contract RNTStakeTest is Test {
rnt.approve(address(rntStake), amount);
rntStake.deposit(amount);
// Staking s = ;
(uint256 lastRewardTime, uint256 depositAmount, uint256 rewardAmount) = rntStake.deposits(who);
assertEq(depositAmount, amount);
assertEq(lastRewardTime, block.timestamp);
assertEq(rewardAmount, 0);
// (uint256 lastRewardTime, uint256 depositAmount, uint256 rewardAmount) = rntStake.deposits(who);
// assertEq(depositAmount, amount);
// assertEq(lastRewardTime, block.timestamp);
// assertEq(rewardAmount, 0);
vm.stopPrank();
}
}

0 comments on commit 82f806b

Please sign in to comment.