Skip to content

Commit

Permalink
test: add test when array count is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRBerg committed Feb 17, 2023
1 parent a880863 commit 630c579
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 32 deletions.
32 changes: 27 additions & 5 deletions test/unit/lockup/shared/cancel-multiple/cancelMultiple.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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();
}
Expand Down
57 changes: 30 additions & 27 deletions test/unit/lockup/shared/cancel-multiple/cancelMultiple.tree
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 630c579

Please sign in to comment.