Skip to content

Commit

Permalink
test: Test out admin controls and fix a minor issue in the process
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnfy-view committed Nov 3, 2024
1 parent d821f4c commit 6f62d4a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/PayStreams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract PayStreams is Ownable, IPayStreams {
* @notice Allows the owner to set the gas limit for hooks.
* @param _gasLimitForHooks The gas limit for hooks.
*/
function setGasLimitForHooks(uint16 _gasLimitForHooks) external onlyOwner {
function setGasLimitForHooks(uint256 _gasLimitForHooks) external onlyOwner {
if (_gasLimitForHooks == 0) revert PayStreams__GasLimitZero();
s_gasLimitForHooks = _gasLimitForHooks;

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IPayStreams.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ interface IPayStreams {
error PayStreams__ZeroAmountToCollect();

function setFeeInBasisPoints(uint16 _feeInBasisPoints) external;
function setGasLimitForHooks(uint16 _gasLimitForHooks) external;
function setGasLimitForHooks(uint256 _gasLimitForHooks) external;
function collectFees(address _token, uint256 _amount) external;
function setStream(
StreamData calldata _streamData,
Expand Down
49 changes: 49 additions & 0 deletions test/unit/PayStreamsAdminControls.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { IPayStreams } from "../../src/interfaces/IPayStreams.sol";

import { GlobalHelper } from "../utils/GlobalHelper.sol";

contract PayStreamsAdminControlsTest is GlobalHelper {
function test_setFeeInBasisPoints() public {
uint16 newFee = 100; // 1%

_setFee(newFee);

assertEq(stream.getFeeInBasisPoints(), newFee);
}

function test_setGasLimitForHooks() public {
uint256 newGasLimit = 1_000_000;

_setGasLimitForHooks(newGasLimit);

assertEq(stream.getGasLimitForHooks(), newGasLimit);
}

function test_collectFeesFromStream() public {
uint16 newFee = 100; // 1%

_setFee(newFee);

(IPayStreams.StreamData memory streamData, IPayStreams.HookConfig memory hookConfig, string memory tag) =
_getTestStreamCreationData();
_mintAndApprove(streamData.amount);
vm.startPrank(streamer);
bytes32 streamHash = stream.setStream(streamData, hookConfig, tag);
vm.stopPrank();

_warpBy(streamData.duration);
stream.collectFundsFromStream(streamHash);

uint256 expectedFeeAmount = (streamData.amount * newFee) / BPS;
assertEq(token.balanceOf(address(stream)), expectedFeeAmount);

vm.startPrank(deployer);
stream.collectFees(address(token), expectedFeeAmount);
vm.stopPrank();
assertEq(token.balanceOf(address(deployer)), expectedFeeAmount);
assertEq(token.balanceOf(address(stream)), 0);
}
}
14 changes: 14 additions & 0 deletions test/unit/PayStreamsInitialization.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { GlobalHelper } from "../utils/GlobalHelper.sol";

contract PayStreamsInitializationTest is GlobalHelper {
function test_checkFee() public view {
assertEq(stream.getFeeInBasisPoints(), fee);
}

function test_checkGasLimitForHooks() public view {
assertEq(stream.getGasLimitForHooks(), gasLimitForHooks);
}
}

0 comments on commit 6f62d4a

Please sign in to comment.