From 630c5791186255b6653f5969c17cfeb9afa85322 Mon Sep 17 00:00:00 2001 From: Paul Razvan Berg Date: Fri, 17 Feb 2023 19:20:23 +0200 Subject: [PATCH] test: add test when array count is zero --- .../cancel-multiple/cancelMultiple.t.sol | 32 +++++++++-- .../cancel-multiple/cancelMultiple.tree | 57 ++++++++++--------- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/test/unit/lockup/shared/cancel-multiple/cancelMultiple.t.sol b/test/unit/lockup/shared/cancel-multiple/cancelMultiple.t.sol index ea92bf4be..d6482fdc1 100644 --- a/test/unit/lockup/shared/cancel-multiple/cancelMultiple.t.sol +++ b/test/unit/lockup/shared/cancel-multiple/cancelMultiple.t.sol @@ -24,14 +24,24 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { } /// @dev it should do nothing. - function test_RevertWhen_OnlyNullStreams() external { + function test_RevertWhen_ArrayCountZero() external { + uint256[] memory streamIds = new uint256[](0); + lockup.cancelMultiple(streamIds); + } + + modifier arrayCountNotZero() { + _; + } + + /// @dev it should do nothing. + function test_RevertWhen_OnlyNullStreams() external arrayCountNotZero { uint256 nullStreamId = 1729; uint256[] memory streamIds = Solarray.uint256s(nullStreamId); lockup.cancelMultiple(streamIds); } /// @dev it should ignore the null streams and cancel the non-null ones. - function test_RevertWhen_SomeNullStreams() external { + function test_RevertWhen_SomeNullStreams() external arrayCountNotZero { uint256 nullStreamId = 1729; uint256[] memory streamIds = Solarray.uint256s(defaultStreamIds[0], nullStreamId); lockup.cancelMultiple(streamIds); @@ -45,7 +55,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { } /// @dev it should do nothing. - function test_RevertWhen_AllStreamsNonCancelable() external onlyNonNullStreams { + function test_RevertWhen_AllStreamsNonCancelable() external arrayCountNotZero onlyNonNullStreams { // Create the non-cancelable stream. uint256 nonCancelableStreamId = createDefaultStreamNonCancelable(); @@ -54,7 +64,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { } /// @dev it should ignore the non-cancelable streams and cancel the cancelable streams. - function test_RevertWhen_SomeStreamsNonCancelable() external onlyNonNullStreams { + function test_RevertWhen_SomeStreamsNonCancelable() external arrayCountNotZero onlyNonNullStreams { // Create the non-cancelable stream. uint256 nonCancelableStreamId = createDefaultStreamNonCancelable(); @@ -78,6 +88,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should revert. function test_RevertWhen_CallerUnauthorizedAllStreams_MaliciousThirdParty() external + arrayCountNotZero onlyNonNullStreams allStreamsCancelable { @@ -94,6 +105,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should revert. function test_RevertWhen_CallerUnauthorizedAllStreams_ApprovedOperator() external + arrayCountNotZero onlyNonNullStreams allStreamsCancelable { @@ -113,6 +125,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should revert. function test_RevertWhen_CallerUnauthorizedAllStreams_FormerRecipient() external + arrayCountNotZero onlyNonNullStreams allStreamsCancelable { @@ -130,6 +143,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should revert. function test_RevertWhen_CallerUnauthorizedSomeStreams_MaliciousThirdParty() external + arrayCountNotZero onlyNonNullStreams allStreamsCancelable { @@ -149,6 +163,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should revert. function test_RevertWhen_CallerUnauthorizedSomeStreams_ApprovedOperator() external + arrayCountNotZero onlyNonNullStreams allStreamsCancelable { @@ -168,6 +183,7 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should revert. function test_RevertWhen_CallerUnauthorizedSomeStreams_FormerRecipient() external + arrayCountNotZero onlyNonNullStreams allStreamsCancelable { @@ -187,7 +203,13 @@ abstract contract CancelMultiple_Unit_Test is Unit_Test, Lockup_Shared_Test { /// @dev it should perform the ERC-20 transfers, cancel the streams, update the withdrawn amounts, and emit /// CancelLockupStream events. - function test_CancelMultiple_Sender() external onlyNonNullStreams allStreamsCancelable callerAuthorizedAllStreams { + function test_CancelMultiple_Sender() + external + arrayCountNotZero + onlyNonNullStreams + allStreamsCancelable + callerAuthorizedAllStreams + { changePrank({ msgSender: users.sender }); test_CancelMultiple(); } diff --git a/test/unit/lockup/shared/cancel-multiple/cancelMultiple.tree b/test/unit/lockup/shared/cancel-multiple/cancelMultiple.tree index 1e33f55b9..d1daea34d 100644 --- a/test/unit/lockup/shared/cancel-multiple/cancelMultiple.tree +++ b/test/unit/lockup/shared/cancel-multiple/cancelMultiple.tree @@ -1,30 +1,33 @@ cancelMultiple.t.sol -├── when the stream ids array points only to null streams +├── when the array count is zero │ └── it should do nothing -├── when the stream ids array points to some null streams -│ └── it should ignore the null streams and cancel the non-null ones -└── when the stream ids array points only to non-null streams - ├── when all streams are non-cancelable +└── when the array count is not zero + ├── when the stream ids array points only to null streams │ └── it should do nothing - ├── when some of the streams are non-cancelable - │ └── it should ignore the non-cancelable streams and cancel the cancelable streams - └── when all streams are cancelable - ├── when the caller is unauthorized for any stream - │ ├── when the caller is a malicious third-party - │ │ └── it should revert - │ ├── when the caller is an approved operator - │ │ └── it should revert - │ └── when the caller is a former recipient - │ └── it should revert - ├── when the caller is unauthorized for some streams - │ ├── when the caller is a malicious third-party - │ │ └── it should revert - │ ├── when the caller is an approved operator - │ │ └── it should revert - │ └── when the caller is a former recipient - │ └── it should revert - └── when the caller is authorized for all streams - ├── when the caller is the sender - │ └── it should perform the ERC-20 transfers, cancel the streams, update the withdrawn amounts, and emit {CancelLockupStream} events - └── when the caller is the recipient - └── it should perform the ERC-20 transfers, cancel the streams, update the withdrawn amounts, and emit {CancelLockupStream} events + ├── when the stream ids array points to some null streams + │ └── it should ignore the null streams and cancel the non-null ones + └── when the stream ids array points only to non-null streams + ├── when all streams are non-cancelable + │ └── it should do nothing + ├── when some of the streams are non-cancelable + │ └── it should ignore the non-cancelable streams and cancel the cancelable streams + └── when all streams are cancelable + ├── when the caller is unauthorized for any stream + │ ├── when the caller is a malicious third-party + │ │ └── it should revert + │ ├── when the caller is an approved operator + │ │ └── it should revert + │ └── when the caller is a former recipient + │ └── it should revert + ├── when the caller is unauthorized for some streams + │ ├── when the caller is a malicious third-party + │ │ └── it should revert + │ ├── when the caller is an approved operator + │ │ └── it should revert + │ └── when the caller is a former recipient + │ └── it should revert + └── when the caller is authorized for all streams + ├── when the caller is the sender + │ └── it should perform the ERC-20 transfers, cancel the streams, update the withdrawn amounts, and emit {CancelLockupStream} events + └── when the caller is the recipient + └── it should perform the ERC-20 transfers, cancel the streams, update the withdrawn amounts, and emit {CancelLockupStream} events