From 807c23968fa233e6172b4d82b4124811c553a1b3 Mon Sep 17 00:00:00 2001 From: smol-ninja Date: Sat, 27 Apr 2024 12:49:08 +0100 Subject: [PATCH 1/6] perf: optimize modifiers --- src/SablierV2OpenEnded.sol | 52 ++++++++++++++++++++--- src/abstracts/SablierV2OpenEndedState.sol | 14 +----- src/interfaces/ISablierV2OpenEnded.sol | 16 ++++--- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/SablierV2OpenEnded.sol b/src/SablierV2OpenEnded.sol index 81afd8dd..30442173 100644 --- a/src/SablierV2OpenEnded.sol +++ b/src/SablierV2OpenEnded.sol @@ -28,6 +28,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope view override notCanceled(streamId) + notNull(streamId) returns (uint128 refundableAmount) { refundableAmount = _refundableAmountOf(streamId, uint40(block.timestamp)); @@ -42,13 +43,20 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope view override notCanceled(streamId) + notNull(streamId) returns (uint128 refundableAmount) { refundableAmount = _refundableAmountOf(streamId, time); } /// @inheritdoc ISablierV2OpenEnded - function streamDebt(uint256 streamId) external view notCanceled(streamId) returns (uint128 debt) { + function streamDebt(uint256 streamId) + external + view + notCanceled(streamId) + notNull(streamId) + returns (uint128 debt) + { uint128 balance = _streams[streamId].balance; uint128 streamedAmount = _streamedAmountOf(streamId, uint40(block.timestamp)); @@ -60,7 +68,13 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function streamedAmountOf(uint256 streamId) external view notCanceled(streamId) returns (uint128 streamedAmount) { + function streamedAmountOf(uint256 streamId) + external + view + notCanceled(streamId) + notNull(streamId) + returns (uint128 streamedAmount) + { streamedAmount = _streamedAmountOf(streamId, uint40(block.timestamp)); } @@ -72,6 +86,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope external view notCanceled(streamId) + notNull(streamId) returns (uint128 streamedAmount) { streamedAmount = _streamedAmountOf(streamId, time); @@ -82,6 +97,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope external view notCanceled(streamId) + notNull(streamId) returns (uint128 withdrawableAmount) { withdrawableAmount = _withdrawableAmountOf(streamId, uint40(block.timestamp)); @@ -95,6 +111,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope external view notCanceled(streamId) + notNull(streamId) returns (uint128 withdrawableAmount) { withdrawableAmount = _withdrawableAmountOf(streamId, time); @@ -112,6 +129,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope external noDelegateCall notCanceled(streamId) + notNull(streamId) onlySender(streamId) { // Effects and Interactions: adjust the stream. @@ -119,7 +137,13 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function cancel(uint256 streamId) public noDelegateCall notCanceled(streamId) onlySender(streamId) { + function cancel(uint256 streamId) + public + noDelegateCall + notCanceled(streamId) + notNull(streamId) + onlySender(streamId) + { _cancel(streamId); } @@ -211,7 +235,15 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function deposit(uint256 streamId, uint128 depositAmount) external noDelegateCall notCanceled(streamId) { + function deposit( + uint256 streamId, + uint128 depositAmount + ) + external + noDelegateCall + notCanceled(streamId) + notNull(streamId) + { // Checks, Effects and Interactions: deposit on stream. _deposit(streamId, depositAmount); } @@ -260,6 +292,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope external noDelegateCall notCanceled(streamId) + notNull(streamId) onlySender(streamId) { // Checks, Effects and Interactions: make the refund. @@ -632,7 +665,16 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @dev See the documentation for the user-facing functions that call this internal function. - function _withdraw(uint256 streamId, address to, uint40 time) internal noDelegateCall notCanceled(streamId) { + function _withdraw( + uint256 streamId, + address to, + uint40 time + ) + internal + noDelegateCall + notCanceled(streamId) + notNull(streamId) + { // Check: the withdrawal address is not zero. if (to == address(0)) { revert Errors.SablierV2OpenEnded_WithdrawToZeroAddress(); diff --git a/src/abstracts/SablierV2OpenEndedState.sol b/src/abstracts/SablierV2OpenEndedState.sol index d1b0e0b2..00ec1bc7 100644 --- a/src/abstracts/SablierV2OpenEndedState.sol +++ b/src/abstracts/SablierV2OpenEndedState.sol @@ -34,7 +34,7 @@ abstract contract SablierV2OpenEndedState is ISablierV2OpenEndedState { /// @dev Checks that `streamId` does not reference a canceled stream. modifier notCanceled(uint256 streamId) { - if (isCanceled(streamId)) { + if (_streams[streamId].isCanceled) { revert Errors.SablierV2OpenEnded_StreamCanceled(streamId); } _; @@ -50,7 +50,7 @@ abstract contract SablierV2OpenEndedState is ISablierV2OpenEndedState { /// @dev Checks the `msg.sender` is the stream's sender. modifier onlySender(uint256 streamId) { - if (!_isCallerStreamSender(streamId)) { + if (msg.sender != _streams[streamId].sender) { revert Errors.SablierV2OpenEnded_Unauthorized(streamId, msg.sender); } _; @@ -127,14 +127,4 @@ abstract contract SablierV2OpenEndedState is ISablierV2OpenEndedState { function isStream(uint256 streamId) public view returns (bool result) { result = _streams[streamId].isStream; } - - /*////////////////////////////////////////////////////////////////////////// - INTERNAL CONSTANT FUNCTIONS - //////////////////////////////////////////////////////////////////////////*/ - - /// @notice Checks whether `msg.sender` is the stream's sender. - /// @param streamId The stream ID for the query. - function _isCallerStreamSender(uint256 streamId) internal view returns (bool) { - return msg.sender == _streams[streamId].sender; - } } diff --git a/src/interfaces/ISablierV2OpenEnded.sol b/src/interfaces/ISablierV2OpenEnded.sol index 84538ad1..f90fbf0d 100644 --- a/src/interfaces/ISablierV2OpenEnded.sol +++ b/src/interfaces/ISablierV2OpenEnded.sol @@ -99,42 +99,44 @@ interface ISablierV2OpenEnded is ISablierV2OpenEndedState { //////////////////////////////////////////////////////////////////////////*/ /// @notice Calculates the amount that the sender can refund from stream, denoted in 18 decimals. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. + /// @return refundableAmount The amount that the sender can refund. function refundableAmountOf(uint256 streamId) external view returns (uint128 refundableAmount); /// @notice Calculates the amount that the sender can refund from stream at `time`, denoted in 18 decimals. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. /// @param time The Unix timestamp for the streamed amount calculation. + /// @return refundableAmount The amount that the sender can refund. function refundableAmountOf(uint256 streamId, uint40 time) external view returns (uint128 refundableAmount); /// @notice Calculates the amount that the sender owes on the stream, i.e. if more assets have been streamed than /// its balance, denoted in 18 decimals. If there is no debt, it will return zero. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. function streamDebt(uint256 streamId) external view returns (uint128 debt); /// @notice Calculates the amount streamed to the recipient from the last time update to the current time, /// denoted in 18 decimals. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount); /// @notice Calculates the amount streamed to the recipient from the last time update to `time` passed as parameter, /// denoted in 18 decimals. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. /// @param time The Unix timestamp for the streamed amount calculation. function streamedAmountOf(uint256 streamId, uint40 time) external view returns (uint128 streamedAmount); /// @notice Calculates the amount that the recipient can withdraw from the stream, denoted in 18 decimals. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. function withdrawableAmountOf(uint256 streamId) external view returns (uint128 withdrawableAmount); /// @notice Calculates the amount that the recipient can withdraw from the stream at `time`, denoted in 18 decimals. - /// @dev Reverts if `streamId` references a canceled stream. + /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. /// @param time The Unix timestamp for the streamed amount calculation. function withdrawableAmountOf(uint256 streamId, uint40 time) external view returns (uint128 withdrawableAmount); From 95758be956a03bda92ea41b0553b4647fcf7cc3c Mon Sep 17 00:00:00 2001 From: smol-ninja Date: Sat, 27 Apr 2024 13:00:41 +0100 Subject: [PATCH 2/6] refactor: rename streamDebt to streamDebtOf --- src/SablierV2OpenEnded.sol | 8 ++++---- src/interfaces/ISablierV2OpenEnded.sol | 2 +- test/integration/stream-debt/streamDebt.t.sol | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/SablierV2OpenEnded.sol b/src/SablierV2OpenEnded.sol index 30442173..abcd3df1 100644 --- a/src/SablierV2OpenEnded.sol +++ b/src/SablierV2OpenEnded.sol @@ -50,7 +50,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function streamDebt(uint256 streamId) + function streamDebtOf(uint256 streamId) external view notCanceled(streamId) @@ -60,11 +60,11 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128 balance = _streams[streamId].balance; uint128 streamedAmount = _streamedAmountOf(streamId, uint40(block.timestamp)); - if (balance >= streamedAmount) { - return 0; + if (balance < streamedAmount) { + return streamedAmount - balance; } - debt = streamedAmount - balance; + return 0; } /// @inheritdoc ISablierV2OpenEnded diff --git a/src/interfaces/ISablierV2OpenEnded.sol b/src/interfaces/ISablierV2OpenEnded.sol index f90fbf0d..1035c4bd 100644 --- a/src/interfaces/ISablierV2OpenEnded.sol +++ b/src/interfaces/ISablierV2OpenEnded.sol @@ -115,7 +115,7 @@ interface ISablierV2OpenEnded is ISablierV2OpenEndedState { /// its balance, denoted in 18 decimals. If there is no debt, it will return zero. /// @dev Reverts if `streamId` references a canceled or a null stream. /// @param streamId The stream ID for the query. - function streamDebt(uint256 streamId) external view returns (uint128 debt); + function streamDebtOf(uint256 streamId) external view returns (uint128 debt); /// @notice Calculates the amount streamed to the recipient from the last time update to the current time, /// denoted in 18 decimals. diff --git a/test/integration/stream-debt/streamDebt.t.sol b/test/integration/stream-debt/streamDebt.t.sol index d4a28a7b..cc329f62 100644 --- a/test/integration/stream-debt/streamDebt.t.sol +++ b/test/integration/stream-debt/streamDebt.t.sol @@ -10,23 +10,23 @@ contract StreamDebt_Integration_Test is Integration_Test { function test_RevertGiven_Null() external { expectRevertNull(); - openEnded.streamDebt(nullStreamId); + openEnded.streamDebtOf(nullStreamId); } function test_RevertGiven_Canceled() external givenNotNull { expectRevertCanceled(); - openEnded.streamDebt(defaultStreamId); + openEnded.streamDebtOf(defaultStreamId); } function test_StreamDebt_BalanceGreaterThanOrEqualStreamedAmount() external givenNotNull givenNotCanceled { defaultDeposit(); - uint128 streamDebt = openEnded.streamDebt(defaultStreamId); + uint128 streamDebt = openEnded.streamDebtOf(defaultStreamId); assertEq(streamDebt, 0, "stream debt"); } - function test_StreamDebt() external givenNotNull givenNotCanceled { + function test_streamDebtOf() external givenNotNull givenNotCanceled { vm.warp({ newTimestamp: WARP_ONE_MONTH }); - uint128 streamDebt = openEnded.streamDebt(defaultStreamId); + uint128 streamDebt = openEnded.streamDebtOf(defaultStreamId); assertEq(streamDebt, ONE_MONTH_STREAMED_AMOUNT, "stream debt"); } } From 57ab589151ff4930480f80459e673a2e1b521d78 Mon Sep 17 00:00:00 2001 From: smol-ninja Date: Sat, 27 Apr 2024 13:55:43 +0100 Subject: [PATCH 3/6] fix: add override --- src/SablierV2OpenEnded.sol | 30 +++++++++++++++++++---- src/abstracts/SablierV2OpenEndedState.sol | 12 ++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/SablierV2OpenEnded.sol b/src/SablierV2OpenEnded.sol index abcd3df1..ad784789 100644 --- a/src/SablierV2OpenEnded.sol +++ b/src/SablierV2OpenEnded.sol @@ -53,6 +53,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope function streamDebtOf(uint256 streamId) external view + override notCanceled(streamId) notNull(streamId) returns (uint128 debt) @@ -71,6 +72,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope function streamedAmountOf(uint256 streamId) external view + override notCanceled(streamId) notNull(streamId) returns (uint128 streamedAmount) @@ -85,6 +87,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope ) external view + override notCanceled(streamId) notNull(streamId) returns (uint128 streamedAmount) @@ -96,6 +99,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope function withdrawableAmountOf(uint256 streamId) external view + override notCanceled(streamId) notNull(streamId) returns (uint128 withdrawableAmount) @@ -110,6 +114,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope ) external view + override notCanceled(streamId) notNull(streamId) returns (uint128 withdrawableAmount) @@ -127,6 +132,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128 newRatePerSecond ) external + override noDelegateCall notCanceled(streamId) notNull(streamId) @@ -139,6 +145,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope /// @inheritdoc ISablierV2OpenEnded function cancel(uint256 streamId) public + override noDelegateCall notCanceled(streamId) notNull(streamId) @@ -165,6 +172,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope IERC20 asset ) external + override returns (uint256 streamId) { // Checks, Effects and Interactions: create the stream. @@ -180,6 +188,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128 depositAmount ) external + override returns (uint256 streamId) { // Checks, Effects and Interactions: create the stream. @@ -197,6 +206,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope IERC20 asset ) public + override returns (uint256[] memory streamIds) { uint256 recipientsCount = recipients.length; @@ -226,6 +236,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128[] calldata depositAmounts ) external + override returns (uint256[] memory streamIds) { streamIds = new uint256[](recipients.length); @@ -240,6 +251,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128 depositAmount ) external + override noDelegateCall notCanceled(streamId) notNull(streamId) @@ -249,7 +261,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function depositMultiple(uint256[] memory streamIds, uint128[] calldata amounts) public noDelegateCall { + function depositMultiple(uint256[] memory streamIds, uint128[] calldata amounts) public override noDelegateCall { uint256 streamIdsCount = streamIds.length; uint256 depositAmountsCount = amounts.length; @@ -270,13 +282,20 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function restartStream(uint256 streamId, uint128 ratePerSecond) external { + function restartStream(uint256 streamId, uint128 ratePerSecond) external override { // Checks, Effects and Interactions: restart the stream. _restartStream(streamId, ratePerSecond); } /// @inheritdoc ISablierV2OpenEnded - function restartStreamAndDeposit(uint256 streamId, uint128 ratePerSecond, uint128 depositAmount) external { + function restartStreamAndDeposit( + uint256 streamId, + uint128 ratePerSecond, + uint128 depositAmount + ) + external + override + { // Checks, Effects and Interactions: restart the stream. _restartStream(streamId, ratePerSecond); @@ -290,6 +309,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128 refundAmount ) external + override noDelegateCall notCanceled(streamId) notNull(streamId) @@ -300,7 +320,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function withdraw(uint256 streamId, address to, uint40 time) external { + function withdraw(uint256 streamId, address to, uint40 time) external override { // Checks, Effects and Interactions: make the withdrawal. _withdraw(streamId, to, time); } @@ -322,7 +342,7 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope } /// @inheritdoc ISablierV2OpenEnded - function withdrawMax(uint256 streamId, address to) external { + function withdrawMax(uint256 streamId, address to) external override { // Checks, Effects and Interactions: make the withdrawal. _withdraw(streamId, to, uint40(block.timestamp)); } diff --git a/src/abstracts/SablierV2OpenEndedState.sol b/src/abstracts/SablierV2OpenEndedState.sol index 00ec1bc7..6464fcf9 100644 --- a/src/abstracts/SablierV2OpenEndedState.sol +++ b/src/abstracts/SablierV2OpenEndedState.sol @@ -109,12 +109,18 @@ abstract contract SablierV2OpenEndedState is ISablierV2OpenEndedState { } /// @inheritdoc ISablierV2OpenEndedState - function getSender(uint256 streamId) external view notNull(streamId) returns (address sender) { + function getSender(uint256 streamId) external view override notNull(streamId) returns (address sender) { sender = _streams[streamId].sender; } /// @inheritdoc ISablierV2OpenEndedState - function getStream(uint256 streamId) external view notNull(streamId) returns (OpenEnded.Stream memory stream) { + function getStream(uint256 streamId) + external + view + override + notNull(streamId) + returns (OpenEnded.Stream memory stream) + { stream = _streams[streamId]; } @@ -124,7 +130,7 @@ abstract contract SablierV2OpenEndedState is ISablierV2OpenEndedState { } /// @inheritdoc ISablierV2OpenEndedState - function isStream(uint256 streamId) public view returns (bool result) { + function isStream(uint256 streamId) public view override returns (bool result) { result = _streams[streamId].isStream; } } From 939cf40cd82c42f0f70b8b0ee9db2ead804d322b Mon Sep 17 00:00:00 2001 From: smol-ninja Date: Sat, 27 Apr 2024 14:01:01 +0100 Subject: [PATCH 4/6] style: solhint-disable no-console --- script/Base.s.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/Base.s.sol b/script/Base.s.sol index a64b9c2b..3b551b38 100644 --- a/script/Base.s.sol +++ b/script/Base.s.sol @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-or-later +// solhint-disable no-console pragma solidity >=0.8.22; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; @@ -57,7 +58,7 @@ abstract contract BaseScript is Script { string memory json = vm.readFile("package.json"); string memory version = json.readString(".version"); string memory create2Salt = string.concat("ChainID ", chainId, ", Version ", version); - console2.log("The CREATE2 salt is \"%s\"", create2Salt); + console2.log("The CREATE2 salt is %s", create2Salt); return bytes32(abi.encodePacked(create2Salt)); } } From 0f35376b4af1ebbe6eb1f8e2e28ed988c82a595a Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Mon, 29 Apr 2024 14:58:56 +0300 Subject: [PATCH 5/6] chore: use return variable in streamDebtOf --- src/SablierV2OpenEnded.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SablierV2OpenEnded.sol b/src/SablierV2OpenEnded.sol index ad784789..7f1ec665 100644 --- a/src/SablierV2OpenEnded.sol +++ b/src/SablierV2OpenEnded.sol @@ -62,10 +62,10 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope uint128 streamedAmount = _streamedAmountOf(streamId, uint40(block.timestamp)); if (balance < streamedAmount) { - return streamedAmount - balance; + debt = streamedAmount - balance; + } else { + return 0; } - - return 0; } /// @inheritdoc ISablierV2OpenEnded From 614c84f3d50d61a4105b8d570a459057fed842d9 Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Mon, 29 Apr 2024 15:06:06 +0300 Subject: [PATCH 6/6] test: update streamDebt files --- .../streamDebtOf.t.sol} | 8 +++++++- .../streamDebt.tree => stream-debt-of/streamDebtOf.tree} | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) rename test/integration/{stream-debt/streamDebt.t.sol => stream-debt-of/streamDebtOf.t.sol} (74%) rename test/integration/{stream-debt/streamDebt.tree => stream-debt-of/streamDebtOf.tree} (96%) diff --git a/test/integration/stream-debt/streamDebt.t.sol b/test/integration/stream-debt-of/streamDebtOf.t.sol similarity index 74% rename from test/integration/stream-debt/streamDebt.t.sol rename to test/integration/stream-debt-of/streamDebtOf.t.sol index cc329f62..a0ff6bd3 100644 --- a/test/integration/stream-debt/streamDebt.t.sol +++ b/test/integration/stream-debt-of/streamDebtOf.t.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.22; +import { console2 } from "forge-std/src/console2.sol"; import { Integration_Test } from "../Integration.t.sol"; contract StreamDebt_Integration_Test is Integration_Test { @@ -18,15 +19,20 @@ contract StreamDebt_Integration_Test is Integration_Test { openEnded.streamDebtOf(defaultStreamId); } - function test_StreamDebt_BalanceGreaterThanOrEqualStreamedAmount() external givenNotNull givenNotCanceled { + function test_StreamDebtOf_BalanceGreaterThanOrEqualStreamedAmount() external givenNotNull givenNotCanceled { defaultDeposit(); uint128 streamDebt = openEnded.streamDebtOf(defaultStreamId); + assertEq(streamDebt, 0, "stream debt"); } function test_streamDebtOf() external givenNotNull givenNotCanceled { vm.warp({ newTimestamp: WARP_ONE_MONTH }); uint128 streamDebt = openEnded.streamDebtOf(defaultStreamId); + + console2.log("streamedAmountOf %s", openEnded.streamedAmountOf(defaultStreamId)); + console2.log("balance %s", openEnded.getBalance(defaultStreamId)); + assertEq(streamDebt, ONE_MONTH_STREAMED_AMOUNT, "stream debt"); } } diff --git a/test/integration/stream-debt/streamDebt.tree b/test/integration/stream-debt-of/streamDebtOf.tree similarity index 96% rename from test/integration/stream-debt/streamDebt.tree rename to test/integration/stream-debt-of/streamDebtOf.tree index 18102d58..db21f29e 100644 --- a/test/integration/stream-debt/streamDebt.tree +++ b/test/integration/stream-debt-of/streamDebtOf.tree @@ -1,4 +1,4 @@ -streamDebt.t.sol +streamDebtOf.t.sol ├── given the id references a null stream │ └── it should revert └── given the id does not reference a null stream