diff --git a/src/SablierV2.sol b/src/SablierV2.sol index e80e9c719..72ec9f77c 100644 --- a/src/SablierV2.sol +++ b/src/SablierV2.sol @@ -14,11 +14,6 @@ abstract contract SablierV2 is ISablierV2 { /// @inheritdoc ISablierV2 uint256 public override nextStreamId; - /// INTERNAL STORAGE /// - - /// @dev Mapping from owners to creators to stream creation authorizations. - mapping(address => mapping(address => mapping(IERC20 => uint256))) internal authorizations; - /// CONSTRUCTOR /// constructor() { @@ -27,15 +22,6 @@ abstract contract SablierV2 is ISablierV2 { /// CONSTANT FUNCTIONS /// - /// @inheritdoc ISablierV2 - function getAuthorization( - address sender, - address funder, - IERC20 token - ) external view returns (uint256 authorization) { - authorization = authorizations[sender][funder][token]; - } - /// @inheritdoc ISablierV2 function getRecipient(uint256 streamId) public view virtual override returns (address recipient); @@ -82,28 +68,6 @@ abstract contract SablierV2 is ISablierV2 { } } - /// @inheritdoc ISablierV2 - function decreaseAuthorization( - address funder, - IERC20 token, - uint256 amount - ) public virtual override { - address sender = msg.sender; - uint256 newAuthorization = authorizations[sender][funder][token] - amount; - authorizeInternal(sender, funder, token, newAuthorization); - } - - /// @inheritdoc ISablierV2 - function increaseAuthorization( - address funder, - IERC20 token, - uint256 amount - ) public virtual override { - address sender = msg.sender; - uint256 newAuthorization = authorizations[sender][funder][token] + amount; - authorizeInternal(sender, funder, token, newAuthorization); - } - /// INTERNAL CONSTANT FUNCTIONS /// /// @dev Checks the basic requiremenets for the `create` function. @@ -143,25 +107,6 @@ abstract contract SablierV2 is ISablierV2 { /// INTERNAL NON-CONSTANT FUNCTIONS /// - /// @dev See the documentation for the public functions that call this internal function. - function authorizeInternal( - address sender, - address funder, - IERC20 token, - uint256 amount - ) internal virtual { - // Checks: the would-be stream sender is not the zero address. - if (sender == address(0)) { - revert SablierV2__AuthorizeSenderZeroAddress(); - } - - // Effects: update the authorization for the given sender and funder pair. - authorizations[sender][funder][token] = amount; - - // Emit an event. - emit Authorize(sender, funder, amount); - } - /// @dev See the documentation for the public functions that call this internal function. function cancelInternal(uint256 streamId) internal virtual; } diff --git a/src/SablierV2Cliff.sol b/src/SablierV2Cliff.sol index a7f3f0374..55c817b07 100644 --- a/src/SablierV2Cliff.sol +++ b/src/SablierV2Cliff.sol @@ -160,20 +160,6 @@ contract SablierV2Cliff is revert SablierV2__FunderZeroAddress(); } - // If the `funder` is not the `msg.sender`, we have to perform some authorization checks. - if (funder != msg.sender) { - // Checks: the caller has sufficient authorization to create this stream on behalf of `funder`. - uint256 authorization = authorizations[funder][msg.sender][token]; - if (authorization < depositAmount) { - revert SablierV2__InsufficientAuthorization(funder, msg.sender, token, authorization, depositAmount); - } - - // Effects: decrease the authorization since this stream consumes a part or all of it. - unchecked { - authorizeInternal(funder, msg.sender, token, authorization - depositAmount); - } - } - // Checks, Effects and Interactions: create the stream. streamId = createInternal( funder, @@ -204,20 +190,6 @@ contract SablierV2Cliff is revert SablierV2__FunderZeroAddress(); } - // If the `funder` is not the `msg.sender`, we have to perform some authorization checks. - if (funder != msg.sender) { - // Checks: `msg.sender` has sufficient authorization to create this stream on behalf of `funder`. - uint256 authorization = authorizations[funder][msg.sender][token]; - if (authorization < depositAmount) { - revert SablierV2__InsufficientAuthorization(funder, msg.sender, token, authorization, depositAmount); - } - - // Effects: decrease the authorization since this stream consumes a part or all of it. - unchecked { - authorizeInternal(funder, msg.sender, token, authorization - depositAmount); - } - } - // Calculate the cliff time and the stop time. It is fine to use unchecked arithmetic because the // `createInternal` function will nonetheless check that the stop time is greater than or equal to the // cliff time, and that the cliff time is greater than or equal to the start time. diff --git a/src/SablierV2Linear.sol b/src/SablierV2Linear.sol index 5710e5151..21e57c7f6 100644 --- a/src/SablierV2Linear.sol +++ b/src/SablierV2Linear.sol @@ -149,20 +149,6 @@ contract SablierV2Linear is uint256 stopTime, bool cancelable ) external returns (uint256 streamId) { - // If the `funder` is not the `msg.sender`, we have to perform some authorization checks. - if (funder != msg.sender) { - // Checks: the caller has sufficient authorization to create this stream on behalf of `funder`. - uint256 authorization = authorizations[funder][msg.sender][token]; - if (authorization < depositAmount) { - revert SablierV2__InsufficientAuthorization(funder, msg.sender, token, authorization, depositAmount); - } - - // Effects: decrease the authorization since this stream consumes a part of all of it. - unchecked { - authorizeInternal(funder, msg.sender, token, authorization - depositAmount); - } - } - // Checks, Effects and Interactions: create the stream. streamId = createInternal(funder, sender, recipient, depositAmount, token, startTime, stopTime, cancelable); } @@ -177,20 +163,6 @@ contract SablierV2Linear is uint256 duration, bool cancelable ) external returns (uint256 streamId) { - // If the `funder` is not the `msg.sender`, we have to perform some authorization checks. - if (funder != msg.sender) { - // Checks: `msg.sender` has sufficient authorization to create this stream on behalf of `funder`. - uint256 authorization = authorizations[funder][msg.sender][token]; - if (authorization < depositAmount) { - revert SablierV2__InsufficientAuthorization(funder, msg.sender, token, authorization, depositAmount); - } - - // Effects: decrease the authorization since this stream consumes a part or all of it. - unchecked { - authorizeInternal(funder, msg.sender, token, authorization - depositAmount); - } - } - // Calculate the stop time. It is fine to use unchecked arithmetic because the `createInternal` function will // nonetheless check that the stop time is greater than or equal to the start time. uint256 startTime = block.timestamp; diff --git a/src/SablierV2Pro.sol b/src/SablierV2Pro.sol index 2aa1be4ae..37c367d57 100644 --- a/src/SablierV2Pro.sol +++ b/src/SablierV2Pro.sol @@ -219,20 +219,6 @@ contract SablierV2Pro is revert SablierV2__FunderZeroAddress(); } - // If the `funder` is not the `msg.sender`, we have to perform some authorization checks. - if (funder != msg.sender) { - // Checks: the caller has sufficient authorization to create this stream on behalf of `funder`. - uint256 authorization = authorizations[funder][msg.sender][token]; - if (authorization < depositAmount) { - revert SablierV2__InsufficientAuthorization(funder, msg.sender, token, authorization, depositAmount); - } - - // Effects: decrease the authorization since this stream consumes a part of all of it. - unchecked { - authorizeInternal(funder, msg.sender, token, authorization - depositAmount); - } - } - // Checks, Effects and Interactions: create the stream. streamId = createInternal( funder, diff --git a/src/interfaces/ISablierV2.sol b/src/interfaces/ISablierV2.sol index 2b50156da..e8a830e34 100644 --- a/src/interfaces/ISablierV2.sol +++ b/src/interfaces/ISablierV2.sol @@ -20,15 +20,6 @@ interface ISablierV2 { /// @notice Emitted when attempting to create a stream on behalf of the zero address. error SablierV2__FunderZeroAddress(); - /// @notice Emitted when the funder does not have sufficient authorization to create a stream. - error SablierV2__InsufficientAuthorization( - address sender, - address funder, - IERC20 token, - uint256 authorization, - uint256 depositAmount - ); - /// @notice Emitted when attempting to create a stream with recipient as the zero address. error SablierV2__RecipientZeroAddress(); @@ -70,12 +61,6 @@ interface ISablierV2 { /// EVENTS /// - /// @notice Emitted when an authorization to create streams is granted. - /// @param sender The address of the would-be stream sender. - /// @param funder The address of the stream funder. - /// @param amount The authorization that can be used for creating streams, as an 18-decimal number. - event Authorize(address indexed sender, address indexed funder, uint256 amount); - /// @notice Emitted when a stream is canceled. /// @param streamId The id of the stream. /// @param recipient The address of the recipient. @@ -95,18 +80,6 @@ interface ISablierV2 { /// CONSTANT FUNCTIONS /// - /// @notice Returns the authorization that `sender` has given `funder` to create streams. - /// @param sender The address of the would-be stream sender. - /// @param funder The address of the funder. - /// @param token The ERC-20 token for which to grant the authorization. - /// @return authorization The maximum amount that can be used for creating streams, in units of the token's - /// decimals. - function getAuthorization( - address sender, - address funder, - IERC20 token - ) external view returns (uint256 authorization); - /// @notice Reads the amount deposited in the stream. /// @param streamId The id of the stream to make the query for. /// @return depositAmount The amount deposited in the stream, in units of the ERC-20 token's decimals. @@ -180,42 +153,6 @@ interface ISablierV2 { /// @param streamIds The ids of the streams to cancel. function cancelAll(uint256[] calldata streamIds) external; - /// @notice Decreases the authorization given by `msg.sender` to `funder` to create streams using their - /// `token` balance. - /// - /// @dev Emits an {Authorize} event indicating the updated authorization. - /// - /// Requirements: - /// - `funder` must not be the zero address. - /// - `funder` must have an authorization from `msg.sender` of at least `amount`. - /// - /// @param funder The address of the stream funder. - /// @param token The ERC-20 token for which to decrease the authorization. - /// @param amount The authorization to decrease, as an 18-decimal number. - function decreaseAuthorization( - address funder, - IERC20 token, - uint256 amount - ) external; - - /// @notice Increases the authorization given by `msg.sender` to `funder` to create streams using their - /// `token` balance. - /// - /// @dev Emits an {Authorize} event indicating the updated authorization. - /// - /// Requirements: - /// - `funder` must not be the zero address. - /// - The authorization calculations must not overflow uint256. - /// - /// @param funder The address of the stream funder. - /// @param token The ERC-20 token for which to increase the authorization. - /// @param amount The amount by which to increase the authorization, in units of the token's decimals. - function increaseAuthorization( - address funder, - IERC20 token, - uint256 amount - ) external; - /// @notice Counter for stream ids. /// @return The next stream id. function nextStreamId() external view returns (uint256); diff --git a/test/unit/SablierV2UnitTest.t.sol b/test/unit/SablierV2UnitTest.t.sol index a82baab65..cf944f38b 100644 --- a/test/unit/SablierV2UnitTest.t.sol +++ b/test/unit/SablierV2UnitTest.t.sol @@ -31,7 +31,8 @@ abstract contract SablierV2UnitTest is Test { uint256 internal constant TOTAL_DURATION = 10_000 seconds; uint256 internal immutable CLIFF_TIME; - uint256 internal immutable DEPOSIT_AMOUNT; + uint256 internal immutable DEPOSIT_AMOUNT_DAI; + uint256 internal immutable DEPOSIT_AMOUNT_USDC; uint256 internal immutable START_TIME; uint256 internal immutable STOP_TIME; @@ -49,7 +50,8 @@ abstract contract SablierV2UnitTest is Test { bytes32 internal nextUser = keccak256(abi.encodePacked("user address")); NonStandardERC20 internal nonStandardToken = new NonStandardERC20("Stablecoin", "USD", 18); - GodModeERC20 internal usd = new GodModeERC20("Stablecoin", "USD", 18); + GodModeERC20 internal dai = new GodModeERC20("Dai Stablecoin", "DAI", 18); + GodModeERC20 internal usdc = new GodModeERC20("USD Coin", "USDC", 6); Users internal users; /// CONSTRUCTOR /// @@ -61,7 +63,8 @@ abstract contract SablierV2UnitTest is Test { // Initialize the default stream values. CLIFF_TIME = block.timestamp + CLIFF_DURATION; - DEPOSIT_AMOUNT = bn(10_000); + DEPOSIT_AMOUNT_DAI = bn(10_000, 18); + DEPOSIT_AMOUNT_USDC = bn(10_000, 6); START_TIME = block.timestamp; STOP_TIME = block.timestamp + TOTAL_DURATION; @@ -91,11 +94,6 @@ abstract contract SablierV2UnitTest is Test { /// CONSTANT FUNCTIONS /// - /// @dev Helper function that multiplies the `amount` by `10^18` and returns a `uint256.` - function bn(uint256 amount) internal pure returns (uint256 result) { - result = bn(amount, 18); - } - /// @dev Helper function that multiplies the `amount` by `10^decimals` and returns a `uint256.` function bn(uint256 amount, uint256 decimals) internal pure returns (uint256 result) { result = amount * 10**decimals; @@ -179,8 +177,9 @@ abstract contract SablierV2UnitTest is Test { /// @dev Give user 100 ETH and 1M USD. function fundUser(address payable user) internal { vm.deal(user, 100 ether); - usd.mint(user, bn(1_000_000)); - nonStandardToken.mint(user, bn(1_000_000)); + dai.mint(user, bn(1_000_000, 18)); + usdc.mint(user, bn(1_000_000, 6)); + nonStandardToken.mint(user, bn(1_000_000, 18)); } /// @dev Converts bytes32 to address. diff --git a/test/unit/abstract-sablier-v2/decrease-authorization/decreaseAuthorization.t.sol b/test/unit/abstract-sablier-v2/decrease-authorization/decreaseAuthorization.t.sol deleted file mode 100644 index cc2454363..000000000 --- a/test/unit/abstract-sablier-v2/decrease-authorization/decreaseAuthorization.t.sol +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.13; - -import { ISablierV2 } from "@sablier/v2-core/interfaces/ISablierV2.sol"; - -import { stdError } from "forge-std/Test.sol"; - -import { AbstractSablierV2UnitTest } from "../AbstractSablierV2UnitTest.t.sol"; - -contract AbstractSablierV2__UnitTest__DecreaseAuthorization is AbstractSablierV2UnitTest { - /// @dev When the calculation underflows uint256, it should revert. - function testCannotDecreaseAuthorization__Underflow() external { - vm.expectRevert(stdError.arithmeticError); - uint256 amount = 1; - abstractSablierV2.decreaseAuthorization(users.funder, usd, amount); - } - - /// @dev When the authorization is decreased entirely, it should set the authorization to zero. - function testDecreaseAuthorization__DecreaseEntirely() external { - // Increase the authorization. - uint256 authorization = DEPOSIT_AMOUNT; - abstractSablierV2.increaseAuthorization(users.funder, usd, authorization); - - // Run the test. - abstractSablierV2.decreaseAuthorization(users.funder, usd, authorization); - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = 0; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When the authorization is decreased partially, it should emit an Authorize event. - function testDecreaseAuthorization__DecreasePartially(uint256 firstAmount, uint256 secondAmount) external { - // Bound the first authorization to be greater than the second authorization. - vm.assume(firstAmount > secondAmount); - abstractSablierV2.increaseAuthorization(users.funder, usd, firstAmount); - - // Run the test. - abstractSablierV2.decreaseAuthorization(users.funder, usd, secondAmount); - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = firstAmount - secondAmount; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When the authorization is decreased partially, it should emit an Authorize event. - function testDecreaseAuthorization__DecreasePartially__Event(uint256 firstAmount, uint256 secondAmount) external { - // Bound the first authorization to be greater than the second authorization. - vm.assume(firstAmount > secondAmount); - abstractSablierV2.increaseAuthorization(users.funder, usd, firstAmount); - - // Run the test. - vm.expectEmit(true, true, false, true); - uint256 authorization = firstAmount - secondAmount; - emit Authorize(users.sender, users.funder, authorization); - abstractSablierV2.decreaseAuthorization(users.funder, usd, secondAmount); - } -} diff --git a/test/unit/abstract-sablier-v2/decrease-authorization/decreaseAuthorization.tree b/test/unit/abstract-sablier-v2/decrease-authorization/decreaseAuthorization.tree deleted file mode 100644 index 47d085e59..000000000 --- a/test/unit/abstract-sablier-v2/decrease-authorization/decreaseAuthorization.tree +++ /dev/null @@ -1,10 +0,0 @@ -decreaseAuthorization.t.sol -├── when the calculation underflows uint256 -│ └── it should revert -└── when the calculation does not underflow uint256 - ├── when the authorization is decreased entirely - │ └── it should set the authorization to zero - └── when the authorization is decreased partially - ├── it should decrease the authorization - └── it should emit an Authorize event - diff --git a/test/unit/abstract-sablier-v2/get-authorization/getAuthorization.t.sol b/test/unit/abstract-sablier-v2/get-authorization/getAuthorization.t.sol deleted file mode 100644 index 1eee6a7c1..000000000 --- a/test/unit/abstract-sablier-v2/get-authorization/getAuthorization.t.sol +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.13; - -import { ISablierV2 } from "@sablier/v2-core/interfaces/ISablierV2.sol"; - -import { AbstractSablierV2UnitTest } from "../AbstractSablierV2UnitTest.t.sol"; - -contract AbstractSablierV2__UnitTest__GetAuthorization is AbstractSablierV2UnitTest { - /// @dev When the authorization is not set, it should return zero. - function testGetAuthorization__AuthorizationNotSet() external { - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = 0; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When the authorization is not set, it should return the correct authorization. - function testGetAuthorization__AuthorizationSet() external { - uint256 authorization = DEPOSIT_AMOUNT; - abstractSablierV2.increaseAuthorization(users.funder, usd, authorization); - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = authorization; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When all checks pass, it should emit an Authorize event. - function testDecreaseAuthorization__Event() external { - uint256 amount = DEPOSIT_AMOUNT; - abstractSablierV2.increaseAuthorization(users.funder, usd, amount); - vm.expectEmit(true, true, false, true); - emit Authorize(users.sender, users.funder, 0); - abstractSablierV2.decreaseAuthorization(users.funder, usd, amount); - } -} diff --git a/test/unit/abstract-sablier-v2/get-authorization/getAuthorization.tree b/test/unit/abstract-sablier-v2/get-authorization/getAuthorization.tree deleted file mode 100644 index 8ebd29b39..000000000 --- a/test/unit/abstract-sablier-v2/get-authorization/getAuthorization.tree +++ /dev/null @@ -1,6 +0,0 @@ -getAuthorization.t.sol -├── when the authorization is not set -│ └── it should return zero -└── when the authorization is set - └── it should return the correct authorization - diff --git a/test/unit/abstract-sablier-v2/increase-authorization/increaseAuthorization.t.sol b/test/unit/abstract-sablier-v2/increase-authorization/increaseAuthorization.t.sol deleted file mode 100644 index 80aaa0a8a..000000000 --- a/test/unit/abstract-sablier-v2/increase-authorization/increaseAuthorization.t.sol +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.13; - -import { ISablierV2 } from "@sablier/v2-core/interfaces/ISablierV2.sol"; - -import { stdError } from "forge-std/Test.sol"; - -import { AbstractSablierV2UnitTest } from "../AbstractSablierV2UnitTest.t.sol"; - -contract AbstractSablierV2__UnitTest__IncreaseAuthorization is AbstractSablierV2UnitTest { - /// @dev When the calculation overflows uint256, it should revert. - function testCannotIncreaseAuthorization__Overflow() external { - abstractSablierV2.increaseAuthorization(users.funder, usd, 1); - vm.expectRevert(stdError.arithmeticError); - abstractSablierV2.increaseAuthorization(users.funder, usd, MAX_UINT_256); - } - - /// @dev When the sender is the zero address, it should revert. - function testCannotIncreaseAuthorization__SenderZeroAddress() external { - // Make the zero address the `msg.sender` in this test case. - changePrank(address(0)); - - // Run the test. - vm.expectRevert(ISablierV2.SablierV2__AuthorizeSenderZeroAddress.selector); - uint256 authorization = DEPOSIT_AMOUNT; - abstractSablierV2.increaseAuthorization(users.funder, usd, authorization); - } - - /// @dev When the amount is zero, it should not increase the authorization. - function testIncreaseAuthorization__AmountZero() external { - uint256 authorization = 0; - abstractSablierV2.increaseAuthorization(users.funder, usd, authorization); - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = 0; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When the current authorization is zero, it should not increase the authorization. - function testIncreaseAuthorization__CurrentAuthorizationZero(uint256 authorization) external { - abstractSablierV2.increaseAuthorization(users.funder, usd, authorization); - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = authorization; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When the current authorization is not zero, it should increase the authorization. - function testIncreaseAuthorization__CurrentAuthorizationNonZero(uint256 firstAmount, uint256 secondAmount) - external - { - // Bound the two inputs to max uint256. - vm.assume(firstAmount <= MAX_UINT_256 - secondAmount); - abstractSablierV2.increaseAuthorization(users.funder, usd, firstAmount); - - // Run the test. - abstractSablierV2.increaseAuthorization(users.funder, usd, secondAmount); - uint256 actualAuthorization = abstractSablierV2.getAuthorization(users.sender, users.funder, usd); - uint256 expectedAuthorization = firstAmount + secondAmount; - assertEq(actualAuthorization, expectedAuthorization); - } - - /// @dev When the current authorization is not zero, it should emit an Authorize event. - function testIncreaseAuthorization__CurrentAuthorizationNonZero__Event(uint256 firstAmount, uint256 secondAmount) - external - { - // Bound the two inputs to max uint256. - vm.assume(firstAmount <= MAX_UINT_256 - secondAmount); - abstractSablierV2.increaseAuthorization(users.funder, usd, firstAmount); - - // Run the test. - vm.expectEmit(true, true, false, true); - uint256 authorization = firstAmount + secondAmount; - emit Authorize(users.sender, users.funder, authorization); - abstractSablierV2.increaseAuthorization(users.funder, usd, secondAmount); - } -} diff --git a/test/unit/abstract-sablier-v2/increase-authorization/increaseAuthorization.tree b/test/unit/abstract-sablier-v2/increase-authorization/increaseAuthorization.tree deleted file mode 100644 index 37223c450..000000000 --- a/test/unit/abstract-sablier-v2/increase-authorization/increaseAuthorization.tree +++ /dev/null @@ -1,15 +0,0 @@ -increaseAuthorization.t.sol -├── when the calculation overflows uint256 -│ └── it should revert -└── when the calculation does not overflow uint256 - ├── when the sender is the zero address - │ └── it should revert - └── when the sender is not the zero address - ├── when the amount is zero - │ └── it should not increase the authorization - └── when the amount is not zero - ├── when the current authorization is zero - │ └── it should increase the authorization - └── when the current authorization is not zero - ├── it should increase the authorization - └── it should emit an Authorize event diff --git a/test/unit/sablier-v2-cliff/SablierV2CliffUnitTest.t.sol b/test/unit/sablier-v2-cliff/SablierV2CliffUnitTest.t.sol index c33a7c3c6..4a3eb3d33 100644 --- a/test/unit/sablier-v2-cliff/SablierV2CliffUnitTest.t.sol +++ b/test/unit/sablier-v2-cliff/SablierV2CliffUnitTest.t.sol @@ -30,52 +30,69 @@ abstract contract SablierV2CliffUnitTest is SablierV2UnitTest { /// CONSTANTS /// uint256 internal constant TIME_OFFSET = 2_600 seconds; - uint256 internal immutable WITHDRAW_AMOUNT = bn(2_600); + uint256 internal immutable WITHDRAW_AMOUNT_DAI = bn(2_600, 18); + uint256 internal immutable WITHDRAW_AMOUNT_USDC = bn(2_600, 6); /// TESTING VARIABLES /// SablierV2Cliff internal sablierV2Cliff = new SablierV2Cliff(); - ISablierV2Cliff.Stream internal stream; + ISablierV2Cliff.Stream internal daiStream; + ISablierV2Cliff.Stream internal usdcStream; // SETUP FUNCTION /// /// @dev A setup function invoked before each test case. function setUp() public virtual { - // Create the default stream to be used across many tests. - stream = ISablierV2Cliff.Stream({ + // Create the default streams to be used across the tests. + daiStream = ISablierV2Cliff.Stream({ cancelable: true, cliffTime: CLIFF_TIME, - depositAmount: DEPOSIT_AMOUNT, + depositAmount: DEPOSIT_AMOUNT_DAI, recipient: users.recipient, sender: users.sender, startTime: START_TIME, stopTime: STOP_TIME, - token: usd, + token: dai, + withdrawnAmount: 0 + }); + usdcStream = ISablierV2Cliff.Stream({ + cancelable: true, + cliffTime: CLIFF_TIME, + depositAmount: DEPOSIT_AMOUNT_USDC, + recipient: users.recipient, + sender: users.sender, + startTime: START_TIME, + stopTime: STOP_TIME, + token: usdc, withdrawnAmount: 0 }); - // Approve the SablierV2Cliff contract to spend $USD from the `sender` account. - vm.prank(users.sender); - usd.approve(address(sablierV2Cliff), MAX_UINT_256); - - // Approve the SablierV2Cliff contract to spend non-standard tokens from the `sender` account. - vm.prank(users.sender); + // Approve the SablierV2Cliff contract to spend tokens from the sender. + vm.startPrank(users.sender); + dai.approve(address(sablierV2Cliff), MAX_UINT_256); + usdc.approve(address(sablierV2Cliff), MAX_UINT_256); nonStandardToken.approve(address(sablierV2Cliff), MAX_UINT_256); - // Approve the SablierV2Cliff contract to spend $USD from the `recipient` account. - vm.prank(users.recipient); - usd.approve(address(sablierV2Cliff), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from the recipient. + changePrank(users.recipient); + dai.approve(address(sablierV2Cliff), MAX_UINT_256); + usdc.approve(address(sablierV2Cliff), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Cliff), MAX_UINT_256); - // Approve the SablierV2Cliff contract to spend $USD from the `funder` account. - vm.prank(users.funder); - usd.approve(address(sablierV2Cliff), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from the funder. + changePrank(users.funder); + dai.approve(address(sablierV2Cliff), MAX_UINT_256); + usdc.approve(address(sablierV2Cliff), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Cliff), MAX_UINT_256); - // Approve the SablierV2Cliff contract to spend $USD from the `eve` account. - vm.prank(users.eve); - usd.approve(address(sablierV2Cliff), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from eve. + changePrank(users.eve); + dai.approve(address(sablierV2Cliff), MAX_UINT_256); + usdc.approve(address(sablierV2Cliff), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Cliff), MAX_UINT_256); // Sets all subsequent calls' `msg.sender` to be `sender`. - vm.startPrank(users.sender); + changePrank(users.sender); } /// NON-CONSTANT FUNCTIONS /// @@ -93,33 +110,48 @@ abstract contract SablierV2CliffUnitTest is SablierV2UnitTest { assertEq(a.withdrawnAmount, b.withdrawnAmount); } - /// @dev Helper function to create a default stream. - function createDefaultStream() internal returns (uint256 streamId) { - streamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + /// @dev Helper function to create a default stream with $DAI used as streaming currency. + function createDefaultDaiStream() internal returns (uint256 daiStreamId) { + daiStreamId = sablierV2Cliff.create( + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable + ); + } + + /// @dev Helper function to create a default stream with $USDC used as streaming currency. + function createDefaultUsdcStream() internal returns (uint256 usdcStreamId) { + usdcStreamId = sablierV2Cliff.create( + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + usdcStream.cliffTime, + usdcStream.stopTime, + usdcStream.cancelable ); } - /// @dev Helper function to create a non-cancelable stream. - function createNonCancelableStream() internal returns (uint256 nonCancelableStreamId) { + /// @dev Helper function to create a non-cancelable stream with $DAI used as streaming currency. + function createNonCancelableDaiStream() internal returns (uint256 nonCancelableDaiStreamId) { bool cancelable = false; - nonCancelableStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, + nonCancelableDaiStreamId = sablierV2Cliff.create( + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, cancelable ); } diff --git a/test/unit/sablier-v2-cliff/cancel-all/cancelAll.t.sol b/test/unit/sablier-v2-cliff/cancel-all/cancelAll.t.sol index e86fe3205..5943e9e17 100644 --- a/test/unit/sablier-v2-cliff/cancel-all/cancelAll.t.sol +++ b/test/unit/sablier-v2-cliff/cancel-all/cancelAll.t.sol @@ -14,8 +14,8 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { super.setUp(); // Create the default streams, since most tests need them. - defaultStreamIds.push(createDefaultStream()); - defaultStreamIds.push(createDefaultStream()); + defaultStreamIds.push(createDefaultDaiStream()); + defaultStreamIds.push(createDefaultDaiStream()); } /// @dev When the stream ids array points only to non existent streams, it should do nothing. @@ -57,13 +57,13 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { uint256 eveStreamId = sablierV2Cliff.create( users.eve, users.eve, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); // Run the test. @@ -93,20 +93,20 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { /// @dev When all streams are non-cancelable, it should do nothing. function testCannotCancelAll__AllStreamsNonCancelable() external { // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. - uint256[] memory nonCancelableStreamIds = createDynamicArray(nonCancelableStreamId); + uint256[] memory nonCancelableStreamIds = createDynamicArray(nonCancelableDaiStreamId); sablierV2Cliff.cancelAll(nonCancelableStreamIds); } /// @dev When some streams are non-cancelable, it should cancel and delete the cancelable streams. function testCannotCancelAll__SomeStreamsNonCancelable() external { // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. - uint256[] memory streamIds = createDynamicArray(defaultStreamIds[0], nonCancelableStreamId); + uint256[] memory streamIds = createDynamicArray(defaultStreamIds[0], nonCancelableDaiStreamId); sablierV2Cliff.cancelAll(streamIds); ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(defaultStreamIds[0]); ISablierV2Cliff.Stream memory expectedStream; @@ -116,7 +116,7 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { /// @dev When all streams are ended, it should cancel and delete the streams. function testCancelAll__AllStreamsEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. sablierV2Cliff.cancelAll(defaultStreamIds); @@ -132,16 +132,16 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { /// @dev When all streams are ended, it should emit multiple Cancel events. function testCancelAll__AllStreamsEnded__Events() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; uint256 returnAmount = 0; vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[0], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[0], daiStream.recipient, withdrawAmount, returnAmount); vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[1], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[1], daiStream.recipient, withdrawAmount, returnAmount); uint256[] memory streamIds = createDynamicArray(defaultStreamIds[0], defaultStreamIds[1]); sablierV2Cliff.cancelAll(streamIds); @@ -150,7 +150,7 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { /// @dev When all streams are ongoing, it should cancel and delete the streams. function testCancelAll__AllStreamsOngoing() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.cancelAll(defaultStreamIds); @@ -166,40 +166,40 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { /// @dev When all streams are ongoing, it should emit multiple Cancel events. function testCancelAll__AllStreamsOngoing__Events() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; - uint256 returnAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; + uint256 returnAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[0], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[0], daiStream.recipient, withdrawAmount, returnAmount); vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[1], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[1], daiStream.recipient, withdrawAmount, returnAmount); sablierV2Cliff.cancelAll(defaultStreamIds); } /// @dev When some of the streams are ended and some are ongoing, it should cancel and delete the streams. function testCancelAll__SomeStreamsEndedSomeStreamsOngoing() external { - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Create the ended stream. - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - // Warp to the end of the first stream. + // Warp to the end of the first daiStream. vm.warp(earlyStopTime); // Run the test. @@ -216,36 +216,36 @@ contract SablierV2Cliff__UnitTest__CancelAll is SablierV2CliffUnitTest { /// @dev When some of the streams are ended and some are ongoing, it should emit multiple Cancel events. function testCancelAll__SomeStreamsEndedSomeStreamsOngoing__Events() external { - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Create the ended stream. - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - // Warp to the end of the first stream. + // Warp to the end of the first daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; + uint256 endedWithdrawAmount = daiStream.depositAmount; uint256 endedReturnAmount = 0; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; - uint256 ongoingReturnAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; + uint256 ongoingReturnAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Cancel(endedStreamId, stream.recipient, endedWithdrawAmount, endedReturnAmount); + emit Cancel(endedStreamId, daiStream.recipient, endedWithdrawAmount, endedReturnAmount); vm.expectEmit(true, true, false, true); - emit Cancel(ongoingStreamId, stream.recipient, ongoingWithdrawAmount, ongoingReturnAmount); + emit Cancel(ongoingStreamId, daiStream.recipient, ongoingWithdrawAmount, ongoingReturnAmount); uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); sablierV2Cliff.cancelAll(streamIds); diff --git a/test/unit/sablier-v2-cliff/cancel/cancel.t.sol b/test/unit/sablier-v2-cliff/cancel/cancel.t.sol index 8dd24c543..5dd0581b6 100644 --- a/test/unit/sablier-v2-cliff/cancel/cancel.t.sol +++ b/test/unit/sablier-v2-cliff/cancel/cancel.t.sol @@ -14,7 +14,7 @@ contract SablierV2Cliff__UnitTest__Cancel is SablierV2CliffUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should revert. @@ -49,19 +49,19 @@ contract SablierV2Cliff__UnitTest__Cancel is SablierV2CliffUnitTest { /// @dev When the stream is non-cancelable, it should revert. function testCannotCancel__StreamNonCancelable() external { // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. vm.expectRevert( - abi.encodeWithSelector(ISablierV2.SablierV2__StreamNonCancelable.selector, nonCancelableStreamId) + abi.encodeWithSelector(ISablierV2.SablierV2__StreamNonCancelable.selector, nonCancelableDaiStreamId) ); - sablierV2Cliff.cancel(nonCancelableStreamId); + sablierV2Cliff.cancel(nonCancelableDaiStreamId); } /// @dev When the stream ended, it should cancel and delete the stream. function testCancel__StreamEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. sablierV2Cliff.cancel(streamId); @@ -73,20 +73,20 @@ contract SablierV2Cliff__UnitTest__Cancel is SablierV2CliffUnitTest { /// @dev When the stream ended, it should emit a Cancel event. function testCancel__StreamEnded__Event() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. vm.expectEmit(true, true, false, true); - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; uint256 returnAmount = 0; - emit Cancel(streamId, stream.recipient, withdrawAmount, returnAmount); + emit Cancel(streamId, daiStream.recipient, withdrawAmount, returnAmount); sablierV2Cliff.cancel(streamId); } /// @dev When the stream is ongoing, it should cancel and delete the stream. function testCancel__StreamOngoing() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.cancel(streamId); @@ -98,13 +98,13 @@ contract SablierV2Cliff__UnitTest__Cancel is SablierV2CliffUnitTest { /// @dev When the stream is ongoing, it should emit a Cancel event. function testCancel__StreamOngoing__Event() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; - uint256 returnAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; + uint256 returnAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Cancel(streamId, stream.recipient, withdrawAmount, returnAmount); + emit Cancel(streamId, daiStream.recipient, withdrawAmount, returnAmount); sablierV2Cliff.cancel(streamId); } } diff --git a/test/unit/sablier-v2-cliff/create-with-duration/createWithDuration.t.sol b/test/unit/sablier-v2-cliff/create-with-duration/createWithDuration.t.sol index 854d07851..0c486dad6 100644 --- a/test/unit/sablier-v2-cliff/create-with-duration/createWithDuration.t.sol +++ b/test/unit/sablier-v2-cliff/create-with-duration/createWithDuration.t.sol @@ -28,14 +28,14 @@ contract SablierV2Cliff__UnitTest__CreateWithDuration is SablierV2CliffUnitTest ) ); sablierV2Cliff.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, cliffDuration, totalDuration, - stream.cancelable + daiStream.cancelable ); } @@ -58,14 +58,14 @@ contract SablierV2Cliff__UnitTest__CreateWithDuration is SablierV2CliffUnitTest ) ); sablierV2Cliff.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, cliffDuration, totalDuration, - stream.cancelable + daiStream.cancelable ); } @@ -80,24 +80,24 @@ contract SablierV2Cliff__UnitTest__CreateWithDuration is SablierV2CliffUnitTest stopTime = block.timestamp + totalDuration; } uint256 streamId = sablierV2Cliff.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, cliffDuration, totalDuration, - stream.cancelable + daiStream.cancelable ); - ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(stream.startTime, createdStream.startTime); - assertEq(cliffTime, createdStream.cliffTime); - assertEq(stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId); + assertEq(actualStream.sender, daiStream.sender); + assertEq(actualStream.recipient, daiStream.recipient); + assertEq(actualStream.depositAmount, daiStream.depositAmount); + assertEq(actualStream.token, daiStream.token); + assertEq(actualStream.startTime, daiStream.startTime); + assertEq(actualStream.cliffTime, cliffTime); + assertEq(actualStream.stopTime, stopTime); + assertEq(actualStream.cancelable, daiStream.cancelable); + assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount); } } diff --git a/test/unit/sablier-v2-cliff/create/create.t.sol b/test/unit/sablier-v2-cliff/create/create.t.sol index 93f7ecaf3..deee5dfdc 100644 --- a/test/unit/sablier-v2-cliff/create/create.t.sol +++ b/test/unit/sablier-v2-cliff/create/create.t.sol @@ -15,15 +15,15 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest { vm.expectRevert(ISablierV2.SablierV2__RecipientZeroAddress.selector); address recipient = address(0); sablierV2Cliff.create( - stream.sender, - stream.sender, + daiStream.sender, + daiStream.sender, recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); } @@ -32,69 +32,69 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest { vm.expectRevert(ISablierV2.SablierV2__DepositAmountZero.selector); uint256 depositAmount = 0; sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, + daiStream.sender, + daiStream.sender, + daiStream.recipient, depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); } /// @dev When the start time is greater than the stop time, it should revert. function testCannotCreate__StartTimeGreaterThanStopTime() external { - uint256 startTime = stream.stopTime; - uint256 stopTime = stream.startTime; + uint256 startTime = daiStream.stopTime; + uint256 stopTime = daiStream.startTime; vm.expectRevert( abi.encodeWithSelector(ISablierV2.SablierV2__StartTimeGreaterThanStopTime.selector, startTime, stopTime) ); sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, startTime, - stream.cliffTime, + daiStream.cliffTime, stopTime, - stream.cancelable + daiStream.cancelable ); } /// @dev When the start time is equal to the stop time, it should create the stream. function testCreate__StartTimeEqualToStopTime() external { - uint256 cliffTime = stream.startTime; - uint256 stopTime = stream.startTime; + uint256 cliffTime = daiStream.startTime; + uint256 stopTime = daiStream.startTime; uint256 streamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, cliffTime, stopTime, - stream.cancelable + daiStream.cancelable ); ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(stream.startTime, createdStream.startTime); + assertEq(daiStream.sender, createdStream.sender); + assertEq(daiStream.recipient, createdStream.recipient); + assertEq(daiStream.depositAmount, createdStream.depositAmount); + assertEq(daiStream.token, createdStream.token); + assertEq(daiStream.startTime, createdStream.startTime); assertEq(cliffTime, createdStream.cliffTime); assertEq(stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(daiStream.cancelable, createdStream.cancelable); + assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount); } /// @dev When the start time is greater than the cliff time, is should revert. function testCannotCreate__StartTimeGreaterThanCliffTime() external { - uint256 startTime = stream.cliffTime; - uint256 cliffTime = stream.startTime; + uint256 startTime = daiStream.cliffTime; + uint256 cliffTime = daiStream.startTime; vm.expectRevert( abi.encodeWithSelector( ISablierV2Cliff.SablierV2Cliff__StartTimeGreaterThanCliffTime.selector, @@ -103,48 +103,22 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest { ) ); sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, startTime, cliffTime, - stream.stopTime, - stream.cancelable + daiStream.stopTime, + daiStream.cancelable ); } - /// @dev When the cliff time is equal to the stop time, it should create the stream. - function testCreate__CliffTimeEqualStopTime() external { - uint256 cliffTime = stream.stopTime; - uint256 streamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - cliffTime, - stream.stopTime, - stream.cancelable - ); - ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(stream.startTime, createdStream.startTime); - assertEq(cliffTime, createdStream.cliffTime); - assertEq(stream.stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); - } - /// @dev When the cliff time is greater than the stop time, is should revert. function testCannotCreate__CliffTimeGreaterThanStopTime() external { - uint256 cliffTime = stream.stopTime; - uint256 stopTime = stream.cliffTime; + uint256 cliffTime = daiStream.stopTime; + uint256 stopTime = daiStream.cliffTime; vm.expectRevert( abi.encodeWithSelector( ISablierV2Cliff.SablierV2Cliff__CliffTimeGreaterThanStopTime.selector, @@ -153,42 +127,42 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest { ) ); sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, cliffTime, stopTime, - stream.cancelable + daiStream.cancelable ); } - /// @dev When the cliff time is the equal to the stop time, it should create the stream. + /// @dev When the cliff time is equal to the stop time, it should create the stream. function testCreate__CliffTimeEqualToStopTime() external { - uint256 cliffTime = stream.stopTime; + uint256 cliffTime = daiStream.stopTime; uint256 streamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, cliffTime, - stream.cancelable + daiStream.stopTime, + daiStream.cancelable ); - ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(stream.startTime, createdStream.startTime); - assertEq(cliffTime, createdStream.cliffTime); - assertEq(stream.stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId); + assertEq(actualStream.sender, daiStream.sender); + assertEq(actualStream.recipient, daiStream.recipient); + assertEq(actualStream.depositAmount, daiStream.depositAmount); + assertEq(actualStream.token, daiStream.token); + assertEq(actualStream.startTime, daiStream.startTime); + assertEq(actualStream.cliffTime, cliffTime); + assertEq(actualStream.stopTime, daiStream.stopTime); + assertEq(actualStream.cancelable, daiStream.cancelable); + assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount); } /// @dev When the token is not a contract, it should revert. @@ -196,15 +170,15 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest { vm.expectRevert(abi.encodeWithSelector(SafeERC20__CallToNonContract.selector, address(6174))); IERC20 token = IERC20(address(6174)); sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); } @@ -213,61 +187,97 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest { IERC20 token = IERC20(address(nonStandardToken)); uint256 streamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); + assertEq(daiStream.sender, createdStream.sender); + assertEq(daiStream.recipient, createdStream.recipient); + assertEq(daiStream.depositAmount, createdStream.depositAmount); assertEq(address(nonStandardToken), address(createdStream.token)); - assertEq(stream.startTime, createdStream.startTime); - assertEq(stream.cliffTime, createdStream.cliffTime); - assertEq(stream.stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(daiStream.startTime, createdStream.startTime); + assertEq(daiStream.cliffTime, createdStream.cliffTime); + assertEq(daiStream.stopTime, createdStream.stopTime); + assertEq(daiStream.cancelable, createdStream.cancelable); + assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount); + } + + /// @dev When all checks pass and the token has 6 decimals, it should create the stream. + function testCreate__6Decimals() external { + uint256 streamId = createDefaultUsdcStream(); + ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId); + ISablierV2Cliff.Stream memory expectedStream = usdcStream; + assertEq(actualStream, expectedStream); + } + + /// @dev When all checks pass and the token has 6 decimals, it should bump the next stream id. + function testCreate__6Decimals__NextStreamId() external { + uint256 nextStreamId = sablierV2Cliff.nextStreamId(); + createDefaultUsdcStream(); + uint256 actualNextStreamId = sablierV2Cliff.nextStreamId(); + uint256 expectedNextStreamId = nextStreamId + 1; + assertEq(actualNextStreamId, expectedNextStreamId); + } + + /// @dev When all checks pass and the token has 6 decimals, it should emit a CreateStream event. + function testCreate__6Decimals__Event() external { + uint256 streamId = sablierV2Cliff.nextStreamId(); + vm.expectEmit(true, true, true, true); + emit CreateStream( + streamId, + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + usdcStream.cliffTime, + usdcStream.stopTime, + usdcStream.cancelable + ); + createDefaultUsdcStream(); } - /// @dev When all checks pass, it should create the stream. - function testCreate() external { - uint256 streamId = createDefaultStream(); + /// @dev When all checks pass and the token has 18 decimals, it should create the stream. + function testCreate__18Decimals() external { + uint256 streamId = createDefaultDaiStream(); ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId); - assertEq(stream, createdStream); + assertEq(daiStream, createdStream); } - /// @dev When all checks pass, it should bump the next stream id. - function testCreate__NextStreamId() external { + /// @dev When all checks pass and the token has 18 decimals, it should bump the next stream id. + function testCreate__18Decimals__NextStreamId() external { uint256 nextStreamId = sablierV2Cliff.nextStreamId(); - createDefaultStream(); + createDefaultDaiStream(); uint256 actualNextStreamId = sablierV2Cliff.nextStreamId(); uint256 expectedNextStreamId = nextStreamId + 1; assertEq(actualNextStreamId, expectedNextStreamId); } - /// @dev When all checks pass, it should emit a CreateStream event. - function testCreate__Event() external { + /// @dev When all checks pass and the token has 18 decimals, it should emit a CreateStream event. + function testCreate__18Decimals__Event() external { uint256 streamId = sablierV2Cliff.nextStreamId(); vm.expectEmit(true, true, true, true); emit CreateStream( streamId, - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); - createDefaultStream(); + createDefaultDaiStream(); } } diff --git a/test/unit/sablier-v2-cliff/create/create.tree b/test/unit/sablier-v2-cliff/create/create.tree index ed68cb86c..ce4315e3d 100644 --- a/test/unit/sablier-v2-cliff/create/create.tree +++ b/test/unit/sablier-v2-cliff/create/create.tree @@ -25,6 +25,11 @@ create.t.sol ├── when the token misses the return value │ └── it should create the stream └── when the token is ERC-20 compliant - ├── it should create the stream - ├── it should bump the next stream id - └── it should emit a CreateStream event + ├── when the token has 6 decimals + │ ├── it should create the stream + │ ├── it should bump the next stream id + │ └── it should emit a CreateStream event + └── when the token has 18 decimals + ├── it should create the stream + ├── it should bump the next stream id + └── it should emit a CreateStream event diff --git a/test/unit/sablier-v2-cliff/get-cliff-time/getCliffTime.t.sol b/test/unit/sablier-v2-cliff/get-cliff-time/getCliffTime.t.sol index d65897e28..9b70a5c21 100644 --- a/test/unit/sablier-v2-cliff/get-cliff-time/getCliffTime.t.sol +++ b/test/unit/sablier-v2-cliff/get-cliff-time/getCliffTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Cliff__UnitTest__GetCliffTime is SablierV2CliffUnitTest { /// @dev When the stream exists, it should return the correct cliff time. function testGetCliffTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualCliffTime = sablierV2Cliff.getCliffTime(streamId); - uint256 expectedCliffTime = stream.cliffTime; + uint256 expectedCliffTime = daiStream.cliffTime; assertEq(actualCliffTime, expectedCliffTime); } } diff --git a/test/unit/sablier-v2-cliff/get-deposit-amount/getDepositAmount.t.sol b/test/unit/sablier-v2-cliff/get-deposit-amount/getDepositAmount.t.sol index 70bda94be..051b4add9 100644 --- a/test/unit/sablier-v2-cliff/get-deposit-amount/getDepositAmount.t.sol +++ b/test/unit/sablier-v2-cliff/get-deposit-amount/getDepositAmount.t.sol @@ -14,9 +14,9 @@ contract SablierV2Cliff__UnitTest__GetDepositAmount is SablierV2CliffUnitTest { /// @dev When the stream exists, it should the correct deposit amount. function testGetDepositAmount() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualDepositAmount = sablierV2Cliff.getDepositAmount(streamId); - uint256 expectedDepositAmount = stream.depositAmount; + uint256 expectedDepositAmount = daiStream.depositAmount; assertEq(actualDepositAmount, expectedDepositAmount); } } diff --git a/test/unit/sablier-v2-cliff/get-recipient/getRecipient.t.sol b/test/unit/sablier-v2-cliff/get-recipient/getRecipient.t.sol index 18af4c81d..379e83df7 100644 --- a/test/unit/sablier-v2-cliff/get-recipient/getRecipient.t.sol +++ b/test/unit/sablier-v2-cliff/get-recipient/getRecipient.t.sol @@ -14,9 +14,9 @@ contract SablierV2Cliff__UnitTest__GetRecipient is SablierV2CliffUnitTest { /// @dev When the stream exists, it should return the correct recipient. function testGetRecipient() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); address actualRecipient = sablierV2Cliff.getRecipient(streamId); - address expectedRecipient = stream.recipient; + address expectedRecipient = daiStream.recipient; assertEq(actualRecipient, expectedRecipient); } } diff --git a/test/unit/sablier-v2-cliff/get-returnable-amount/getReturnableAmount.sol b/test/unit/sablier-v2-cliff/get-returnable-amount/getReturnableAmount.sol index 8c351a0db..3339b0583 100644 --- a/test/unit/sablier-v2-cliff/get-returnable-amount/getReturnableAmount.sol +++ b/test/unit/sablier-v2-cliff/get-returnable-amount/getReturnableAmount.sol @@ -11,7 +11,7 @@ contract SablierV2Cliff__UnitTest__GetReturnableAmount is SablierV2CliffUnitTest super.setUp(); // Create the default stream, all tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should return zero. @@ -26,36 +26,36 @@ contract SablierV2Cliff__UnitTest__GetReturnableAmount is SablierV2CliffUnitTest /// deposit amount. function testGetReturnableAmount__WithdrawableAmountZero__NoWithdrawals() external { uint256 actualReturnableAmount = sablierV2Cliff.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount; + uint256 expectedReturnableAmount = daiStream.depositAmount; assertEq(actualReturnableAmount, expectedReturnableAmount); } /// @dev When the withdrawable amount is zero and there have been withdrawals, it should return the /// correct returnable amount. function testGetReturnableAmount__WithdrawableAmountZero__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualReturnableAmount = sablierV2Cliff.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedReturnableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualReturnableAmount, expectedReturnableAmount); } /// @dev When the withdrawable amount is not zero and there have been no withdrawals, it should return the /// correct returnable amount. function testGetReturnableAmount__WithdrawableAmountNotZero__NoWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); uint256 actualReturnableAmount = sablierV2Cliff.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedReturnableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualReturnableAmount, expectedReturnableAmount); } /// @dev When the withdrawable amount is not zero and there have been withdrawals, it should return the /// correct returnable amount. function testGetReturnableAmount__WithdrawableAmountNotZero__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET + 1 seconds); - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET + 1 seconds); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualReturnableAmount = sablierV2Cliff.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount - WITHDRAW_AMOUNT - bn(1); + uint256 expectedReturnableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI - bn(1, 18); assertEq(actualReturnableAmount, expectedReturnableAmount); } } diff --git a/test/unit/sablier-v2-cliff/get-sender/getSender.t.sol b/test/unit/sablier-v2-cliff/get-sender/getSender.t.sol index 0f99ccfa8..3c06687e7 100644 --- a/test/unit/sablier-v2-cliff/get-sender/getSender.t.sol +++ b/test/unit/sablier-v2-cliff/get-sender/getSender.t.sol @@ -14,9 +14,9 @@ contract SablierV2Cliff__UnitTest__GetSender is SablierV2CliffUnitTest { /// @dev When the stream exists, it should return the correct sender. function testGetSender() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); address actualSender = sablierV2Cliff.getSender(streamId); - address expectedSender = stream.sender; + address expectedSender = daiStream.sender; assertEq(actualSender, expectedSender); } } diff --git a/test/unit/sablier-v2-cliff/get-start-time/getStartTime.t.sol b/test/unit/sablier-v2-cliff/get-start-time/getStartTime.t.sol index bf32aaebe..39c560488 100644 --- a/test/unit/sablier-v2-cliff/get-start-time/getStartTime.t.sol +++ b/test/unit/sablier-v2-cliff/get-start-time/getStartTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Cliff__UnitTest__StartTime is SablierV2CliffUnitTest { /// @dev When the stream exists, it should return the correct start time. function testGetStartTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualStartTime = sablierV2Cliff.getStartTime(streamId); - uint256 expectedStartTime = stream.startTime; + uint256 expectedStartTime = daiStream.startTime; assertEq(actualStartTime, expectedStartTime); } } diff --git a/test/unit/sablier-v2-cliff/get-stop-time/getStopTime.t.sol b/test/unit/sablier-v2-cliff/get-stop-time/getStopTime.t.sol index 0339d9f42..d9dcfc0a6 100644 --- a/test/unit/sablier-v2-cliff/get-stop-time/getStopTime.t.sol +++ b/test/unit/sablier-v2-cliff/get-stop-time/getStopTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Cliff__UnitTest__StopTime is SablierV2CliffUnitTest { /// @dev When the stream exists, it should return the correct stop time. function testGetStopTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualStopTime = sablierV2Cliff.getStopTime(streamId); - uint256 expectedStopTime = stream.stopTime; + uint256 expectedStopTime = daiStream.stopTime; assertEq(actualStopTime, expectedStopTime); } } diff --git a/test/unit/sablier-v2-cliff/get-stream/getStream.t.sol b/test/unit/sablier-v2-cliff/get-stream/getStream.t.sol index da598f239..0e94e1ae4 100644 --- a/test/unit/sablier-v2-cliff/get-stream/getStream.t.sol +++ b/test/unit/sablier-v2-cliff/get-stream/getStream.t.sol @@ -16,9 +16,9 @@ contract SablierV2Cliff__UnitTest__GetStream is SablierV2CliffUnitTest { /// @dev When the stream exists, it should return the stream struct. function testGetStream() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId); - ISablierV2Cliff.Stream memory expectedStream = stream; + ISablierV2Cliff.Stream memory expectedStream = daiStream; assertEq(actualStream, expectedStream); } } diff --git a/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.t.sol b/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.t.sol index 82af0d95e..6f38fb8f4 100644 --- a/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.t.sol +++ b/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.t.sol @@ -11,7 +11,7 @@ contract SablierV2Cliff__UnitTest__GetWithdrawableAmount is SablierV2CliffUnitTe super.setUp(); // Create the default stream, all tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should return zero. @@ -24,7 +24,7 @@ contract SablierV2Cliff__UnitTest__GetWithdrawableAmount is SablierV2CliffUnitTe /// @dev When the cliff time is greater than the block timestamp, it should return zero. function testGetWithdrawableAmount__CliffTimeGreaterThanBlockTimestamp() external { - vm.warp(stream.cliffTime - 1 seconds); + vm.warp(daiStream.cliffTime - 1 seconds); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 0; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); @@ -32,66 +32,76 @@ contract SablierV2Cliff__UnitTest__GetWithdrawableAmount is SablierV2CliffUnitTe /// @dev When the cliff time is equal to the block timestamp, it should return the correct withdrawable amount. function testGetWithdrawableAmount__CliffTimeEqualToBlockTimestamp() external { - vm.warp(stream.cliffTime); + vm.warp(daiStream.cliffTime); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT - bn(100); + uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT_DAI - bn(100, 18); assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is greater than the stop time and there have been withdrawals, it should /// return the deposit amount minus the withdrawn amount. function testGetWithdrawableAmount__CurrentTimeGreaterThanStopTime__WithWithdrawals() external { - vm.warp(stream.stopTime + 1 seconds); - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.stopTime + 1 seconds); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedWithdrawableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is greater than the stop time and there have been no withdrawals, it should /// return the deposit amount. function testGetWithdrawableAmount__CurrentTimeGreaterThanStopTime__NoWithdrawals() external { - vm.warp(stream.stopTime + 1 seconds); + vm.warp(daiStream.stopTime + 1 seconds); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is equal to the stop time and there have been withdrawals, it should /// return the deposit amount minus the withdrawn amount. function testGetWithdrawableAmount__CurrentTimeEqualToStopTime__WithWithdrawals() external { - vm.warp(stream.stopTime); - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.stopTime); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedWithdrawableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is equal to the stop time and there have been no withdrawals, it should /// return the deposit amount. function testGetWithdrawableAmount__CurrentTimeEqualToStopTime__NoWithdrawals() external { - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is less than the stop time and there have been withdrawals, it should /// return the correct withdrawable amount. function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 0; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When the current time is less than the stop time and there have been no withdrawals, it should - /// return the correct withdrawable amount. - function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__NoWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); + /// @dev When the current time is less than the stop time, there have been no withdrawals and the token + /// has 6 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__NoWithdrawals__6Decimals() external { + streamId = createDefaultUsdcStream(); + vm.warp(usdcStream.startTime + TIME_OFFSET); + uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); + uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT_USDC; + assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); + } + + /// @dev When the current time is less than the stop time, there have been no withdrawals and the token + /// has 18 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__NoWithdrawals__18Decimals() external { + vm.warp(daiStream.startTime + TIME_OFFSET); uint256 actualWithdrawableAmount = sablierV2Cliff.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } } diff --git a/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.tree b/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.tree index 8aba201c6..97cf6a413 100644 --- a/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.tree +++ b/test/unit/sablier-v2-cliff/get-withdrawable-amount/getWithdrawableAmount.tree @@ -21,4 +21,7 @@ getWithdrawableAmount.t.sol ├── when there have been withdrawals │ └── it should return the correct withdrawable amount └── when there haven't been withdrawals - └── it should return the correct withdrawable amount + ├── when the token has 6 decimals + │ └── it should return the correct withdrawable amount + └── when the token has 18 decimals + └── it should return the correct withdrawable amount diff --git a/test/unit/sablier-v2-cliff/get-withdrawn-amount/getWithdrawnAmount.t.sol b/test/unit/sablier-v2-cliff/get-withdrawn-amount/getWithdrawnAmount.t.sol index aa81e220f..c45c88b33 100644 --- a/test/unit/sablier-v2-cliff/get-withdrawn-amount/getWithdrawnAmount.t.sol +++ b/test/unit/sablier-v2-cliff/get-withdrawn-amount/getWithdrawnAmount.t.sol @@ -11,7 +11,7 @@ contract SablierV2Cliff__UnitTest__GetWithdrawnAmount is SablierV2CliffUnitTest super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -34,10 +34,10 @@ contract SablierV2Cliff__UnitTest__GetWithdrawnAmount is SablierV2CliffUnitTest /// @dev When there have been withdrawals, it should return the correct withdrawn amount. function testGetWithdrawnAmount__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualDepositAmount = sablierV2Cliff.getWithdrawnAmount(streamId); - uint256 expectedDepositAmount = WITHDRAW_AMOUNT; + uint256 expectedDepositAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualDepositAmount, expectedDepositAmount); } } diff --git a/test/unit/sablier-v2-cliff/is-cancelable/isCancelable.t.sol b/test/unit/sablier-v2-cliff/is-cancelable/isCancelable.t.sol index 7f1f2ab3e..77b35bd78 100644 --- a/test/unit/sablier-v2-cliff/is-cancelable/isCancelable.t.sol +++ b/test/unit/sablier-v2-cliff/is-cancelable/isCancelable.t.sol @@ -14,7 +14,7 @@ contract SablierV2Cliff__UnitTest__IsCancelable is SablierV2CliffUnitTest { /// @dev When the stream is cancelable, it should return false. function testIsCancelable__CancelableStream() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); bool actualCancelable = sablierV2Cliff.isCancelable(streamId); bool expectedCancelable = true; assertEq(actualCancelable, expectedCancelable); @@ -22,8 +22,8 @@ contract SablierV2Cliff__UnitTest__IsCancelable is SablierV2CliffUnitTest { /// @dev When the stream is not cancelable, it should return true. function testIsCancelable__NonCancelableStream() external { - uint256 nonCancelableStreamId = createNonCancelableStream(); - bool actualCancelable = sablierV2Cliff.isCancelable(nonCancelableStreamId); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); + bool actualCancelable = sablierV2Cliff.isCancelable(nonCancelableDaiStreamId); bool expectedCancelable = false; assertEq(actualCancelable, expectedCancelable); } diff --git a/test/unit/sablier-v2-cliff/renounce/renounce.t.sol b/test/unit/sablier-v2-cliff/renounce/renounce.t.sol index b7e1457aa..cc7c893c5 100644 --- a/test/unit/sablier-v2-cliff/renounce/renounce.t.sol +++ b/test/unit/sablier-v2-cliff/renounce/renounce.t.sol @@ -14,7 +14,7 @@ contract SablierV2Cliff__UnitTest__Renounce is SablierV2CliffUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should revert. @@ -37,13 +37,13 @@ contract SablierV2Cliff__UnitTest__Renounce is SablierV2CliffUnitTest { /// @dev When the stream is already non-cancelable, it should revert. function testCannotRenounce__NonCancelabeStream() external { // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. vm.expectRevert( - abi.encodeWithSelector(ISablierV2.SablierV2__RenounceNonCancelableStream.selector, nonCancelableStreamId) + abi.encodeWithSelector(ISablierV2.SablierV2__RenounceNonCancelableStream.selector, nonCancelableDaiStreamId) ); - sablierV2Cliff.renounce(nonCancelableStreamId); + sablierV2Cliff.renounce(nonCancelableDaiStreamId); } /// @dev When all checks pass, it should make the stream non-cancelable. diff --git a/test/unit/sablier-v2-cliff/withdraw-all-to/withdrawAllTo.t.sol b/test/unit/sablier-v2-cliff/withdraw-all-to/withdrawAllTo.t.sol index ea6e777fa..3c714e547 100644 --- a/test/unit/sablier-v2-cliff/withdraw-all-to/withdrawAllTo.t.sol +++ b/test/unit/sablier-v2-cliff/withdraw-all-to/withdrawAllTo.t.sol @@ -16,12 +16,12 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { super.setUp(); // Define the default amounts, since most tests need them. - defaultAmounts.push(WITHDRAW_AMOUNT); - defaultAmounts.push(WITHDRAW_AMOUNT); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); // Create the default streams, since most tests need them. - defaultStreamIds.push(createDefaultStream()); - defaultStreamIds.push(createDefaultStream()); + defaultStreamIds.push(createDefaultDaiStream()); + defaultStreamIds.push(createDefaultDaiStream()); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -55,7 +55,7 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { function testCannotWithdrawAllTo__OnlyNonExistentStreams() external { uint256 nonStreamId = 1729; uint256[] memory nonStreamIds = createDynamicArray(nonStreamId); - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI); sablierV2Cliff.withdrawAllTo(nonStreamIds, toAlice, amounts); } @@ -66,13 +66,13 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { uint256[] memory streamIds = createDynamicArray(nonStreamId, defaultStreamIds[0]); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.withdrawAllTo(streamIds, toAlice, defaultAmounts); ISablierV2Cliff.Stream memory queriedStream = sablierV2Cliff.getStream(defaultStreamIds[0]); uint256 actualWithdrawnAmount = queriedStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } @@ -107,20 +107,20 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { uint256 reversedStreamId = sablierV2Cliff.create( users.recipient, users.recipient, - stream.sender, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.sender, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); // Make Eve the sender the caller in the rest of this test case. changePrank(users.sender); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. uint256[] memory streamIds = createDynamicArray(reversedStreamId, defaultStreamIds[0]); @@ -135,22 +135,22 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { // Create a stream with Eve as the recipient. changePrank(users.sender); uint256 eveStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, + daiStream.sender, + daiStream.sender, users.eve, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); // Make Eve the `msg.sender` the caller in the rest of this test case. changePrank(users.eve); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. uint256[] memory streamIds = createDynamicArray(eveStreamId, defaultStreamIds[0]); @@ -163,10 +163,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When some amounts are zero, it should revert. function testCannotWithdrawAllTo__SomeAmountsZero() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT, 0); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI, 0); vm.expectRevert(abi.encodeWithSelector(ISablierV2.SablierV2__WithdrawAmountZero.selector, defaultStreamIds[1])); sablierV2Cliff.withdrawAllTo(defaultStreamIds, toAlice, amounts); } @@ -174,10 +174,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When some amounts are greater than the withrawable amounts, it should revert. function testCannotWithdrawAllTo__SomeAmountsGreaterThanWithdrawableAmount() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawableAmount = WITHDRAW_AMOUNT; + uint256 withdrawableAmount = WITHDRAW_AMOUNT_DAI; uint256 withdrawAmountMaxUint256 = MAX_UINT_256; uint256[] memory amounts = createDynamicArray(withdrawableAmount, withdrawAmountMaxUint256); vm.expectRevert( @@ -194,18 +194,18 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When the to address is the recipient, it should make the withdrawals and update the withdrawn amounts. function testWithdrawAllTo__Recipient() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - address toRecipient = stream.recipient; + address toRecipient = daiStream.recipient; sablierV2Cliff.withdrawAllTo(defaultStreamIds, toRecipient, defaultAmounts); ISablierV2Cliff.Stream memory queriedStream0 = sablierV2Cliff.getStream(defaultStreamIds[0]); ISablierV2Cliff.Stream memory queriedStream1 = sablierV2Cliff.getStream(defaultStreamIds[1]); uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -214,10 +214,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When all streams are ended, it should make the withdrawals and delete the streams. function testWithdrawAllTo__ThirdParty__AllStreamsEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256[] memory amounts = createDynamicArray(stream.depositAmount, stream.depositAmount); + uint256[] memory amounts = createDynamicArray(daiStream.depositAmount, daiStream.depositAmount); sablierV2Cliff.withdrawAllTo(defaultStreamIds, toAlice, amounts); ISablierV2Cliff.Stream memory actualStream0 = sablierV2Cliff.getStream(defaultStreamIds[0]); @@ -231,10 +231,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When all streams are ended, it should emit multiple Withdraw events. function testWithdrawAllTo__ThirdParty__AllStreamsEnded__Events() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; vm.expectEmit(true, true, false, true); emit Withdraw(defaultStreamIds[0], toAlice, withdrawAmount); @@ -248,7 +248,7 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When all streams are ongoing, it should make the withdrawals and update the withdrawn amounts. function testWithdrawAllTo__ThirdParty__AllStreamsOngoing() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.withdrawAllTo(defaultStreamIds, toAlice, defaultAmounts); @@ -257,8 +257,8 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -267,10 +267,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When all streams are ongoing, it should emit multiple Withdraw events. function testWithdrawAllTo__ThirdParty__AllStreamsOngoing__Events() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); emit Withdraw(defaultStreamIds[0], toAlice, withdrawAmount); @@ -283,31 +283,31 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { /// @dev When some streams are ended and some streams are ongoing, it should make the withdrawals, delete the /// ended streams and update the withdrawn amounts function testWithdrawAllTo__ThirdParty__SomeStreamsEndedSomeStreamsOngoing() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); uint256[] memory amounts = createDynamicArray(endedWithdrawAmount, ongoingWithdrawAmount); sablierV2Cliff.withdrawAllTo(streamIds, toAlice, amounts); @@ -318,37 +318,37 @@ contract SablierV2Cliff__UnitTest__WithdrawAllTo is SablierV2CliffUnitTest { ISablierV2Cliff.Stream memory queriedStream1 = sablierV2Cliff.getStream(ongoingStreamId); uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); } /// @dev When some streams are ended and some streams are ongoing, it should emit Withdraw events. function testWithdrawAllTo__ThirdParty__SomeStreamsEndedSomeStreamsOngoing__Events() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); emit Withdraw(endedStreamId, toAlice, endedWithdrawAmount); diff --git a/test/unit/sablier-v2-cliff/withdraw-all/withdrawAll.t.sol b/test/unit/sablier-v2-cliff/withdraw-all/withdrawAll.t.sol index 0a9e9b65c..21824ce62 100644 --- a/test/unit/sablier-v2-cliff/withdraw-all/withdrawAll.t.sol +++ b/test/unit/sablier-v2-cliff/withdraw-all/withdrawAll.t.sol @@ -15,12 +15,12 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { super.setUp(); // Define the default amounts, since most tests need them. - defaultAmounts.push(WITHDRAW_AMOUNT); - defaultAmounts.push(WITHDRAW_AMOUNT); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); // Create the default streams, since most tests need them. - defaultStreamIds.push(createDefaultStream()); - defaultStreamIds.push(createDefaultStream()); + defaultStreamIds.push(createDefaultDaiStream()); + defaultStreamIds.push(createDefaultDaiStream()); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -44,7 +44,7 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { function testCannotWithdrawAll__OnlyNonExistentStreams() external { uint256 nonStreamId = 1729; uint256[] memory nonStreamIds = createDynamicArray(nonStreamId); - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI); sablierV2Cliff.withdrawAll(nonStreamIds, amounts); } @@ -55,13 +55,13 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { uint256[] memory streamIds = createDynamicArray(nonStreamId, defaultStreamIds[0]); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.withdrawAll(streamIds, defaultAmounts); ISablierV2Cliff.Stream memory queriedStream = sablierV2Cliff.getStream(defaultStreamIds[0]); uint256 actualWithdrawnAmount = queriedStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } @@ -86,17 +86,17 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { uint256 eveStreamId = sablierV2Cliff.create( users.eve, users.eve, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, - stream.stopTime, - stream.cancelable + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, + daiStream.stopTime, + daiStream.cancelable ); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. uint256[] memory streamIds = createDynamicArray(eveStreamId, defaultStreamIds[0]); @@ -113,7 +113,7 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { changePrank(users.sender); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.withdrawAll(defaultStreamIds, defaultAmounts); @@ -122,8 +122,8 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -132,10 +132,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { /// @dev When some amounts are zero, it should revert. function testCannotWithdrawAll__SomeAmountsZero() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT, 0); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI, 0); vm.expectRevert(abi.encodeWithSelector(ISablierV2.SablierV2__WithdrawAmountZero.selector, defaultStreamIds[1])); sablierV2Cliff.withdrawAll(defaultStreamIds, amounts); } @@ -143,10 +143,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { /// @dev When some amounts are greater than the withrawable amounts, it should revert. function testCannotWithdrawAll__SomeAmountsGreaterThanWithdrawableAmount() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawableAmount = WITHDRAW_AMOUNT; + uint256 withdrawableAmount = WITHDRAW_AMOUNT_DAI; uint256 withdrawAmountMaxUint256 = MAX_UINT_256; uint256[] memory amounts = createDynamicArray(withdrawableAmount, withdrawAmountMaxUint256); vm.expectRevert( @@ -163,10 +163,10 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { /// @dev When all streams are ended, it should make the withdrawals and delete the streams. function testWithdrawAll__AllStreamsEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256[] memory amounts = createDynamicArray(stream.depositAmount, stream.depositAmount); + uint256[] memory amounts = createDynamicArray(daiStream.depositAmount, daiStream.depositAmount); sablierV2Cliff.withdrawAll(defaultStreamIds, amounts); ISablierV2Cliff.Stream memory actualStream0 = sablierV2Cliff.getStream(defaultStreamIds[0]); @@ -180,14 +180,14 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { /// @dev When all streams are ended, it should emit multiple Withdraw events. function testWithdrawAll__AllStreamsEnded__Events() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[0], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[0], daiStream.recipient, withdrawAmount); vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[1], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[1], daiStream.recipient, withdrawAmount); uint256[] memory amounts = createDynamicArray(withdrawAmount, withdrawAmount); sablierV2Cliff.withdrawAll(defaultStreamIds, amounts); } @@ -195,7 +195,7 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { /// @dev When all streams are ongoing, it should make the withdrawals and update the withdrawn amounts. function testWithdrawAll__AllStreamsOngoing() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Cliff.withdrawAll(defaultStreamIds, defaultAmounts); @@ -204,8 +204,8 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -214,45 +214,45 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { /// @dev When all streams are ongoing, it should emit multiple Withdraw events. function testWithdrawAll__AllStreamsOngoing__Events() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[0], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[0], daiStream.recipient, withdrawAmount); vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[1], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[1], daiStream.recipient, withdrawAmount); sablierV2Cliff.withdrawAll(defaultStreamIds, defaultAmounts); } /// @dev When some streams are ended and some streams are ongoing, it should make the withdrawals, delete the /// ended streams and update the withdrawn amounts. function testWithdrawAll__SomeStreamsEndedSomeStreamsOngoing() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); uint256[] memory amounts = createDynamicArray(endedWithdrawAmount, ongoingWithdrawAmount); sablierV2Cliff.withdrawAll(streamIds, amounts); @@ -263,42 +263,42 @@ contract SablierV2Cliff__UnitTest__WithdrawAll is SablierV2CliffUnitTest { ISablierV2Cliff.Stream memory queriedStream1 = sablierV2Cliff.getStream(ongoingStreamId); uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount1 = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); } /// @dev When some streams are ended and some streams are ongoing, it should emit Withdraw events. function testWithdrawAll__SomeStreamsEndedSomeStreamsOngoing__Events() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Cliff.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.cliffTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.cliffTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Withdraw(endedStreamId, stream.recipient, endedWithdrawAmount); + emit Withdraw(endedStreamId, daiStream.recipient, endedWithdrawAmount); vm.expectEmit(true, true, false, true); - emit Withdraw(ongoingStreamId, stream.recipient, ongoingWithdrawAmount); + emit Withdraw(ongoingStreamId, daiStream.recipient, ongoingWithdrawAmount); uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); uint256[] memory amounts = createDynamicArray(endedWithdrawAmount, ongoingWithdrawAmount); diff --git a/test/unit/sablier-v2-cliff/withdraw-to/withdrawTo.t.sol b/test/unit/sablier-v2-cliff/withdraw-to/withdrawTo.t.sol index 096cb2e45..f7440283c 100644 --- a/test/unit/sablier-v2-cliff/withdraw-to/withdrawTo.t.sol +++ b/test/unit/sablier-v2-cliff/withdraw-to/withdrawTo.t.sol @@ -15,7 +15,7 @@ contract SablierV2Cliff__UnitTest__WithdrawTo is SablierV2CliffUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -87,19 +87,19 @@ contract SablierV2Cliff__UnitTest__WithdrawTo is SablierV2CliffUnitTest { /// @dev When the to address is the recipient, it should make the withdrawal. function testWithdrawTo__Recipient() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - sablierV2Cliff.withdrawTo(streamId, toAlice, WITHDRAW_AMOUNT); + sablierV2Cliff.withdrawTo(streamId, toAlice, WITHDRAW_AMOUNT_DAI); } /// @dev When the stream ended, it should make the withdrawal and delete the stream. function testWithdrawTo__ThirdParty__StreamEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; sablierV2Cliff.withdrawTo(streamId, toAlice, withdrawAmount); ISablierV2Cliff.Stream memory deletedStream = sablierV2Cliff.getStream(streamId); ISablierV2Cliff.Stream memory expectedStream; @@ -109,11 +109,11 @@ contract SablierV2Cliff__UnitTest__WithdrawTo is SablierV2CliffUnitTest { /// @dev When the stream ended, it should emit a Withdraw event. function testWithdrawTo__ThirdParty__StreamEnded__Event() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. vm.expectEmit(true, true, false, true); - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; emit Withdraw(streamId, toAlice, withdrawAmount); sablierV2Cliff.withdrawTo(streamId, toAlice, withdrawAmount); } @@ -121,23 +121,23 @@ contract SablierV2Cliff__UnitTest__WithdrawTo is SablierV2CliffUnitTest { /// @dev When the stream is ongoing, it should make the withdrawal and update the withdrawn amount. function testWithdrawTo__ThirdParty__StreamOngoing() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - sablierV2Cliff.withdrawTo(streamId, toAlice, WITHDRAW_AMOUNT); + sablierV2Cliff.withdrawTo(streamId, toAlice, WITHDRAW_AMOUNT_DAI); ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId); uint256 actualWithdrawnAmount = actualStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } /// @dev When the stream is ongoing, it should emit a Withdraw event. function testWithdrawTo__ThirdParty__StreamOngoing__Event() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); emit Withdraw(streamId, toAlice, withdrawAmount); sablierV2Cliff.withdrawTo(streamId, toAlice, withdrawAmount); diff --git a/test/unit/sablier-v2-cliff/withdraw/withdraw.t.sol b/test/unit/sablier-v2-cliff/withdraw/withdraw.t.sol index a61e204bd..21b6076b4 100644 --- a/test/unit/sablier-v2-cliff/withdraw/withdraw.t.sol +++ b/test/unit/sablier-v2-cliff/withdraw/withdraw.t.sol @@ -14,7 +14,7 @@ contract SablierV2Cliff__UnitTest__Withdraw is SablierV2CliffUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -45,8 +45,8 @@ contract SablierV2Cliff__UnitTest__Withdraw is SablierV2CliffUnitTest { changePrank(users.sender); // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); - uint256 withdrawAmount = WITHDRAW_AMOUNT; + vm.warp(daiStream.startTime + TIME_OFFSET); + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; // Run the test. sablierV2Cliff.withdraw(streamId, withdrawAmount); @@ -77,10 +77,10 @@ contract SablierV2Cliff__UnitTest__Withdraw is SablierV2CliffUnitTest { /// @dev When the stream ended, it should cancel and delete the stream. function testWithdraw__StreamEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; sablierV2Cliff.withdraw(streamId, withdrawAmount); ISablierV2Cliff.Stream memory deletedStream = sablierV2Cliff.getStream(streamId); ISablierV2Cliff.Stream memory expectedStream; @@ -90,37 +90,37 @@ contract SablierV2Cliff__UnitTest__Withdraw is SablierV2CliffUnitTest { /// @dev When the stream ended, it should emit a Withdraw event. function testWithdraw__StreamEnded__Event() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. vm.expectEmit(true, true, false, true); - uint256 withdrawAmount = stream.depositAmount; - emit Withdraw(streamId, stream.recipient, withdrawAmount); + uint256 withdrawAmount = daiStream.depositAmount; + emit Withdraw(streamId, daiStream.recipient, withdrawAmount); sablierV2Cliff.withdraw(streamId, withdrawAmount); } /// @dev When the stream is ongoing, it should make the withdrawal and update the withdrawn amount. function testWithdraw__StreamOngoing() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT); + sablierV2Cliff.withdraw(streamId, WITHDRAW_AMOUNT_DAI); ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId); uint256 actualWithdrawnAmount = actualStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } /// @dev When the stream is ongoing, it should emit a Withdraw event. function testWithdraw__StreamOngoing__Event() external { // Warp to 2,600 seconds after the start time (26% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Withdraw(streamId, stream.recipient, withdrawAmount); + emit Withdraw(streamId, daiStream.recipient, withdrawAmount); sablierV2Cliff.withdraw(streamId, withdrawAmount); } } diff --git a/test/unit/sablier-v2-linear/SablierV2LinearUnitTest.t.sol b/test/unit/sablier-v2-linear/SablierV2LinearUnitTest.t.sol index e3eacc98d..20f692802 100644 --- a/test/unit/sablier-v2-linear/SablierV2LinearUnitTest.t.sol +++ b/test/unit/sablier-v2-linear/SablierV2LinearUnitTest.t.sol @@ -29,51 +29,67 @@ abstract contract SablierV2LinearUnitTest is SablierV2UnitTest { /// CONSTANTS /// uint256 internal constant TIME_OFFSET = 100 seconds; - uint256 internal immutable WITHDRAW_AMOUNT = bn(100); + uint256 internal immutable WITHDRAW_AMOUNT_DAI = bn(100, 18); + uint256 internal immutable WITHDRAW_AMOUNT_USDC = bn(100, 6); /// TESTING VARIABLES /// SablierV2Linear internal sablierV2Linear = new SablierV2Linear(); - ISablierV2Linear.Stream internal stream; + ISablierV2Linear.Stream internal daiStream; + ISablierV2Linear.Stream internal usdcStream; // SETUP FUNCTION /// /// @dev A setup function invoked before each test case. function setUp() public virtual { - // Create the default stream to be used across many tests. - stream = ISablierV2Linear.Stream({ + // Create the default streams to be used across the tests. + daiStream = ISablierV2Linear.Stream({ cancelable: true, - depositAmount: DEPOSIT_AMOUNT, + depositAmount: DEPOSIT_AMOUNT_DAI, recipient: users.recipient, sender: users.sender, startTime: START_TIME, stopTime: STOP_TIME, - token: usd, + token: dai, + withdrawnAmount: 0 + }); + usdcStream = ISablierV2Linear.Stream({ + cancelable: true, + depositAmount: DEPOSIT_AMOUNT_USDC, + recipient: users.recipient, + sender: users.sender, + startTime: START_TIME, + stopTime: STOP_TIME, + token: usdc, withdrawnAmount: 0 }); - // Approve the SablierV2Linear contract to spend $USD from the `sender` account. - vm.prank(users.sender); - usd.approve(address(sablierV2Linear), MAX_UINT_256); - - // Approve the SablierV2Linear contract to spend non-standard tokens from the `sender` account. - vm.prank(users.sender); + // Approve the SablierV2Cliff contract to spend tokens from the sender. + vm.startPrank(users.sender); + dai.approve(address(sablierV2Linear), MAX_UINT_256); + usdc.approve(address(sablierV2Linear), MAX_UINT_256); nonStandardToken.approve(address(sablierV2Linear), MAX_UINT_256); - // Approve the SablierV2Linear contract to spend $USD from the `recipient` account. - vm.prank(users.recipient); - usd.approve(address(sablierV2Linear), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from the recipient. + changePrank(users.recipient); + dai.approve(address(sablierV2Linear), MAX_UINT_256); + usdc.approve(address(sablierV2Linear), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Linear), MAX_UINT_256); - // Approve the SablierV2Linear contract to spend $USD from the `funder` account. - vm.prank(users.funder); - usd.approve(address(sablierV2Linear), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from the funder. + changePrank(users.funder); + dai.approve(address(sablierV2Linear), MAX_UINT_256); + usdc.approve(address(sablierV2Linear), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Linear), MAX_UINT_256); - // Approve the SablierV2Linear contract to spend $USD from the `eve` account. - vm.prank(users.eve); - usd.approve(address(sablierV2Linear), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from eve. + changePrank(users.eve); + dai.approve(address(sablierV2Linear), MAX_UINT_256); + usdc.approve(address(sablierV2Linear), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Linear), MAX_UINT_256); // Sets all subsequent calls' `msg.sender` to be `sender`. - vm.startPrank(users.sender); + changePrank(users.sender); } /// NON-CONSTANT FUNCTIONS /// @@ -90,31 +106,45 @@ abstract contract SablierV2LinearUnitTest is SablierV2UnitTest { assertEq(a.withdrawnAmount, b.withdrawnAmount); } - /// @dev Helper function to create a default stream. - function createDefaultStream() internal returns (uint256 streamId) { - streamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + /// @dev Helper function to create a default stream with $DAI used as streaming currency. + function createDefaultDaiStream() internal returns (uint256 daiStreamId) { + daiStreamId = sablierV2Linear.create( + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable + ); + } + + /// @dev Helper function to create a default stream with $USDC used as streaming currency. + function createDefaultUsdcStream() internal returns (uint256 usdcStreamId) { + usdcStreamId = sablierV2Linear.create( + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + usdcStream.stopTime, + usdcStream.cancelable ); } - /// @dev Helper function to create a non-cancelable stream. - function createNonCancelableStream() internal returns (uint256 nonCancelableStreamId) { + /// @dev Helper function to create a non-cancelable daiStream. + function createNonCancelableDaiStream() internal returns (uint256 nonCancelableDaiStreamId) { bool cancelable = false; - nonCancelableStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, + nonCancelableDaiStreamId = sablierV2Linear.create( + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, cancelable ); } diff --git a/test/unit/sablier-v2-linear/cancel-all/cancelAll.t.sol b/test/unit/sablier-v2-linear/cancel-all/cancelAll.t.sol index 2e5aded33..ee9425776 100644 --- a/test/unit/sablier-v2-linear/cancel-all/cancelAll.t.sol +++ b/test/unit/sablier-v2-linear/cancel-all/cancelAll.t.sol @@ -14,8 +14,8 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { super.setUp(); // Create the default streams, since most tests need them. - defaultStreamIds.push(createDefaultStream()); - defaultStreamIds.push(createDefaultStream()); + defaultStreamIds.push(createDefaultDaiStream()); + defaultStreamIds.push(createDefaultDaiStream()); } /// @dev When the stream ids array points only to non existent streams, it should do nothing. @@ -57,12 +57,12 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { uint256 streamIdEve = sablierV2Linear.create( users.eve, users.eve, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); // Run the test. @@ -91,21 +91,21 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { /// @dev When all streams are non-cancelable, it should do nothing. function testCannotCancelAll__AllStreamsNonCancelable() external { - // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + // Create the non-cancelable daiStream. + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. - uint256[] memory nonCancelableStreamIds = createDynamicArray(nonCancelableStreamId); + uint256[] memory nonCancelableStreamIds = createDynamicArray(nonCancelableDaiStreamId); sablierV2Linear.cancelAll(nonCancelableStreamIds); } /// @dev When some streams are non-cancelable, it should cancel and delete the cancelable streams. function testCannotCancelAll__SomeStreamsNonCancelable() external { - // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + // Create the non-cancelable daiStream. + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. - uint256[] memory streamIds = createDynamicArray(defaultStreamIds[0], nonCancelableStreamId); + uint256[] memory streamIds = createDynamicArray(defaultStreamIds[0], nonCancelableDaiStreamId); sablierV2Linear.cancelAll(streamIds); ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(defaultStreamIds[0]); ISablierV2Linear.Stream memory expectedStream; @@ -115,7 +115,7 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { /// @dev When all streams are ended, it should cancel and delete the streams. function testCancelAll__AllStreamsEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. sablierV2Linear.cancelAll(defaultStreamIds); @@ -131,15 +131,15 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { /// @dev When all streams are ended, it should emit multiple Cancel events. function testCancelAll__AllStreamsEnded__Events() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; uint256 returnAmount = 0; vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[0], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[0], daiStream.recipient, withdrawAmount, returnAmount); vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[1], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[1], daiStream.recipient, withdrawAmount, returnAmount); uint256[] memory streamIds = createDynamicArray(defaultStreamIds[0], defaultStreamIds[1]); sablierV2Linear.cancelAll(streamIds); } @@ -147,7 +147,7 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { /// @dev When all streams are ongoing, it should cancel and delete the streams. function testCancelAll__AllStreamsOngoing() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.cancelAll(defaultStreamIds); @@ -163,37 +163,37 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { /// @dev When all streams are ongoing, it should emit multiple Cancel events. function testCancelAll__AllStreamsOngoing__Events() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; - uint256 returnAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; + uint256 returnAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[0], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[0], daiStream.recipient, withdrawAmount, returnAmount); vm.expectEmit(true, true, false, true); - emit Cancel(defaultStreamIds[1], stream.recipient, withdrawAmount, returnAmount); + emit Cancel(defaultStreamIds[1], daiStream.recipient, withdrawAmount, returnAmount); sablierV2Linear.cancelAll(defaultStreamIds); } /// @dev When some of the streams are ended and some are ongoing, it should cancel and delete the streams. function testCancelAll__SomeStreamsEndedSomeStreamsOngoing() external { - // Create the ended stream. - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. @@ -210,35 +210,35 @@ contract SablierV2Linear__UnitTest__CancelAll is SablierV2LinearUnitTest { /// @dev When some of the streams are ended and some are ongoing, it should emit multiple Cancel events. function testCancelAll__SomeStreamsEndedSomeStreamsOngoing__Events() external { - // Create the ended stream. - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; + uint256 endedWithdrawAmount = daiStream.depositAmount; uint256 endedReturnAmount = 0; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; - uint256 ongoingReturnAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; + uint256 ongoingReturnAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Cancel(endedStreamId, stream.recipient, endedWithdrawAmount, endedReturnAmount); + emit Cancel(endedStreamId, daiStream.recipient, endedWithdrawAmount, endedReturnAmount); vm.expectEmit(true, true, false, true); - emit Cancel(ongoingStreamId, stream.recipient, ongoingWithdrawAmount, ongoingReturnAmount); + emit Cancel(ongoingStreamId, daiStream.recipient, ongoingWithdrawAmount, ongoingReturnAmount); uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); sablierV2Linear.cancelAll(streamIds); diff --git a/test/unit/sablier-v2-linear/cancel/cancel.t.sol b/test/unit/sablier-v2-linear/cancel/cancel.t.sol index 63617e904..8e3f4bcf7 100644 --- a/test/unit/sablier-v2-linear/cancel/cancel.t.sol +++ b/test/unit/sablier-v2-linear/cancel/cancel.t.sol @@ -14,7 +14,7 @@ contract SablierV2Linear__UnitTest__Cancel is SablierV2LinearUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should revert. @@ -48,20 +48,20 @@ contract SablierV2Linear__UnitTest__Cancel is SablierV2LinearUnitTest { /// @dev When the stream is non-cancelable, it should revert. function testCannotCancel__StreamNonCancelable() external { - // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + // Create the non-cancelable daiStream. + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. vm.expectRevert( - abi.encodeWithSelector(ISablierV2.SablierV2__StreamNonCancelable.selector, nonCancelableStreamId) + abi.encodeWithSelector(ISablierV2.SablierV2__StreamNonCancelable.selector, nonCancelableDaiStreamId) ); - sablierV2Linear.cancel(nonCancelableStreamId); + sablierV2Linear.cancel(nonCancelableDaiStreamId); } /// @dev When the stream ended, it should cancel and delete the stream. function testCancel__StreamEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. sablierV2Linear.cancel(streamId); @@ -73,20 +73,20 @@ contract SablierV2Linear__UnitTest__Cancel is SablierV2LinearUnitTest { /// @dev When the stream ended, it should emit a Cancel event. function testCancel__StreamEnded__Event() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; uint256 returnAmount = 0; vm.expectEmit(true, true, false, true); - emit Cancel(streamId, stream.recipient, withdrawAmount, returnAmount); + emit Cancel(streamId, daiStream.recipient, withdrawAmount, returnAmount); sablierV2Linear.cancel(streamId); } /// @dev When the stream is ongoing, it should cancel and delete the stream. function testCancel__StreamOngoing() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.cancel(streamId); @@ -98,13 +98,13 @@ contract SablierV2Linear__UnitTest__Cancel is SablierV2LinearUnitTest { /// @dev When the stream is ongoing, it should emit a Cancel event. function testCancel__StreamOngoing__Event() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; - uint256 returnAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; + uint256 returnAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Cancel(streamId, stream.recipient, withdrawAmount, returnAmount); + emit Cancel(streamId, daiStream.recipient, withdrawAmount, returnAmount); sablierV2Linear.cancel(streamId); } } diff --git a/test/unit/sablier-v2-linear/create-with-duration/createWithDuration.t.sol b/test/unit/sablier-v2-linear/create-with-duration/createWithDuration.t.sol index 423ee55e3..78abee78d 100644 --- a/test/unit/sablier-v2-linear/create-with-duration/createWithDuration.t.sol +++ b/test/unit/sablier-v2-linear/create-with-duration/createWithDuration.t.sol @@ -23,13 +23,13 @@ contract SablierV2Linear__UnitTest__CreateWithDuration is SablierV2LinearUnitTes ) ); sablierV2Linear.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, totalDuration, - stream.cancelable + daiStream.cancelable ); } @@ -37,27 +37,27 @@ contract SablierV2Linear__UnitTest__CreateWithDuration is SablierV2LinearUnitTes function testCreateWithDuration(uint256 totalDuration) external { vm.assume(totalDuration <= MAX_UINT_256 - block.timestamp); uint256 streamId = sablierV2Linear.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, totalDuration, - stream.cancelable + daiStream.cancelable ); - ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId); + ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId); uint256 expectedStartTime = block.timestamp; uint256 expectedStopTime; unchecked { expectedStopTime = block.timestamp + totalDuration; } - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(expectedStartTime, createdStream.startTime); - assertEq(expectedStopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(actualStream.sender, daiStream.sender); + assertEq(actualStream.recipient, daiStream.recipient); + assertEq(actualStream.depositAmount, daiStream.depositAmount); + assertEq(actualStream.token, daiStream.token); + assertEq(actualStream.startTime, expectedStartTime); + assertEq(actualStream.stopTime, expectedStopTime); + assertEq(actualStream.cancelable, daiStream.cancelable); + assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount); } } diff --git a/test/unit/sablier-v2-linear/create/create.t.sol b/test/unit/sablier-v2-linear/create/create.t.sol index fa9cad374..075f3ba18 100644 --- a/test/unit/sablier-v2-linear/create/create.t.sol +++ b/test/unit/sablier-v2-linear/create/create.t.sol @@ -15,14 +15,14 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest { vm.expectRevert(ISablierV2.SablierV2__RecipientZeroAddress.selector); address recipient = address(0); sablierV2Linear.create( - stream.sender, - stream.sender, + daiStream.sender, + daiStream.sender, recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); } @@ -31,58 +31,58 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest { vm.expectRevert(ISablierV2.SablierV2__DepositAmountZero.selector); uint256 depositAmount = 0; sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, + daiStream.sender, + daiStream.sender, + daiStream.recipient, depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); } /// @dev When the start time is greater than the stop time, it should revert. function testCannotCreate__StartTimeGreaterThanStopTime() external { - uint256 startTime = stream.stopTime; - uint256 stopTime = stream.startTime; + uint256 startTime = daiStream.stopTime; + uint256 stopTime = daiStream.startTime; vm.expectRevert( abi.encodeWithSelector(ISablierV2.SablierV2__StartTimeGreaterThanStopTime.selector, startTime, stopTime) ); sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, startTime, stopTime, - stream.cancelable + daiStream.cancelable ); } /// @dev When the start time is the equal to the stop time, it should create the stream. function testCreate__StartTimeEqualToStopTime() external { - uint256 stopTime = stream.startTime; + uint256 stopTime = daiStream.startTime; uint256 streamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, stopTime, - stream.cancelable + daiStream.cancelable ); ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(stream.startTime, createdStream.startTime); + assertEq(daiStream.sender, createdStream.sender); + assertEq(daiStream.recipient, createdStream.recipient); + assertEq(daiStream.depositAmount, createdStream.depositAmount); + assertEq(daiStream.token, createdStream.token); + assertEq(daiStream.startTime, createdStream.startTime); assertEq(stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(daiStream.cancelable, createdStream.cancelable); + assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount); } /// @dev When the token is not a contract, it should revert. @@ -90,14 +90,14 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest { vm.expectRevert(abi.encodeWithSelector(SafeERC20__CallToNonContract.selector, address(6174))); IERC20 token = IERC20(address(6174)); sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); } @@ -106,58 +106,93 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest { IERC20 token = IERC20(address(nonStandardToken)); uint256 streamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); + assertEq(daiStream.sender, createdStream.sender); + assertEq(daiStream.recipient, createdStream.recipient); + assertEq(daiStream.depositAmount, createdStream.depositAmount); assertEq(address(nonStandardToken), address(createdStream.token)); - assertEq(stream.startTime, createdStream.startTime); - assertEq(stream.stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(daiStream.startTime, createdStream.startTime); + assertEq(daiStream.stopTime, createdStream.stopTime); + assertEq(daiStream.cancelable, createdStream.cancelable); + assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount); } - /// @dev When all checks pass, it should create the stream. - function testCreate() external { - uint256 streamId = createDefaultStream(); + /// @dev When all checks pass and the token has 6 decimals, it should create the stream. + function testCreate__6Decimals() external { + uint256 streamId = createDefaultUsdcStream(); + ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId); + ISablierV2Linear.Stream memory expectedStream = usdcStream; + assertEq(actualStream, expectedStream); + } + + /// @dev When all checks pass and the token has 6 decimals, it should bump the next stream id. + function testCreate__6Decimals__NextStreamId() external { + uint256 nextStreamId = sablierV2Linear.nextStreamId(); + createDefaultUsdcStream(); + uint256 actualNextStreamId = sablierV2Linear.nextStreamId(); + uint256 expectedNextStreamId = nextStreamId + 1; + assertEq(actualNextStreamId, expectedNextStreamId); + } + + /// @dev When all checks pass and the token has 6 decimals, it should emit a CreateStream event. + function testCreate__6Decimals__Event() external { + uint256 streamId = sablierV2Linear.nextStreamId(); + vm.expectEmit(true, true, true, true); + emit CreateStream( + streamId, + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + usdcStream.stopTime, + usdcStream.cancelable + ); + createDefaultUsdcStream(); + } + + /// @dev When all checks pass and the token has 18 decimals, it should create the stream. + function testCreate__18Decimals() external { + uint256 streamId = createDefaultDaiStream(); ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId); - assertEq(stream, createdStream); + assertEq(daiStream, createdStream); } - /// @dev When all checks pass, it should bump the next stream id. - function testCreate__NextStreamId() external { + /// @dev When all checks pass and the token has 18 decimals, it should bump the next stream id. + function testCreate__18Decimals__NextStreamId() external { uint256 nextStreamId = sablierV2Linear.nextStreamId(); - createDefaultStream(); + createDefaultDaiStream(); uint256 actualNextStreamId = sablierV2Linear.nextStreamId(); uint256 expectedNextStreamId = nextStreamId + 1; assertEq(actualNextStreamId, expectedNextStreamId); } - /// @dev When all checks pass, it should emit a CreateStream event. - function testCreate__Event() external { + /// @dev When all checks pass and the token has 18 decimals, it should emit a CreateStream event. + function testCreate__18Decimals__Event() external { uint256 streamId = sablierV2Linear.nextStreamId(); vm.expectEmit(true, true, true, true); emit CreateStream( streamId, - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); - createDefaultStream(); + createDefaultDaiStream(); } } diff --git a/test/unit/sablier-v2-linear/create/create.tree b/test/unit/sablier-v2-linear/create/create.tree index 143084a0c..15d33955f 100644 --- a/test/unit/sablier-v2-linear/create/create.tree +++ b/test/unit/sablier-v2-linear/create/create.tree @@ -15,6 +15,11 @@ create.t.sol ├── when the token misses the return value │ └── it should create the stream └── when the token is ERC-20 compliant - ├── it should create the stream - ├── it should bump the next stream id - └── it should emit a CreateStream event + ├── when the token has 6 decimals + │ ├── it should create the stream + │ ├── it should bump the next stream id + │ └── it should emit a CreateStream event + └── when the token has 18 decimals + ├── it should create the stream + ├── it should bump the next stream id + └── it should emit a CreateStream event diff --git a/test/unit/sablier-v2-linear/get-deposit-amount/getDepositAmount.t.sol b/test/unit/sablier-v2-linear/get-deposit-amount/getDepositAmount.t.sol index 1271d06a6..57deca13a 100644 --- a/test/unit/sablier-v2-linear/get-deposit-amount/getDepositAmount.t.sol +++ b/test/unit/sablier-v2-linear/get-deposit-amount/getDepositAmount.t.sol @@ -14,9 +14,9 @@ contract SablierV2Linear__UnitTest__GetDepositAmount is SablierV2LinearUnitTest /// @dev When the stream exists, it should return the correct deposit amount. function testGetDepositAmount() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualDepositAmount = sablierV2Linear.getDepositAmount(streamId); - uint256 expectedDepositAmount = stream.depositAmount; + uint256 expectedDepositAmount = daiStream.depositAmount; assertEq(actualDepositAmount, expectedDepositAmount); } } diff --git a/test/unit/sablier-v2-linear/get-recipient/getRecipient.t.sol b/test/unit/sablier-v2-linear/get-recipient/getRecipient.t.sol index 6efc8b629..d8e5ffd41 100644 --- a/test/unit/sablier-v2-linear/get-recipient/getRecipient.t.sol +++ b/test/unit/sablier-v2-linear/get-recipient/getRecipient.t.sol @@ -14,9 +14,9 @@ contract SablierV2Linear__UnitTest__GetRecipient is SablierV2LinearUnitTest { /// @dev When the stream exists, it should return the correct recipient. function testGetRecipient() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); address actualRecipient = sablierV2Linear.getRecipient(streamId); - address expectedRecipient = stream.recipient; + address expectedRecipient = daiStream.recipient; assertEq(actualRecipient, expectedRecipient); } } diff --git a/test/unit/sablier-v2-linear/get-returnable-amount/getReturnableAmount.sol b/test/unit/sablier-v2-linear/get-returnable-amount/getReturnableAmount.sol index ae442fc8c..1ceca0231 100644 --- a/test/unit/sablier-v2-linear/get-returnable-amount/getReturnableAmount.sol +++ b/test/unit/sablier-v2-linear/get-returnable-amount/getReturnableAmount.sol @@ -11,7 +11,7 @@ contract SablierV2Linear__UnitTest__GetReturnableAmount is SablierV2LinearUnitTe super.setUp(); // Create the default stream, all tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should return zero. @@ -26,36 +26,36 @@ contract SablierV2Linear__UnitTest__GetReturnableAmount is SablierV2LinearUnitTe /// deposit amount. function testGetReturnableAmount__WithdrawableAmountZero__NoWithdrawals() external { uint256 actualReturnableAmount = sablierV2Linear.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount; + uint256 expectedReturnableAmount = daiStream.depositAmount; assertEq(actualReturnableAmount, expectedReturnableAmount); } /// @dev When the withdrawable amount is zero and there have been withdrawals, it should return the /// correct returnable amount. function testGetReturnableAmount__WithdrawableAmountZero__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); - sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET); + sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualReturnableAmount = sablierV2Linear.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedReturnableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualReturnableAmount, expectedReturnableAmount); } /// @dev When the withdrawable amount is not zero and there have been no withdrawals, it should return the /// correct returnable amount. function testGetReturnableAmount__WithdrawableAmountNotZero__NoWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); uint256 actualReturnableAmount = sablierV2Linear.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedReturnableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualReturnableAmount, expectedReturnableAmount); } /// @dev When the withdrawable amount is not zero and there have been withdrawals, it should return the /// correct returnable amount. function testGetReturnableAmount__WithdrawableAmountNotZero__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET + 1 seconds); - sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET + 1 seconds); + sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualReturnableAmount = sablierV2Linear.getReturnableAmount(streamId); - uint256 expectedReturnableAmount = stream.depositAmount - WITHDRAW_AMOUNT - bn(1); + uint256 expectedReturnableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI - bn(1, 18); assertEq(actualReturnableAmount, expectedReturnableAmount); } } diff --git a/test/unit/sablier-v2-linear/get-sender/getSender.t.sol b/test/unit/sablier-v2-linear/get-sender/getSender.t.sol index fc68a4a20..75b54f2d7 100644 --- a/test/unit/sablier-v2-linear/get-sender/getSender.t.sol +++ b/test/unit/sablier-v2-linear/get-sender/getSender.t.sol @@ -14,9 +14,9 @@ contract SablierV2Linear__UnitTest__GetSender is SablierV2LinearUnitTest { /// @dev When the stream exists, it should return the correct sender. function testGetSender() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); address actualSender = sablierV2Linear.getSender(streamId); - address expectedSender = stream.sender; + address expectedSender = daiStream.sender; assertEq(actualSender, expectedSender); } } diff --git a/test/unit/sablier-v2-linear/get-start-time/getStartTime.t.sol b/test/unit/sablier-v2-linear/get-start-time/getStartTime.t.sol index 2cd581db0..a75fc2a49 100644 --- a/test/unit/sablier-v2-linear/get-start-time/getStartTime.t.sol +++ b/test/unit/sablier-v2-linear/get-start-time/getStartTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Linear__UnitTest__StartTime is SablierV2LinearUnitTest { /// @dev When the stream exists, it should return the correct start time. function testGetStartTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualStartTime = sablierV2Linear.getStartTime(streamId); - uint256 expectedStartTime = stream.startTime; + uint256 expectedStartTime = daiStream.startTime; assertEq(actualStartTime, expectedStartTime); } } diff --git a/test/unit/sablier-v2-linear/get-stop-time/getStopTime.t.sol b/test/unit/sablier-v2-linear/get-stop-time/getStopTime.t.sol index 2fb4f39f9..d379aab0c 100644 --- a/test/unit/sablier-v2-linear/get-stop-time/getStopTime.t.sol +++ b/test/unit/sablier-v2-linear/get-stop-time/getStopTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Linear__UnitTest__StopTime is SablierV2LinearUnitTest { /// @dev When the stream exists, it should return the correct stop time. function testGetStopTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualStopTime = sablierV2Linear.getStopTime(streamId); - uint256 expectedStopTime = stream.stopTime; + uint256 expectedStopTime = daiStream.stopTime; assertEq(actualStopTime, expectedStopTime); } } diff --git a/test/unit/sablier-v2-linear/get-stream/getStream.t.sol b/test/unit/sablier-v2-linear/get-stream/getStream.t.sol index a3b3a460b..92c6a2971 100644 --- a/test/unit/sablier-v2-linear/get-stream/getStream.t.sol +++ b/test/unit/sablier-v2-linear/get-stream/getStream.t.sol @@ -16,9 +16,9 @@ contract SablierV2Linear__UnitTest__GetStream is SablierV2LinearUnitTest { /// @dev When the stream exists, it should return the stream struct. function testGetStream() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId); - ISablierV2Linear.Stream memory expectedStream = stream; + ISablierV2Linear.Stream memory expectedStream = daiStream; assertEq(actualStream, expectedStream); } } diff --git a/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.t.sol b/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.t.sol index 5fc653edd..8494dc0d1 100644 --- a/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.t.sol +++ b/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.t.sol @@ -11,7 +11,7 @@ contract SablierV2Linear__UnitTest__GetWithdrawableAmount is SablierV2LinearUnit super.setUp(); // Create the default stream, all tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should return zero. @@ -24,7 +24,7 @@ contract SablierV2Linear__UnitTest__GetWithdrawableAmount is SablierV2LinearUnit /// @dev When the start time is greater than the block timestamp, it should return zero. function testGetWithdrawableAmount__StartTimeGreaterThanBlockTimestamp() external { - vm.warp(stream.startTime - 1 seconds); + vm.warp(daiStream.startTime - 1 seconds); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 0; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); @@ -40,57 +40,67 @@ contract SablierV2Linear__UnitTest__GetWithdrawableAmount is SablierV2LinearUnit /// @dev When the current time is greater than the stop time and there have been withdrawals, it should /// return the deposit amount minus the withdrawn amount. function testGetWithdrawableAmount__CurrentTimeGreaterThanStopTime__WithWithdrawals() external { - vm.warp(stream.stopTime + 1 seconds); - sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.stopTime + 1 seconds); + sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedWithdrawableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is greater than the stop time and there have been no withdrawals, it should /// return the deposit amount. function testGetWithdrawableAmount__CurrentTimeGreaterThanStopTime__NoWithdrawals() external { - vm.warp(stream.stopTime + 1 seconds); + vm.warp(daiStream.stopTime + 1 seconds); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is equal to the stop time and there have been withdrawals, it should /// return the deposit amount minus the withdrawn amount. function testGetWithdrawableAmount__CurrentTimeEqualToStopTime__WithWithdrawals() external { - vm.warp(stream.stopTime); - sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.stopTime); + sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount - WITHDRAW_AMOUNT; + uint256 expectedWithdrawableAmount = daiStream.depositAmount - WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is equal to the stop time and there have been no withdrawals, it should /// return the deposit amount. function testGetWithdrawableAmount__CurrentTimeEqualToStopTime__NoWithdrawals() external { - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When the current time is less than the stop time and there have been withdrawals, it should + /// @dev When the current time is less than the stop time there have been withdrawals, it should /// return the correct withdrawable amount. function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); - sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET); + sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 0; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When the current time is less than the stop time and there have been no withdrawals, it should - /// return the correct withdrawable amount. - function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__NoWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); + /// @dev When the current time is less than the stop time, there have been no withdrawals and the token + /// has 6 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__NoWithdrawals__6Decimals() external { + streamId = createDefaultUsdcStream(); + vm.warp(usdcStream.startTime + TIME_OFFSET); + uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); + uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT_USDC; + assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); + } + + /// @dev When the current time is less than the stop time, there have been no withdrawals and the token + /// has 18 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__CurrentTimeLessThanStopTime__NoWithdrawals__18Decimals() external { + vm.warp(daiStream.startTime + TIME_OFFSET); uint256 actualWithdrawableAmount = sablierV2Linear.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawableAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } } diff --git a/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.tree b/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.tree index 669f7e792..3857c885d 100644 --- a/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.tree +++ b/test/unit/sablier-v2-linear/get-withdrawable-amount/getWithdrawableAmount.tree @@ -21,4 +21,7 @@ getWithdrawableAmount.t.sol ├── when there have been withdrawals │ └── it should return the correct withdrawable amount └── when there haven't been withdrawals - └── it should return the correct withdrawable amount + ├── when the token has 6 decimals + │ └── it should return the correct withdrawable amount + └── when the token has 18 decimals + └── it should return the correct withdrawable amount diff --git a/test/unit/sablier-v2-linear/get-withdrawn-amount/getWithdrawnAmount.t.sol b/test/unit/sablier-v2-linear/get-withdrawn-amount/getWithdrawnAmount.t.sol index 63f288f0b..4b136874f 100644 --- a/test/unit/sablier-v2-linear/get-withdrawn-amount/getWithdrawnAmount.t.sol +++ b/test/unit/sablier-v2-linear/get-withdrawn-amount/getWithdrawnAmount.t.sol @@ -11,7 +11,7 @@ contract SablierV2Linear__UnitTest__GetWithdrawnAmount is SablierV2LinearUnitTes super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -34,10 +34,10 @@ contract SablierV2Linear__UnitTest__GetWithdrawnAmount is SablierV2LinearUnitTes /// @dev When there have been withdrawals, it should return the correct withdrawn amount. function testGetWithdrawnAmount__WithWithdrawals() external { - vm.warp(stream.startTime + TIME_OFFSET); - sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT); + vm.warp(daiStream.startTime + TIME_OFFSET); + sablierV2Linear.withdraw(streamId, WITHDRAW_AMOUNT_DAI); uint256 actualDepositAmount = sablierV2Linear.getWithdrawnAmount(streamId); - uint256 expectedDepositAmount = WITHDRAW_AMOUNT; + uint256 expectedDepositAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualDepositAmount, expectedDepositAmount); } } diff --git a/test/unit/sablier-v2-linear/is-cancelable/isCancelable.t.sol b/test/unit/sablier-v2-linear/is-cancelable/isCancelable.t.sol index 773427ddc..8d0ed5095 100644 --- a/test/unit/sablier-v2-linear/is-cancelable/isCancelable.t.sol +++ b/test/unit/sablier-v2-linear/is-cancelable/isCancelable.t.sol @@ -14,7 +14,7 @@ contract SablierV2Linear__UnitTest__IsCancelable is SablierV2LinearUnitTest { /// @dev When the stream is cancelable, it should return false. function testIsCancelable__CancelableStream() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); bool actualCancelable = sablierV2Linear.isCancelable(streamId); bool expectedCancelable = true; assertEq(actualCancelable, expectedCancelable); @@ -22,8 +22,8 @@ contract SablierV2Linear__UnitTest__IsCancelable is SablierV2LinearUnitTest { /// @dev When the stream is not cancelable, it should return true. function testIsCancelable__NonCancelableStream() external { - uint256 nonCancelableStreamId = createNonCancelableStream(); - bool actualCancelable = sablierV2Linear.isCancelable(nonCancelableStreamId); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); + bool actualCancelable = sablierV2Linear.isCancelable(nonCancelableDaiStreamId); bool expectedCancelable = false; assertEq(actualCancelable, expectedCancelable); } diff --git a/test/unit/sablier-v2-linear/renounce/renounce.t.sol b/test/unit/sablier-v2-linear/renounce/renounce.t.sol index 377e89b97..67158b04b 100644 --- a/test/unit/sablier-v2-linear/renounce/renounce.t.sol +++ b/test/unit/sablier-v2-linear/renounce/renounce.t.sol @@ -14,7 +14,7 @@ contract SablierV2Linear__UnitTest__Renounce is SablierV2LinearUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should revert. @@ -36,14 +36,14 @@ contract SablierV2Linear__UnitTest__Renounce is SablierV2LinearUnitTest { /// @dev When the stream is already non-cancelable, it should revert. function testCannotRenounce__NonCancelabeStream() external { - // Create the non-cancelable stream. - uint256 nonCancelableStreamId = createNonCancelableStream(); + // Create the non-cancelable daiStream. + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); // Run the test. vm.expectRevert( - abi.encodeWithSelector(ISablierV2.SablierV2__RenounceNonCancelableStream.selector, nonCancelableStreamId) + abi.encodeWithSelector(ISablierV2.SablierV2__RenounceNonCancelableStream.selector, nonCancelableDaiStreamId) ); - sablierV2Linear.renounce(nonCancelableStreamId); + sablierV2Linear.renounce(nonCancelableDaiStreamId); } /// @dev When all checks pass, it should make the stream non-cancelable. diff --git a/test/unit/sablier-v2-linear/withdraw-all-to/withdrawAllTo.t.sol b/test/unit/sablier-v2-linear/withdraw-all-to/withdrawAllTo.t.sol index 85e2a6d7b..fc2e15a0d 100644 --- a/test/unit/sablier-v2-linear/withdraw-all-to/withdrawAllTo.t.sol +++ b/test/unit/sablier-v2-linear/withdraw-all-to/withdrawAllTo.t.sol @@ -16,12 +16,12 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { super.setUp(); // Define the default amounts, since most tests need them. - defaultAmounts.push(WITHDRAW_AMOUNT); - defaultAmounts.push(WITHDRAW_AMOUNT); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); // Create the default streams, since most tests need them. - defaultStreamIds.push(createDefaultStream()); - defaultStreamIds.push(createDefaultStream()); + defaultStreamIds.push(createDefaultDaiStream()); + defaultStreamIds.push(createDefaultDaiStream()); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -55,7 +55,7 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { function testCannotWithdrawAllTo__OnlyNonExistentStreams() external { uint256 nonStreamId = 1729; uint256[] memory nonStreamIds = createDynamicArray(nonStreamId); - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI); sablierV2Linear.withdrawAllTo(nonStreamIds, toAlice, amounts); } @@ -66,13 +66,13 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { uint256[] memory streamIds = createDynamicArray(nonStreamId, defaultStreamIds[0]); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.withdrawAllTo(streamIds, toAlice, defaultAmounts); ISablierV2Linear.Stream memory queriedStream = sablierV2Linear.getStream(defaultStreamIds[0]); uint256 actualWithdrawnAmount = queriedStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } @@ -107,19 +107,19 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { uint256 reversedStreamId = sablierV2Linear.create( users.recipient, users.recipient, - stream.sender, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.sender, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); // Make Eve the sender the caller in the rest of this test case. changePrank(users.sender); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. uint256[] memory streamIds = createDynamicArray(reversedStreamId, defaultStreamIds[0]); @@ -134,21 +134,21 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { // Create a stream with Eve as the recipient. changePrank(users.sender); uint256 streamIdEve = sablierV2Linear.create( - stream.sender, - stream.sender, + daiStream.sender, + daiStream.sender, users.eve, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); // Make Eve the `msg.sender` the caller in the rest of this test case. changePrank(users.eve); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. uint256[] memory streamIds = createDynamicArray(streamIdEve, defaultStreamIds[0]); @@ -161,10 +161,10 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When some amounts are zero, it should revert. function testCannotWithdrawAllTo__SomeAmountsZero() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT, 0); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI, 0); vm.expectRevert(abi.encodeWithSelector(ISablierV2.SablierV2__WithdrawAmountZero.selector, defaultStreamIds[1])); sablierV2Linear.withdrawAllTo(defaultStreamIds, toAlice, amounts); } @@ -172,10 +172,10 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When some amounts are greater than the withrawable amounts, it should revert. function testCannotWithdrawAllTo__SomeAmountsGreaterThanWithdrawableAmount() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawableAmount = WITHDRAW_AMOUNT; + uint256 withdrawableAmount = WITHDRAW_AMOUNT_DAI; uint256 withdrawAmountMaxUint256 = MAX_UINT_256; uint256[] memory amounts = createDynamicArray(withdrawableAmount, withdrawAmountMaxUint256); vm.expectRevert( @@ -192,18 +192,18 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When the to address is the recipient, it should make the withdrawals and update the withdrawn amounts. function testWithdrawAllTo__Recipient() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - address toRecipient = stream.recipient; + address toRecipient = daiStream.recipient; sablierV2Linear.withdrawAllTo(defaultStreamIds, toRecipient, defaultAmounts); ISablierV2Linear.Stream memory queriedStream0 = sablierV2Linear.getStream(defaultStreamIds[0]); ISablierV2Linear.Stream memory queriedStream1 = sablierV2Linear.getStream(defaultStreamIds[1]); uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = stream.withdrawnAmount + WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = stream.withdrawnAmount + WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -212,10 +212,10 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When all streams are ended, it should make the withdrawals and delete the streams. function testWithdrawAllTo__ThirdParty__AllStreamsEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256[] memory amounts = createDynamicArray(stream.depositAmount, stream.depositAmount); + uint256[] memory amounts = createDynamicArray(daiStream.depositAmount, daiStream.depositAmount); sablierV2Linear.withdrawAllTo(defaultStreamIds, toAlice, amounts); ISablierV2Linear.Stream memory actualStream0 = sablierV2Linear.getStream(defaultStreamIds[0]); @@ -229,10 +229,10 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When all streams are ended, it should emit multiple Withdraw events. function testWithdrawAllTo__ThirdParty__AllStreamsEnded__Events() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; vm.expectEmit(true, true, false, true); emit Withdraw(defaultStreamIds[0], toAlice, withdrawAmount); @@ -246,7 +246,7 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When all streams are ongoing, it should make the withdrawals and update the withdrawn amounts. function testWithdrawAllTo__ThirdParty__AllStreamsOngoing() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.withdrawAllTo(defaultStreamIds, toAlice, defaultAmounts); @@ -255,8 +255,8 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = stream.withdrawnAmount + WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = stream.withdrawnAmount + WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -265,10 +265,10 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When all streams are ongoing, it should emit multiple Withdraw events. function testWithdrawAllTo__ThirdParty__AllStreamsOngoing__Events() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); emit Withdraw(defaultStreamIds[0], toAlice, withdrawAmount); @@ -281,30 +281,30 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { /// @dev When some streams are ended and some streams are ongoing, it should make the withdrawals, delete the /// ended streams and update the withdrawn amounts. function testWithdrawAllTo__ThirdParty__SomeStreamsEndedSomeStreamsOngoing() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); uint256[] memory amounts = createDynamicArray(endedWithdrawAmount, ongoingWithdrawAmount); sablierV2Linear.withdrawAllTo(streamIds, toAlice, amounts); @@ -315,36 +315,36 @@ contract SablierV2Linear__UnitTest__WithdrawAllTo is SablierV2LinearUnitTest { ISablierV2Linear.Stream memory queriedStream1 = sablierV2Linear.getStream(ongoingStreamId); uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount1 = stream.withdrawnAmount + WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount1 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); } /// @dev When some streams are ended and some streams are ongoing, it should emit Withdraw events. function testWithdrawAllTo__ThirdParty__SomeStreamsEndedSomeStreamsOngoing__Events() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); emit Withdraw(endedStreamId, toAlice, endedWithdrawAmount); diff --git a/test/unit/sablier-v2-linear/withdraw-all/withdrawAll.t.sol b/test/unit/sablier-v2-linear/withdraw-all/withdrawAll.t.sol index de8cdb053..42a9d0cca 100644 --- a/test/unit/sablier-v2-linear/withdraw-all/withdrawAll.t.sol +++ b/test/unit/sablier-v2-linear/withdraw-all/withdrawAll.t.sol @@ -15,12 +15,12 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { super.setUp(); // Define the default amounts, since most tests need them. - defaultAmounts.push(WITHDRAW_AMOUNT); - defaultAmounts.push(WITHDRAW_AMOUNT); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); + defaultAmounts.push(WITHDRAW_AMOUNT_DAI); // Create the default streams, since most tests need them. - defaultStreamIds.push(createDefaultStream()); - defaultStreamIds.push(createDefaultStream()); + defaultStreamIds.push(createDefaultDaiStream()); + defaultStreamIds.push(createDefaultDaiStream()); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -44,7 +44,7 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { function testCannotWithdrawAll__OnlyNonExistentStreams() external { uint256 nonStreamId = 1729; uint256[] memory nonStreamIds = createDynamicArray(nonStreamId); - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI); sablierV2Linear.withdrawAll(nonStreamIds, amounts); } @@ -55,13 +55,13 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { uint256[] memory streamIds = createDynamicArray(nonStreamId, defaultStreamIds[0]); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.withdrawAll(streamIds, defaultAmounts); ISablierV2Linear.Stream memory queriedStream = sablierV2Linear.getStream(defaultStreamIds[0]); uint256 actualWithdrawnAmount = queriedStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount = WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } @@ -86,16 +86,16 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { uint256 streamIdEve = sablierV2Linear.create( users.eve, users.eve, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.cancelable + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.cancelable ); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. uint256[] memory streamIds = createDynamicArray(streamIdEve, defaultStreamIds[0]); @@ -112,7 +112,7 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { changePrank(users.sender); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.withdrawAll(defaultStreamIds, defaultAmounts); @@ -121,8 +121,8 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = stream.withdrawnAmount + WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = stream.withdrawnAmount + WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -131,10 +131,10 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { /// @dev When some amounts are zero, it should revert. function testCannotWithdrawAll__SomeAmountsZero() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT, 0); + uint256[] memory amounts = createDynamicArray(WITHDRAW_AMOUNT_DAI, 0); vm.expectRevert(abi.encodeWithSelector(ISablierV2.SablierV2__WithdrawAmountZero.selector, defaultStreamIds[1])); sablierV2Linear.withdrawAll(defaultStreamIds, amounts); } @@ -142,10 +142,10 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { /// @dev When some amounts are greater than the withrawable amounts, it should revert. function testCannotWithdrawAll__SomeAmountsGreaterThanWithdrawableAmount() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawableAmount = WITHDRAW_AMOUNT; + uint256 withdrawableAmount = WITHDRAW_AMOUNT_DAI; uint256 withdrawAmountMaxUint256 = MAX_UINT_256; uint256[] memory amounts = createDynamicArray(withdrawableAmount, withdrawAmountMaxUint256); vm.expectRevert( @@ -162,10 +162,10 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { /// @dev When all streams are ended, it should make the withdrawals and delete the streams. function testWithdrawAll__AllStreamsEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256[] memory amounts = createDynamicArray(stream.depositAmount, stream.depositAmount); + uint256[] memory amounts = createDynamicArray(daiStream.depositAmount, daiStream.depositAmount); sablierV2Linear.withdrawAll(defaultStreamIds, amounts); ISablierV2Linear.Stream memory actualStream0 = sablierV2Linear.getStream(defaultStreamIds[0]); @@ -179,14 +179,14 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { /// @dev When all streams are ended, it should emit multiple Withdraw events. function testWithdrawAll__AllStreamsEnded__Events() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[0], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[0], daiStream.recipient, withdrawAmount); vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[1], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[1], daiStream.recipient, withdrawAmount); uint256[] memory amounts = createDynamicArray(withdrawAmount, withdrawAmount); sablierV2Linear.withdrawAll(defaultStreamIds, amounts); } @@ -194,7 +194,7 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { /// @dev When all streams are ongoing, it should make the withdrawals and update the withdrawn amounts. function testWithdrawAll__AllStreamsOngoing() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. sablierV2Linear.withdrawAll(defaultStreamIds, defaultAmounts); @@ -203,8 +203,8 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { uint256 actualWithdrawnAmount0 = queriedStream0.withdrawnAmount; uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount0 = stream.withdrawnAmount + WITHDRAW_AMOUNT; - uint256 expectedWithdrawnAmount1 = stream.withdrawnAmount + WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount0 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; + uint256 expectedWithdrawnAmount1 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount0, expectedWithdrawnAmount0); assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); @@ -213,44 +213,44 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { /// @dev When all streams are ongoing, it should emit multiple Withdraw events. function testWithdrawAll__AllStreamsOngoing__Events() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[0], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[0], daiStream.recipient, withdrawAmount); vm.expectEmit(true, true, false, true); - emit Withdraw(defaultStreamIds[1], stream.recipient, withdrawAmount); + emit Withdraw(defaultStreamIds[1], daiStream.recipient, withdrawAmount); sablierV2Linear.withdrawAll(defaultStreamIds, defaultAmounts); } /// @dev When some streams are ended and some streams are ongoing, it should make the withdrawals, delete the /// ended streams and update the withdrawn amounts. function testWithdrawAll__SomeStreamsEndedSomeStreamsOngoing() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); uint256[] memory amounts = createDynamicArray(endedWithdrawAmount, ongoingWithdrawAmount); sablierV2Linear.withdrawAll(streamIds, amounts); @@ -261,41 +261,41 @@ contract SablierV2Linear__UnitTest__WithdrawAll is SablierV2LinearUnitTest { ISablierV2Linear.Stream memory queriedStream1 = sablierV2Linear.getStream(ongoingStreamId); uint256 actualWithdrawnAmount1 = queriedStream1.withdrawnAmount; - uint256 expectedWithdrawnAmount1 = stream.withdrawnAmount + WITHDRAW_AMOUNT; + uint256 expectedWithdrawnAmount1 = daiStream.withdrawnAmount + WITHDRAW_AMOUNT_DAI; assertEq(actualWithdrawnAmount1, expectedWithdrawnAmount1); } /// @dev When some streams are ended and some streams are ongoing, it should emit Withdraw events. function testWithdrawAll__SomeStreamsEndedSomeStreamsOngoing__Events() external { - // Create the ended stream. - changePrank(stream.sender); - uint256 earlyStopTime = stream.startTime + TIME_OFFSET; + // Create the ended daiStream. + changePrank(daiStream.sender); + uint256 earlyStopTime = daiStream.startTime + TIME_OFFSET; uint256 endedStreamId = sablierV2Linear.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, earlyStopTime, - stream.cancelable + daiStream.cancelable ); - changePrank(stream.recipient); + changePrank(daiStream.recipient); - // Use the first default stream as the ongoing stream. + // Use the first default stream as the ongoing daiStream. uint256 ongoingStreamId = defaultStreamIds[0]; - // Warp to the end of the early stream. + // Warp to the end of the early daiStream. vm.warp(earlyStopTime); // Run the test. - uint256 endedWithdrawAmount = stream.depositAmount; - uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT; + uint256 endedWithdrawAmount = daiStream.depositAmount; + uint256 ongoingWithdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Withdraw(endedStreamId, stream.recipient, endedWithdrawAmount); + emit Withdraw(endedStreamId, daiStream.recipient, endedWithdrawAmount); vm.expectEmit(true, true, false, true); - emit Withdraw(ongoingStreamId, stream.recipient, ongoingWithdrawAmount); + emit Withdraw(ongoingStreamId, daiStream.recipient, ongoingWithdrawAmount); uint256[] memory streamIds = createDynamicArray(endedStreamId, ongoingStreamId); uint256[] memory amounts = createDynamicArray(endedWithdrawAmount, ongoingWithdrawAmount); diff --git a/test/unit/sablier-v2-linear/withdraw-to/withdrawTo.t.sol b/test/unit/sablier-v2-linear/withdraw-to/withdrawTo.t.sol index 5f3bfc599..2580cd939 100644 --- a/test/unit/sablier-v2-linear/withdraw-to/withdrawTo.t.sol +++ b/test/unit/sablier-v2-linear/withdraw-to/withdrawTo.t.sol @@ -15,7 +15,7 @@ contract SablierV2Linear__UnitTest__WithdrawTo is SablierV2LinearUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -87,20 +87,20 @@ contract SablierV2Linear__UnitTest__WithdrawTo is SablierV2LinearUnitTest { /// @dev When the to address is the recipient, it should make the withdrawal. function testWithdrawTo__Recipient() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - address toRecipient = stream.recipient; - sablierV2Linear.withdrawTo(streamId, toRecipient, WITHDRAW_AMOUNT); + address toRecipient = daiStream.recipient; + sablierV2Linear.withdrawTo(streamId, toRecipient, WITHDRAW_AMOUNT_DAI); } /// @dev When the stream ended, it should make the withdrawal and delete the stream. function testWithdrawTo__ThirdParty__StreamEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; sablierV2Linear.withdrawTo(streamId, toAlice, withdrawAmount); ISablierV2Linear.Stream memory deletedStream = sablierV2Linear.getStream(streamId); ISablierV2Linear.Stream memory expectedStream; @@ -110,11 +110,11 @@ contract SablierV2Linear__UnitTest__WithdrawTo is SablierV2LinearUnitTest { /// @dev When the stream ended, it should emit a Withdraw event. function testWithdrawTo__ThirdParty__StreamEnded__Event() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. vm.expectEmit(true, true, false, true); - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; emit Withdraw(streamId, toAlice, withdrawAmount); sablierV2Linear.withdrawTo(streamId, toAlice, withdrawAmount); } @@ -122,24 +122,24 @@ contract SablierV2Linear__UnitTest__WithdrawTo is SablierV2LinearUnitTest { /// @dev When the stream is ongoing, it should make the withdrawal and update the withdrawn amount. function testWithdrawTo__ThirdParty__StreamOngoing() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawnAmount = WITHDRAW_AMOUNT; + uint256 withdrawnAmount = WITHDRAW_AMOUNT_DAI; sablierV2Linear.withdrawTo(streamId, toAlice, withdrawnAmount); ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId); uint256 actualWithdrawnAmount = actualStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = stream.withdrawnAmount + withdrawnAmount; + uint256 expectedWithdrawnAmount = daiStream.withdrawnAmount + withdrawnAmount; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } /// @dev When the stream is ongoing, it should emit a Withdraw event. function testWithdrawTo__ThirdParty__StreamOngoing__Event() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); emit Withdraw(streamId, toAlice, withdrawAmount); sablierV2Linear.withdrawTo(streamId, toAlice, withdrawAmount); diff --git a/test/unit/sablier-v2-linear/withdraw/withdraw.t.sol b/test/unit/sablier-v2-linear/withdraw/withdraw.t.sol index de750fdbf..c711faf07 100644 --- a/test/unit/sablier-v2-linear/withdraw/withdraw.t.sol +++ b/test/unit/sablier-v2-linear/withdraw/withdraw.t.sol @@ -14,7 +14,7 @@ contract SablierV2Linear__UnitTest__Withdraw is SablierV2LinearUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -45,8 +45,8 @@ contract SablierV2Linear__UnitTest__Withdraw is SablierV2LinearUnitTest { changePrank(users.sender); // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); - uint256 withdrawAmount = WITHDRAW_AMOUNT; + vm.warp(daiStream.startTime + TIME_OFFSET); + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; // Run the test. sablierV2Linear.withdraw(streamId, withdrawAmount); @@ -77,10 +77,10 @@ contract SablierV2Linear__UnitTest__Withdraw is SablierV2LinearUnitTest { /// @dev When the stream ended, it should make the withdrawal and delete the stream. function testWithdraw__StreamEnded() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; sablierV2Linear.withdraw(streamId, withdrawAmount); ISablierV2Linear.Stream memory deletedStream = sablierV2Linear.getStream(streamId); ISablierV2Linear.Stream memory expectedStream; @@ -90,38 +90,38 @@ contract SablierV2Linear__UnitTest__Withdraw is SablierV2LinearUnitTest { /// @dev When the stream ended, it should emit a Withdraw event. function testWithdraw__StreamEnded__Event() external { // Warp to the end of the stream. - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); // Run the test. - uint256 withdrawAmount = stream.depositAmount; + uint256 withdrawAmount = daiStream.depositAmount; vm.expectEmit(true, true, false, true); - emit Withdraw(streamId, stream.recipient, withdrawAmount); + emit Withdraw(streamId, daiStream.recipient, withdrawAmount); sablierV2Linear.withdraw(streamId, withdrawAmount); } /// @dev When the stream is ongoing, it should make the withdrawal and update the withdrawn amount. function testWithdraw__StreamOngoing() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawnAmount = WITHDRAW_AMOUNT; + uint256 withdrawnAmount = WITHDRAW_AMOUNT_DAI; sablierV2Linear.withdraw(streamId, withdrawnAmount); ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId); uint256 actualWithdrawnAmount = actualStream.withdrawnAmount; - uint256 expectedWithdrawnAmount = stream.withdrawnAmount + withdrawnAmount; + uint256 expectedWithdrawnAmount = daiStream.withdrawnAmount + withdrawnAmount; assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); } /// @dev When the stream is ongoing, it should emit a Withdraw event. function testWithdraw__StreamOngoing__Event() external { // Warp to 100 seconds after the start time (1% of the default stream duration). - vm.warp(stream.startTime + TIME_OFFSET); + vm.warp(daiStream.startTime + TIME_OFFSET); // Run the test. - uint256 withdrawAmount = WITHDRAW_AMOUNT; + uint256 withdrawAmount = WITHDRAW_AMOUNT_DAI; vm.expectEmit(true, true, false, true); - emit Withdraw(streamId, stream.recipient, withdrawAmount); + emit Withdraw(streamId, daiStream.recipient, withdrawAmount); sablierV2Linear.withdraw(streamId, withdrawAmount); } } diff --git a/test/unit/sablier-v2-pro/SablierV2ProUnitTest.t.sol b/test/unit/sablier-v2-pro/SablierV2ProUnitTest.t.sol index 75509b10b..2544796cf 100644 --- a/test/unit/sablier-v2-pro/SablierV2ProUnitTest.t.sol +++ b/test/unit/sablier-v2-pro/SablierV2ProUnitTest.t.sol @@ -33,54 +33,77 @@ abstract contract SablierV2ProUnitTest is SablierV2UnitTest { /// CONSTANTS /// uint256 internal constant MAX_SEGMENT_COUNT = 200; - uint256[] internal SEGMENT_AMOUNTS = [bn(2_000), bn(8_000)]; + uint256[] internal SEGMENT_AMOUNTS_DAI = [bn(2_000, 18), bn(8_000, 18)]; + uint256[] internal SEGMENT_AMOUNTS_USDC = [bn(2_000, 6), bn(8_000, 6)]; + uint256[] internal SEGMENT_DELTAS = [2_000 seconds, 8_000 seconds]; SD59x18[] internal SEGMENT_EXPONENTS = [sd59x18(3.14e18), sd59x18(0.5e18)]; uint256[] internal SEGMENT_MILESTONES = [2_100 seconds, 10_100 seconds]; - uint256[] internal SEGMENT_DELTAS = [2_000 seconds, 8_000 seconds]; uint256 internal constant TIME_OFFSET = 2_000 seconds; /// TESTING VARIABLES /// SablierV2Pro internal sablierV2Pro = new SablierV2Pro(MAX_SEGMENT_COUNT); - ISablierV2Pro.Stream internal stream; + ISablierV2Pro.Stream internal daiStream; + ISablierV2Pro.Stream internal usdcStream; // SETUP FUNCTION /// /// @dev A setup function invoked before each test case. function setUp() public virtual { - // Create the default stream to be used across many tests. - stream = ISablierV2Pro.Stream({ + // Create the default streams to be used across the tests. + daiStream = ISablierV2Pro.Stream({ cancelable: true, - depositAmount: DEPOSIT_AMOUNT, + depositAmount: DEPOSIT_AMOUNT_DAI, recipient: users.recipient, - segmentAmounts: SEGMENT_AMOUNTS, + segmentAmounts: SEGMENT_AMOUNTS_DAI, segmentExponents: SEGMENT_EXPONENTS, segmentMilestones: SEGMENT_MILESTONES, sender: users.sender, startTime: START_TIME, stopTime: SEGMENT_MILESTONES[1], - token: usd, + token: dai, + withdrawnAmount: 0 + }); + usdcStream = ISablierV2Pro.Stream({ + cancelable: true, + depositAmount: DEPOSIT_AMOUNT_USDC, + recipient: users.recipient, + segmentAmounts: SEGMENT_AMOUNTS_USDC, + segmentExponents: SEGMENT_EXPONENTS, + segmentMilestones: SEGMENT_MILESTONES, + sender: users.sender, + startTime: START_TIME, + stopTime: SEGMENT_MILESTONES[1], + token: usdc, withdrawnAmount: 0 }); - // Approve the SablierV2Pro contract to spend $USD from the `sender` account. - vm.prank(users.sender); - usd.approve(address(sablierV2Pro), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from the sender. + vm.startPrank(users.sender); + dai.approve(address(sablierV2Pro), MAX_UINT_256); + usdc.approve(address(sablierV2Pro), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Pro), MAX_UINT_256); - // Approve the SablierV2Pro contract to spend non-standard tokens from the `sender` account. - vm.prank(users.sender); + // Approve the SablierV2Cliff contract to spend tokens from the recipient. + changePrank(users.recipient); + dai.approve(address(sablierV2Pro), MAX_UINT_256); + usdc.approve(address(sablierV2Pro), MAX_UINT_256); nonStandardToken.approve(address(sablierV2Pro), MAX_UINT_256); - // Approve the SablierV2Pro contract to spend $USD from the `recipient` account. - vm.prank(users.recipient); - usd.approve(address(sablierV2Pro), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from the funder. + changePrank(users.funder); + dai.approve(address(sablierV2Pro), MAX_UINT_256); + usdc.approve(address(sablierV2Pro), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Pro), MAX_UINT_256); - // Approve the SablierV2Pro contract to spend $USD from the `funder` account. - vm.prank(users.funder); - usd.approve(address(sablierV2Pro), MAX_UINT_256); + // Approve the SablierV2Cliff contract to spend tokens from eve. + changePrank(users.eve); + dai.approve(address(sablierV2Pro), MAX_UINT_256); + usdc.approve(address(sablierV2Pro), MAX_UINT_256); + nonStandardToken.approve(address(sablierV2Pro), MAX_UINT_256); // Sets all subsequent calls' `msg.sender` to be `sender`. - vm.startPrank(users.sender); + changePrank(users.sender); } /// NON-CONSTANT FUNCTIONS /// @@ -123,35 +146,51 @@ abstract contract SablierV2ProUnitTest is SablierV2UnitTest { assertEq(aInt256, bInt256); } - /// @dev Helper function to create a pro stream. - function createDefaultStream() internal returns (uint256 streamId) { - streamId = sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + /// @dev Helper function to create a default stream with $DAI used as streaming currency. + function createDefaultDaiStream() internal returns (uint256 daiStreamId) { + daiStreamId = sablierV2Pro.create( + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable + ); + } + + /// @dev Helper function to create a default stream with $USDC used as streaming currency. + function createDefaultUsdcStream() internal returns (uint256 usdcStreamId) { + usdcStreamId = sablierV2Pro.create( + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + usdcStream.segmentAmounts, + usdcStream.segmentExponents, + usdcStream.segmentMilestones, + usdcStream.cancelable ); } /// @dev Helper function to create a non-cancelable stream. - function createNonCancelableStream() internal returns (uint256 nonCancelableStreamId) { + function createNonCancelableDaiStream() internal returns (uint256 nonCancelableDaiStreamId) { bool cancelable = false; - nonCancelableStreamId = sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, + nonCancelableDaiStreamId = sablierV2Pro.create( + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, cancelable ); } diff --git a/test/unit/sablier-v2-pro/create-with-duration/createWithDuration.t.sol b/test/unit/sablier-v2-pro/create-with-duration/createWithDuration.t.sol index be698dea1..143332113 100644 --- a/test/unit/sablier-v2-pro/create-with-duration/createWithDuration.t.sol +++ b/test/unit/sablier-v2-pro/create-with-duration/createWithDuration.t.sol @@ -22,15 +22,15 @@ contract SablierV2Pro__UnitTest__CreateWithDuration is SablierV2ProUnitTest { } } sablierV2Pro.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.segmentAmounts, - stream.segmentExponents, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.segmentAmounts, + daiStream.segmentExponents, segmentDeltas, - stream.cancelable + daiStream.cancelable ); } @@ -45,20 +45,20 @@ contract SablierV2Pro__UnitTest__CreateWithDuration is SablierV2ProUnitTest { vm.expectRevert( abi.encodeWithSelector( ISablierV2.SablierV2__StartTimeGreaterThanStopTime.selector, - stream.startTime, + daiStream.startTime, stopTime ) ); sablierV2Pro.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.segmentAmounts, - stream.segmentExponents, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.segmentAmounts, + daiStream.segmentExponents, segmentDeltas, - stream.cancelable + daiStream.cancelable ); } @@ -82,15 +82,15 @@ contract SablierV2Pro__UnitTest__CreateWithDuration is SablierV2ProUnitTest { ) ); sablierV2Pro.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.segmentAmounts, - stream.segmentExponents, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.segmentAmounts, + daiStream.segmentExponents, segmentDeltas, - stream.cancelable + daiStream.cancelable ); } @@ -98,7 +98,7 @@ contract SablierV2Pro__UnitTest__CreateWithDuration is SablierV2ProUnitTest { /// it should revert. function testCannotCreateWithDuration__MilestonesCalculationOverflow__SegmentMilestonesNotOrdered() external { uint256 startTime = block.timestamp; - uint256[] memory segmentAmounts = createDynamicArray(0, SEGMENT_AMOUNTS[0], SEGMENT_AMOUNTS[1]); + uint256[] memory segmentAmounts = createDynamicArray(0, SEGMENT_AMOUNTS_DAI[0], SEGMENT_AMOUNTS_DAI[1]); SD59x18[] memory segmentExponents = createDynamicArray(SCALE, SEGMENT_EXPONENTS[0], SEGMENT_EXPONENTS[1]); uint256[] memory segmentDeltas = createDynamicArray(1, MAX_UINT_256, 1); uint256[] memory segmentMilestones = new uint256[](3); @@ -116,32 +116,33 @@ contract SablierV2Pro__UnitTest__CreateWithDuration is SablierV2ProUnitTest { ) ); sablierV2Pro.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, segmentAmounts, segmentExponents, segmentDeltas, - stream.cancelable + daiStream.cancelable ); } /// @dev When all checks pass, it should create the stream with duration. function testCreateWithDuration() external { uint256 streamId = sablierV2Pro.createWithDuration( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.segmentAmounts, - stream.segmentExponents, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.segmentAmounts, + daiStream.segmentExponents, SEGMENT_DELTAS, - stream.cancelable + daiStream.cancelable ); - ISablierV2Pro.Stream memory createdStream = sablierV2Pro.getStream(streamId); - assertEq(stream, createdStream); + ISablierV2Pro.Stream memory actualStream = sablierV2Pro.getStream(streamId); + ISablierV2Pro.Stream memory expectedStream = daiStream; + assertEq(actualStream, expectedStream); } } diff --git a/test/unit/sablier-v2-pro/create/create.t.sol b/test/unit/sablier-v2-pro/create/create.t.sol index 25cad7ed6..3820cdc4e 100644 --- a/test/unit/sablier-v2-pro/create/create.t.sol +++ b/test/unit/sablier-v2-pro/create/create.t.sol @@ -16,16 +16,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { vm.expectRevert(ISablierV2.SablierV2__RecipientZeroAddress.selector); address recipient = address(0); sablierV2Pro.create( - stream.sender, - stream.sender, + daiStream.sender, + daiStream.sender, recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -34,16 +34,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { vm.expectRevert(ISablierV2.SablierV2__DepositAmountZero.selector); uint256 depositAmount = 0; sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, + daiStream.sender, + daiStream.sender, + daiStream.recipient, depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -54,16 +54,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { SD59x18[] memory segmentExponents; uint256[] memory segmentMilestones; sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, segmentAmounts, segmentExponents, segmentMilestones, - stream.cancelable + daiStream.cancelable ); } @@ -81,16 +81,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { } } sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -100,22 +100,22 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { vm.expectRevert( abi.encodeWithSelector( ISablierV2Pro.SablierV2Pro__SegmentCountsNotEqual.selector, - stream.segmentAmounts.length, + daiStream.segmentAmounts.length, segmentExponents.length, - stream.segmentMilestones.length + daiStream.segmentMilestones.length ) ); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -125,78 +125,78 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { vm.expectRevert( abi.encodeWithSelector( ISablierV2Pro.SablierV2Pro__SegmentCountsNotEqual.selector, - stream.segmentAmounts.length, - stream.segmentExponents.length, + daiStream.segmentAmounts.length, + daiStream.segmentExponents.length, segmentMilestones.length ) ); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, segmentMilestones, - stream.cancelable + daiStream.cancelable ); } /// @dev When the start time is greater than the stop time, it should revert. function testCannotCreate__StartTimeGreaterThanFirstMilestone() external { - uint256 startTime = stream.segmentMilestones[0] + 1; + uint256 startTime = daiStream.segmentMilestones[0] + 1; vm.expectRevert( abi.encodeWithSelector( ISablierV2Pro.SablierV2Pro__StartTimeGreaterThanFirstMilestone.selector, startTime, - stream.segmentMilestones[0] + daiStream.segmentMilestones[0] ) ); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } /// @dev When the start time is equal to the stop time, it should create the stream. function testCreate__StartTimeEqualToStopTime() external { - uint256 depositAmount = SEGMENT_AMOUNTS[0]; - uint256[] memory segmentAmounts = createDynamicArray(SEGMENT_AMOUNTS[0]); + uint256 depositAmount = SEGMENT_AMOUNTS_DAI[0]; + uint256[] memory segmentAmounts = createDynamicArray(SEGMENT_AMOUNTS_DAI[0]); SD59x18[] memory segmentExponents = createDynamicArray(SEGMENT_EXPONENTS[0]); - uint256[] memory segmentMilestones = createDynamicArray(stream.stopTime); + uint256[] memory segmentMilestones = createDynamicArray(daiStream.stopTime); uint256 streamId = sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, + daiStream.sender, + daiStream.sender, + daiStream.recipient, depositAmount, - stream.token, - stream.startTime, + daiStream.token, + daiStream.startTime, segmentAmounts, segmentExponents, segmentMilestones, - stream.cancelable + daiStream.cancelable ); ISablierV2Pro.Stream memory createdStream = sablierV2Pro.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); + assertEq(daiStream.sender, createdStream.sender); + assertEq(daiStream.recipient, createdStream.recipient); assertEq(depositAmount, createdStream.depositAmount); - assertEq(stream.token, createdStream.token); - assertEq(stream.startTime, createdStream.startTime); + assertEq(daiStream.token, createdStream.token); + assertEq(daiStream.startTime, createdStream.startTime); assertEq(segmentAmounts, createdStream.segmentAmounts); assertEq(segmentExponents, createdStream.segmentExponents); assertEq(segmentMilestones, createdStream.segmentMilestones); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(daiStream.cancelable, createdStream.cancelable); + assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount); } /// @dev When the segment amounts sum overflows, it should revert. @@ -204,16 +204,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { uint256[] memory segmentAmounts = createDynamicArray(MAX_UINT_256, 1); vm.expectRevert(stdError.arithmeticError); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -229,16 +229,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { ) ); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, segmentMilestones, - stream.cancelable + daiStream.cancelable ); } @@ -250,40 +250,40 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { abi.encodeWithSelector(ISablierV2Pro.SablierV2Pro__SegmentExponentOutOfBounds.selector, outOfBoundsExponent) ); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.segmentMilestones, + daiStream.cancelable ); } /// @dev When a segment exponent is out of bounds, it should revert. function testCannotCreate__DepositAmountNotEqualSegmentAmountsSum() external { - uint256 depositAmount = stream.depositAmount + 1; + uint256 depositAmount = daiStream.depositAmount + 1; vm.expectRevert( abi.encodeWithSelector( ISablierV2Pro.SablierV2Pro__DepositAmountNotEqualToSegmentAmountsSum.selector, depositAmount, - stream.depositAmount + daiStream.depositAmount ) ); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, + daiStream.sender, + daiStream.sender, + daiStream.recipient, depositAmount, - stream.token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.token, + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -292,16 +292,16 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { vm.expectRevert(abi.encodeWithSelector(SafeERC20__CallToNonContract.selector, address(6174))); IERC20 token = IERC20(address(6174)); sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); } @@ -310,63 +310,102 @@ contract SablierV2Pro__UnitTest__Create is SablierV2ProUnitTest { IERC20 token = IERC20(address(nonStandardToken)); uint256 streamId = sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, token, - stream.startTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.startTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); ISablierV2Pro.Stream memory createdStream = sablierV2Pro.getStream(streamId); - assertEq(stream.sender, createdStream.sender); - assertEq(stream.recipient, createdStream.recipient); - assertEq(stream.depositAmount, createdStream.depositAmount); + assertEq(daiStream.sender, createdStream.sender); + assertEq(daiStream.recipient, createdStream.recipient); + assertEq(daiStream.depositAmount, createdStream.depositAmount); assertEq(address(nonStandardToken), address(createdStream.token)); - assertEq(stream.startTime, createdStream.startTime); - assertEq(stream.stopTime, createdStream.stopTime); - assertEq(stream.cancelable, createdStream.cancelable); - assertEq(stream.withdrawnAmount, createdStream.withdrawnAmount); + assertEq(daiStream.startTime, createdStream.startTime); + assertEq(daiStream.stopTime, createdStream.stopTime); + assertEq(daiStream.cancelable, createdStream.cancelable); + assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount); } - /// @dev When all checks pass, it should create the stream. - function testCreate() external { - uint256 streamId = createDefaultStream(); - ISablierV2Pro.Stream memory createdStream = sablierV2Pro.getStream(streamId); - assertEq(stream, createdStream); + /// @dev When all checks pass and the token has 6 decimals, it should create the stream. + function testCreate__6Decimals() external { + uint256 streamId = createDefaultUsdcStream(); + ISablierV2Pro.Stream memory actualStream = sablierV2Pro.getStream(streamId); + ISablierV2Pro.Stream memory expectedStream = usdcStream; + assertEq(actualStream, expectedStream); + } + + /// @dev When all checks pass and the token has 6 decimals, it should bump the next stream id. + function testCreate__6Decimals__NextStreamId() external { + uint256 nextStreamId = sablierV2Pro.nextStreamId(); + createDefaultUsdcStream(); + uint256 actualNextStreamId = sablierV2Pro.nextStreamId(); + uint256 expectedNextStreamId = nextStreamId + 1; + assertEq(actualNextStreamId, expectedNextStreamId); + } + + /// @dev When all checks pass and the token has 6 decimals, it should emit a CreateStream event. + function testCreate__6Decimals__Event() external { + uint256 streamId = sablierV2Pro.nextStreamId(); + vm.expectEmit(true, true, true, true); + emit CreateStream( + streamId, + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + usdcStream.stopTime, + usdcStream.segmentAmounts, + usdcStream.segmentExponents, + usdcStream.segmentMilestones, + usdcStream.cancelable + ); + createDefaultUsdcStream(); + } + + /// @dev When all checks pass and the token has 18 decimals, it should create the stream. + function testCreate__18Decimals() external { + uint256 streamId = createDefaultDaiStream(); + ISablierV2Pro.Stream memory actualStream = sablierV2Pro.getStream(streamId); + ISablierV2Pro.Stream memory expectedStream = daiStream; + assertEq(actualStream, expectedStream); } - /// @dev When all checks pass, it should bump the next stream id. - function testCreate__NextStreamId() external { + /// @dev When all checks pass and the token has 18 decimals, it should bump the next stream id. + function testCreate__18Decimals__NextStreamId() external { uint256 nextStreamId = sablierV2Pro.nextStreamId(); - createDefaultStream(); + createDefaultDaiStream(); uint256 actualNextStreamId = sablierV2Pro.nextStreamId(); uint256 expectedNextStreamId = nextStreamId + 1; assertEq(actualNextStreamId, expectedNextStreamId); } - /// @dev When all checks pass, it should emit a CreateStream event. - function testCreate__Event() external { + /// @dev When all checks pass and the token has 18 decimals, it should emit a CreateStream event. + function testCreate__18Decimals__Event() external { uint256 streamId = sablierV2Pro.nextStreamId(); vm.expectEmit(true, true, true, true); emit CreateStream( streamId, - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, - stream.stopTime, - stream.segmentAmounts, - stream.segmentExponents, - stream.segmentMilestones, - stream.cancelable + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, + daiStream.stopTime, + daiStream.segmentAmounts, + daiStream.segmentExponents, + daiStream.segmentMilestones, + daiStream.cancelable ); - createDefaultStream(); + createDefaultDaiStream(); } } diff --git a/test/unit/sablier-v2-pro/get-deposit-amount/getDepositAmount.t.sol b/test/unit/sablier-v2-pro/get-deposit-amount/getDepositAmount.t.sol index e1e2ae295..fed446e54 100644 --- a/test/unit/sablier-v2-pro/get-deposit-amount/getDepositAmount.t.sol +++ b/test/unit/sablier-v2-pro/get-deposit-amount/getDepositAmount.t.sol @@ -14,9 +14,9 @@ contract SablierV2Pro__UnitTest__GetDepositAmount is SablierV2ProUnitTest { /// @dev When the stream exists, it should the correct deposit amount.. function testGetDepositAmount() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualDepositAmount = sablierV2Pro.getDepositAmount(streamId); - uint256 expectedDepositAmount = stream.depositAmount; + uint256 expectedDepositAmount = daiStream.depositAmount; assertEq(actualDepositAmount, expectedDepositAmount); } } diff --git a/test/unit/sablier-v2-pro/get-recipient/getRecipient.t.sol b/test/unit/sablier-v2-pro/get-recipient/getRecipient.t.sol index 992c43334..e4ef91c43 100644 --- a/test/unit/sablier-v2-pro/get-recipient/getRecipient.t.sol +++ b/test/unit/sablier-v2-pro/get-recipient/getRecipient.t.sol @@ -14,9 +14,9 @@ contract SablierV2Pro__UnitTest__GetRecipient is SablierV2ProUnitTest { /// @dev When the stream exists, it should return the correct recipient. function testGetRecipient() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); address actualRecipient = sablierV2Pro.getRecipient(streamId); - address expectedRecipient = stream.recipient; + address expectedRecipient = daiStream.recipient; assertEq(actualRecipient, expectedRecipient); } } diff --git a/test/unit/sablier-v2-pro/get-sender/getSender.t.sol b/test/unit/sablier-v2-pro/get-sender/getSender.t.sol index fcb8c76e4..595e53c3c 100644 --- a/test/unit/sablier-v2-pro/get-sender/getSender.t.sol +++ b/test/unit/sablier-v2-pro/get-sender/getSender.t.sol @@ -14,9 +14,9 @@ contract SablierV2Pro__UnitTest__GetSender is SablierV2ProUnitTest { /// @dev When the stream exists, it should return the correct sender. function testGetSender() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); address actualSender = sablierV2Pro.getSender(streamId); - address expectedSender = stream.sender; + address expectedSender = daiStream.sender; assertEq(actualSender, expectedSender); } } diff --git a/test/unit/sablier-v2-pro/get-start-time/getStartTime.t.sol b/test/unit/sablier-v2-pro/get-start-time/getStartTime.t.sol index d6662e556..de9fb05c5 100644 --- a/test/unit/sablier-v2-pro/get-start-time/getStartTime.t.sol +++ b/test/unit/sablier-v2-pro/get-start-time/getStartTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Pro__UnitTest__StartTime is SablierV2ProUnitTest { /// @dev When the stream exists, it should return the correct start time. function testGetStartTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualStartTime = sablierV2Pro.getStartTime(streamId); - uint256 expectedStartTime = stream.startTime; + uint256 expectedStartTime = daiStream.startTime; assertEq(actualStartTime, expectedStartTime); } } diff --git a/test/unit/sablier-v2-pro/get-stop-time/getStopTime.t.sol b/test/unit/sablier-v2-pro/get-stop-time/getStopTime.t.sol index d19387030..07b68a7d7 100644 --- a/test/unit/sablier-v2-pro/get-stop-time/getStopTime.t.sol +++ b/test/unit/sablier-v2-pro/get-stop-time/getStopTime.t.sol @@ -14,9 +14,9 @@ contract SablierV2Pro__UnitTest__StopTime is SablierV2ProUnitTest { /// @dev When the stream exists, it should return the correct stop time. function testGetStopTime() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); uint256 actualStopTime = sablierV2Pro.getStopTime(streamId); - uint256 expectedStopTime = stream.stopTime; + uint256 expectedStopTime = daiStream.stopTime; assertEq(actualStopTime, expectedStopTime); } } diff --git a/test/unit/sablier-v2-pro/get-stream/getStream.t.sol b/test/unit/sablier-v2-pro/get-stream/getStream.t.sol index ceb3c1c0a..c13b65c5f 100644 --- a/test/unit/sablier-v2-pro/get-stream/getStream.t.sol +++ b/test/unit/sablier-v2-pro/get-stream/getStream.t.sol @@ -16,9 +16,9 @@ contract SablierV2Pro__UnitTest__GetStream is SablierV2ProUnitTest { /// @dev When the stream exists, it should return the stream struct. function testGetStream() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); ISablierV2Pro.Stream memory actualStream = sablierV2Pro.getStream(streamId); - ISablierV2Pro.Stream memory expectedStream = stream; + ISablierV2Pro.Stream memory expectedStream = daiStream; assertEq(actualStream, expectedStream); } } diff --git a/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.t.sol b/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.t.sol index 6388710db..169a5557d 100644 --- a/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.t.sol +++ b/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.t.sol @@ -14,7 +14,7 @@ contract SablierV2Pro__UnitTest__GetWithdrawableAmount__Basics is SablierV2ProUn super.setUp(); // Create the default stream, all tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } /// @dev When the stream does not exist, it should return zero. @@ -27,7 +27,7 @@ contract SablierV2Pro__UnitTest__GetWithdrawableAmount__Basics is SablierV2ProUn /// @dev When the start time is greater than the block timestamp, it should return zero. function testGetWithdrawableAmount__StartTimeGreaterThanBlockTimestamp() external { - vm.warp(stream.startTime - 1 seconds); + vm.warp(daiStream.startTime - 1 seconds); uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 0; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); @@ -43,45 +43,56 @@ contract SablierV2Pro__UnitTest__GetWithdrawableAmount__Basics is SablierV2ProUn /// @dev When the current time is greater than the stop time and there have been withdrawals, it should /// return the deposit amount minus the withdrawn amount. function testGetWithdrawableAmount__CurrentTimeGreaterThanStopTime__WithWithdrawals() external { - vm.warp(stream.stopTime + 1 seconds); - uint256 withdrawAmount = bn(2_500); + vm.warp(daiStream.stopTime + 1 seconds); + uint256 withdrawAmount = bn(2_500, 18); sablierV2Pro.withdraw(streamId, withdrawAmount); uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount - withdrawAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount - withdrawAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is greater than the stop time and there have been no withdrawals, it should /// return the deposit amount. function testGetWithdrawableAmount__CurrentTimeGreaterThanStopTime__NoWithdrawals() external { - vm.warp(stream.stopTime + 1 seconds); + vm.warp(daiStream.stopTime + 1 seconds); uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is equal to the stop time and there have been withdrawals, it should /// return the deposit amount minus the withdrawn amount. function testGetWithdrawableAmount__CurrentTimeEqualToStopTime__WithWithdrawals() external { - vm.warp(stream.stopTime); - uint256 withdrawAmount = bn(2_500); + vm.warp(daiStream.stopTime); + uint256 withdrawAmount = bn(2_500, 18); sablierV2Pro.withdraw(streamId, withdrawAmount); uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount - withdrawAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount - withdrawAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } /// @dev When the current time is equal to the stop time and there have been no withdrawals, it should /// return the deposit amount. function testGetWithdrawableAmount__CurrentTimeEqualToStopTime__NoWithdrawals() external { - vm.warp(stream.stopTime); + vm.warp(daiStream.stopTime); uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = stream.depositAmount; + uint256 expectedWithdrawableAmount = daiStream.depositAmount; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } + + /// @dev When there have been withdrawals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__WithWithdrawals() external { + vm.warp(daiStream.startTime + 500 seconds); // 500 seconds is 25% of the way in the first segment. + uint256 withdrawAmount = bn(5, 18); + sablierV2Pro.withdraw(streamId, withdrawAmount); + uint256 expectedWithdrawableAmount = 25.73721928961166e18 - withdrawAmount; // 1st term: ~2,000*0.25^{3.14} + uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); + assertEq(expectedWithdrawableAmount, actualWithdrawableAmount); + } } -/// @dev Wrapper contract for the case when the current time is less than the stop time. +/// @dev Wrapper contract for the case when the current time is less than the stop time and when +/// there have been no withdrawals. contract SablierV2Pro__UnitTest__GetWithdrawableAmount__Segments is SablierV2ProUnitTest { uint256 internal streamId; @@ -90,102 +101,184 @@ contract SablierV2Pro__UnitTest__GetWithdrawableAmount__Segments is SablierV2Pro super.setUp(); // Create the default stream, most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); } - /// @dev When there have been withdrawals, it should return the correct withdrawable amount. - function testGetWithdrawableAmount__WithWithdrawals() external { - vm.warp(stream.startTime + 500 seconds); // 500 seconds is 25% of the way in the first segment. - uint256 withdrawAmount = bn(5); - sablierV2Pro.withdraw(streamId, withdrawAmount); - uint256 expectedWithdrawableAmount = 25.73721928961166e18 - withdrawAmount; // 1st term: ~2,000*0.25^{3.14} + /// @dev When there haven't been withdrawals, there is one segment and the token has 6 decimals, it should + /// return the correct withdrawable amount. + function testGetWithdrawableAmount__OneSegment__6Decimals() external { + uint256 daiDepositAmount = SEGMENT_AMOUNTS_USDC[0] + SEGMENT_AMOUNTS_USDC[1]; + uint256[] memory segmentAmounts = createDynamicArray(daiDepositAmount); + SD59x18[] memory segmentExponents = createDynamicArray(SEGMENT_EXPONENTS[1]); + uint256[] memory segmentMilestones = createDynamicArray(SEGMENT_MILESTONES[1]); + + streamId = sablierV2Pro.create( + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + daiDepositAmount, + usdcStream.token, + usdcStream.startTime, + segmentAmounts, + segmentExponents, + segmentMilestones, + usdcStream.cancelable + ); + + vm.warp(usdcStream.startTime + 2_000 seconds); // 2,000 seconds is 20% of the stream duration. uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); - assertEq(expectedWithdrawableAmount, actualWithdrawableAmount); + uint256 expectedWithdrawableAmount = 4472.135955e6; // ~10,000*0.2^{0.5} + assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When there is one segment and there haven't been withdrawals, it should return the correct withdrawable - /// amount. - function testGetWithdrawableAmount__OneSegment() external { - uint256 depositAmount = SEGMENT_AMOUNTS[0] + SEGMENT_AMOUNTS[1]; - uint256[] memory segmentAmounts = createDynamicArray(depositAmount); + /// @dev When there haven't been withdrawals, there is one segment and the token has 18 decimals, it should + /// return the correct withdrawable amount. + function testGetWithdrawableAmount__OneSegment__18Decimals() external { + uint256 usdcDepositAmount = SEGMENT_AMOUNTS_DAI[0] + SEGMENT_AMOUNTS_DAI[1]; + uint256[] memory segmentAmounts = createDynamicArray(usdcDepositAmount); SD59x18[] memory segmentExponents = createDynamicArray(SEGMENT_EXPONENTS[1]); uint256[] memory segmentMilestones = createDynamicArray(SEGMENT_MILESTONES[1]); streamId = sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + usdcDepositAmount, + daiStream.token, + daiStream.startTime, segmentAmounts, segmentExponents, segmentMilestones, - stream.cancelable + daiStream.cancelable ); - vm.warp(stream.startTime + 2_000 seconds); // 2,000 seconds is 20% of the stream duration. + vm.warp(daiStream.startTime + 2_000 seconds); // 2,000 seconds is 20% of the stream duration. uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 4472.13595499957941e18; // ~10,000*0.2^{0.5} assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When there are multiple segments and the current milestone is the 1st in the array, - /// it should return the correct withdrawable amount. - function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__1st() external { - vm.warp(stream.startTime + 500 seconds); // 500 seconds is 25% of the way in the first segment. + /// @dev When there are multiple segments, the current milestone is the 1st in the array and the token + /// has 6 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__1stInArray__6Decimals() external { + uint256 usdcStreamId = createDefaultUsdcStream(); + vm.warp(usdcStream.startTime + 500 seconds); // 500 seconds is 25% of the way in the first segment. + uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(usdcStreamId); + uint256 expectedWithdrawableAmount = 25.737219e6; // ~2,000*0.25^{3.14} + assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); + } + + /// @dev When there are multiple segments, the current milestone is the 2nd in the array and the token + /// has 6 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__2ndInArray__6Decimals() external { + uint256 usdcStreamId = createDefaultUsdcStream(); + vm.warp(usdcStream.startTime + 2_800 seconds); // 2,800 seconds is 10% of the way in the second segment. + uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(usdcStreamId); + // 2nd term: ~8,000*0.1^{0.5} + uint256 expectedWithdrawableAmount = SEGMENT_AMOUNTS_USDC[0] + 2529.822128e6; + assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); + } + + /// @dev When there are multiple segments, the current milestone is the 200th in the array and the token + /// has 6 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__200thInArray__6Decimals() external { + uint256 count = sablierV2Pro.MAX_SEGMENT_COUNT(); + uint256[] memory segmentAmounts = new uint256[](count); + SD59x18[] memory segmentExponents = new SD59x18[](count); + uint256[] memory segmentMilestones = new uint256[](count); + + unchecked { + // Generate 200 segments that each have the same amount, same exponent and are evenly spread apart. + uint256 segmentAmount = usdcStream.depositAmount / count; + SD59x18 segmentExponent = e(); + uint256 totalDuration = usdcStream.stopTime - usdcStream.startTime; + uint256 segmentDuration = totalDuration / count; + for (uint256 i = 0; i < count; ) { + segmentAmounts[i] = segmentAmount; + segmentExponents[i] = segmentExponent; + segmentMilestones[i] = usdcStream.startTime + segmentDuration * (i + 1); + i += 1; + } + + // Create the 200-segment stream. + uint256 usdcStreamId = sablierV2Pro.create( + usdcStream.sender, + usdcStream.sender, + usdcStream.recipient, + usdcStream.depositAmount, + usdcStream.token, + usdcStream.startTime, + segmentAmounts, + segmentExponents, + segmentMilestones, + usdcStream.cancelable + ); + vm.warp(usdcStream.stopTime - segmentDuration / 2); + + uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(usdcStreamId); + // 3rd term: 50*0.5^e + uint256 expectedWithdrawableAmount = segmentAmount * (count - 1) + 7.597761e6; + assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); + } + } + + /// @dev When there are multiple segments, the current milestone is the 1st in the array and the token + /// has 18 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__1stInArray__18Decimals() external { + vm.warp(daiStream.startTime + 500 seconds); // 500 seconds is 25% of the way in the first segment. uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); uint256 expectedWithdrawableAmount = 25.73721928961166e18; // ~2,000*0.25^{3.14} assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When there are multiple segments and the current milestone is the 2nd in the array, - /// it should return the correct withdrawable amount. - function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__2nd() external { - vm.warp(stream.startTime + 2_800 seconds); // 2,800 seconds is 10% of the way in the second segment. + /// @dev When there are multiple segments, the current milestone is the 2nd in the array and the token + /// has 18 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__2ndInArray__18Decimals() external { + vm.warp(daiStream.startTime + 2_800 seconds); // 2,800 seconds is 10% of the way in the second segment. uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); - uint256 expectedWithdrawableAmount = SEGMENT_AMOUNTS[0] + 2529.822128134703472e18; // 2nd term: ~8,000*0.1^{0.5} + // 2nd term: ~8,000*0.1^{0.5} + uint256 expectedWithdrawableAmount = SEGMENT_AMOUNTS_DAI[0] + 2529.822128134703472e18; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } - /// @dev When there are multiple segments and the current milestone is the 200th in the array, - /// it should return the correct withdrawable amount. - function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__200th() external { + /// @dev When there are multiple segments, the current milestone is the 200th in the array and the token + /// has 18 decimals, it should return the correct withdrawable amount. + function testGetWithdrawableAmount__MultipleSegments__CurrentMilestone__200thInArray__18Decimals() external { uint256 count = sablierV2Pro.MAX_SEGMENT_COUNT(); uint256[] memory segmentAmounts = new uint256[](count); SD59x18[] memory segmentExponents = new SD59x18[](count); uint256[] memory segmentMilestones = new uint256[](count); unchecked { - // Generate 200 segments that hold the same amount, same exponent and are evenly spread apart. - uint256 segmentAmount = stream.depositAmount / count; + // Generate 200 segments that each have the same amount, same exponent and are evenly spread apart. + uint256 segmentAmount = daiStream.depositAmount / count; SD59x18 segmentExponent = e(); - uint256 totalDuration = stream.stopTime - stream.startTime; + uint256 totalDuration = daiStream.stopTime - daiStream.startTime; uint256 segmentDuration = totalDuration / count; for (uint256 i = 0; i < count; ) { segmentAmounts[i] = segmentAmount; segmentExponents[i] = segmentExponent; - segmentMilestones[i] = stream.startTime + segmentDuration * (i + 1); + segmentMilestones[i] = daiStream.startTime + segmentDuration * (i + 1); i += 1; } // Create the 200-segment stream. streamId = sablierV2Pro.create( - stream.sender, - stream.sender, - stream.recipient, - stream.depositAmount, - stream.token, - stream.startTime, + daiStream.sender, + daiStream.sender, + daiStream.recipient, + daiStream.depositAmount, + daiStream.token, + daiStream.startTime, segmentAmounts, segmentExponents, segmentMilestones, - stream.cancelable + daiStream.cancelable ); - vm.warp(stream.stopTime - segmentDuration / 2); + vm.warp(daiStream.stopTime - segmentDuration / 2); - // The 3rd term is 50*0.5^e uint256 actualWithdrawableAmount = sablierV2Pro.getWithdrawableAmount(streamId); + // 3rd term: 50*0.5^e uint256 expectedWithdrawableAmount = segmentAmount * (count - 1) + 7.59776116289564825e18; assertEq(actualWithdrawableAmount, expectedWithdrawableAmount); } diff --git a/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.tree b/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.tree index 89e7e75c6..81f097b33 100644 --- a/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.tree +++ b/test/unit/sablier-v2-pro/get-withdrawable-amount/getWithdrawableAmount.tree @@ -22,9 +22,18 @@ getWithdrawableAmount.t.sol │ └── it should return the correct withdrawable amount └── when there haven't withdrawals ├── when there is one segment - │ └── it should return the correct withdrawable amount + │ ├── when the token has 6 decimals + │ │ └── it should return the correct withdrawable amount + │ └── when the token has 18 decimals + │ └── it should return the correct withdrawable amount └── when there are multiple segments ├── when the current milestone is the 1st in the array - │ └── it should return the correct withdrawable amount + │ ├── when the token has 6 decimals + │ │ └── it should return the correct withdrawable amount + │ └── when the token has 18 decimals + │ └── it should return the correct withdrawable amount └── when the current milestone is not the 1st in the array - └── it should return the correct withdrawable amount + ├── when the token has 6 decimals + │ └── it should return the correct withdrawable amount + └── when the token has 18 decimals + └── it should return the correct withdrawable amount diff --git a/test/unit/sablier-v2-pro/get-withdrawn-amount/getWithdrawnAmount.t.sol b/test/unit/sablier-v2-pro/get-withdrawn-amount/getWithdrawnAmount.t.sol index 91b555a9d..38a39c7aa 100644 --- a/test/unit/sablier-v2-pro/get-withdrawn-amount/getWithdrawnAmount.t.sol +++ b/test/unit/sablier-v2-pro/get-withdrawn-amount/getWithdrawnAmount.t.sol @@ -11,7 +11,7 @@ contract SablierV2Pro__UnitTest__GetWithdrawnAmount is SablierV2ProUnitTest { super.setUp(); // Create the default stream, since most tests need it. - streamId = createDefaultStream(); + streamId = createDefaultDaiStream(); // Make the recipient the `msg.sender` in this test suite. changePrank(users.recipient); @@ -34,8 +34,8 @@ contract SablierV2Pro__UnitTest__GetWithdrawnAmount is SablierV2ProUnitTest { /// @dev When there have been withdrawals, it should return the correct withdrawn amount. function testGetWithdrawnAmount__WithWithdrawals() external { - vm.warp(stream.stopTime); - uint256 withdrawAmount = bn(100); + vm.warp(daiStream.stopTime); + uint256 withdrawAmount = bn(100, 18); sablierV2Pro.withdraw(streamId, withdrawAmount); uint256 actualDepositAmount = sablierV2Pro.getWithdrawnAmount(streamId); uint256 expectedDepositAmount = withdrawAmount; diff --git a/test/unit/sablier-v2-pro/is-cancelable/isCancelable.t.sol b/test/unit/sablier-v2-pro/is-cancelable/isCancelable.t.sol index 85b680978..6fc857a23 100644 --- a/test/unit/sablier-v2-pro/is-cancelable/isCancelable.t.sol +++ b/test/unit/sablier-v2-pro/is-cancelable/isCancelable.t.sol @@ -14,7 +14,7 @@ contract SablierV2Pro__UnitTest__IsCancelable is SablierV2ProUnitTest { /// @dev When the stream is cancelable, it should return false. function testIsCancelable__CancelableStream() external { - uint256 streamId = createDefaultStream(); + uint256 streamId = createDefaultDaiStream(); bool actualCancelable = sablierV2Pro.isCancelable(streamId); bool expectedCancelable = true; assertEq(actualCancelable, expectedCancelable); @@ -22,8 +22,8 @@ contract SablierV2Pro__UnitTest__IsCancelable is SablierV2ProUnitTest { /// @dev When the stream is not cancelable, it should return true. function testIsCancelable__NonCancelableStream() external { - uint256 nonCancelableStreamId = createNonCancelableStream(); - bool actualCancelable = sablierV2Pro.isCancelable(nonCancelableStreamId); + uint256 nonCancelableDaiStreamId = createNonCancelableDaiStream(); + bool actualCancelable = sablierV2Pro.isCancelable(nonCancelableDaiStreamId); bool expectedCancelable = false; assertEq(actualCancelable, expectedCancelable); }