Skip to content

Commit

Permalink
Add RewardsStore.transferNextCycleRewards tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kphed committed Nov 2, 2023
1 parent 761cc31 commit e783150
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/FeeDistributor.t.sol → test/Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {DynamicRewards} from "src/DynamicRewards.sol";
import {RewardsStore} from "src/RewardsStore.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";

contract FeeDistributorTest is Test {
contract Helper is Test {
address public constant WETH = 0x4200000000000000000000000000000000000006;
uint32 public constant REWARDS_CYCLE_LENGTH = 1 weeks;
address public immutable owner = address(this);
Expand Down
68 changes: 68 additions & 0 deletions test/RewardsStore.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {RewardsStore} from "src/RewardsStore.sol";
import {Helper} from "test/Helper.sol";

contract RewardsStoreTest is Test, Helper {
using SafeTransferLib for address;

/*//////////////////////////////////////////////////////////////
transferNextCycleRewards
//////////////////////////////////////////////////////////////*/

function testCannotTransferNextCycleRewardsUnauthorized() external {
address msgSender = address(this);

assertTrue(msgSender != dynamicRewardsStore.flywheelRewards());

vm.prank(msgSender);
vm.expectRevert(RewardsStore.Unauthorized.selector);

dynamicRewardsStore.transferNextCycleRewards();
}

function testTransferNextCycleRewards() external {
address msgSender = dynamicRewardsStore.flywheelRewards();

deal(WETH, address(dynamicRewardsStore), 1e18);

uint256 rewardsStoreWETHBalance = WETH.balanceOf(
address(dynamicRewardsStore)
);
uint256 flywheelRewardsWETHBalance = WETH.balanceOf(msgSender);

vm.prank(msgSender);

dynamicRewardsStore.transferNextCycleRewards();

assertEq(0, WETH.balanceOf(address(dynamicRewardsStore)));
assertEq(
flywheelRewardsWETHBalance + rewardsStoreWETHBalance,
WETH.balanceOf(msgSender)
);
}

function testTransferNextCycleRewardsFuzz(uint256 amount) external {
address msgSender = dynamicRewardsStore.flywheelRewards();

deal(WETH, address(dynamicRewardsStore), amount);

uint256 rewardsStoreWETHBalance = WETH.balanceOf(
address(dynamicRewardsStore)
);
uint256 flywheelRewardsWETHBalance = WETH.balanceOf(msgSender);

vm.prank(msgSender);

dynamicRewardsStore.transferNextCycleRewards();

assertEq(0, WETH.balanceOf(address(dynamicRewardsStore)));
assertEq(
flywheelRewardsWETHBalance + rewardsStoreWETHBalance,
WETH.balanceOf(msgSender)
);
}
}

0 comments on commit e783150

Please sign in to comment.