Skip to content

Commit

Permalink
improve fuzz bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 30, 2024
1 parent 0618811 commit 405dbde
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/RewardsDistributor.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {console} from "@forge-std/console.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";
Expand Down Expand Up @@ -78,12 +79,15 @@ contract RewardsDistributor is Ownable2StepUpgradeable, IRewardsDistributor {
// difference in time since last update
uint256 timeDelta = block.timestamp - rewardConfiguration.lastUpdate;

console.log("time-delta", timeDelta);

Check failure on line 82 in src/RewardsDistributor.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

if (rewardConfiguration.emissionRate == 0 || timeDelta == 0) {
// nothing to do
return 0;
}

rewards = rewardConfiguration.emissionRate * timeDelta;
console.log("rewards", rewards);

Check failure on line 90 in src/RewardsDistributor.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

// update the last update timestamp
rewardConfiguration.lastUpdate = block.timestamp;
Expand Down
24 changes: 23 additions & 1 deletion test/RewardsDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ contract RewardsDistributorTest is Test {
}

function _jumpAhead(uint256 _seconds) public {
vm.assume(_seconds != 0);
_seconds = bound(_seconds, 1, 26 weeks);
vm.warp(vm.getBlockTimestamp() + _seconds);
}

function _setRewardConfiguration(
address receiver,
uint256 emissionRate
) internal {
emissionRate = bound(emissionRate, 0, 1e18);
emissionRate = bound(emissionRate, 1, 1e18);
rewardsDistributor.setRewardConfiguration(receiver, emissionRate);
}
}
Expand All @@ -45,6 +47,8 @@ contract OwnableFunctions is RewardsDistributorTest {
address _receiver,
uint256 _emissionRate
) public {
vm.assume(_receiver != address(0));

vm.expectEmit();
emit RewardsDistributor.RewardConfigurationSet(
_receiver,
Expand All @@ -57,6 +61,8 @@ contract OwnableFunctions is RewardsDistributorTest {
address _receiver,
uint256 _emissionRate
) public {
vm.assume(_receiver != address(0));

rewardsDistributor.setRewardConfiguration(_receiver, _emissionRate);

(uint256 emissionRate, ) = rewardsDistributor.rewardConfigurations(
Expand All @@ -70,6 +76,8 @@ contract OwnableFunctions is RewardsDistributorTest {
address _receiver,
uint256 _emissionRate
) public {
vm.assume(_receiver != address(0));

rewardsDistributor.setRewardConfiguration(_receiver, _emissionRate);

(, uint256 lastUpdate) = rewardsDistributor.rewardConfigurations(
Expand Down Expand Up @@ -156,6 +164,8 @@ contract OwnableFunctions is RewardsDistributorTest {
}

function testFuzz_WithdrawFunds(address _to, uint256 _amount) public {
vm.assume(_to != address(0));

_amount = bound(_amount, 0, govToken.balanceOf(address(this)));
govToken.transfer(address(rewardsDistributor), _amount);

Expand Down Expand Up @@ -183,3 +193,15 @@ contract OwnableFunctions is RewardsDistributorTest {
rewardsDistributor.withdrawFunds(_to, _amount);
}
}

contract CollectRewards is RewardsDistributorTest {
// function testFuzz_CollectRewardsReturnsRewardAmount(address _receiver, uint256 _jump, uint256 _emisisonRate) public{
// _setRewardConfiguration(_receiver, _emisisonRate);
// uint256 timestampBefore = vm.getBlockTimestamp();
// _jumpAhead(_jump);
// uint256 expectedRewards = _emisisonRate * (block.timestamp - timestampBefore);
// vm.prank(_receiver);
// uint256 rewards = rewardsDistributor.collectRewards();
// assertEq(rewards, expectedRewards);
// }
}

0 comments on commit 405dbde

Please sign in to comment.