Skip to content

Commit

Permalink
test: improve wording in testing trees
Browse files Browse the repository at this point in the history
test: add new "operator" user
test: add new testing branches for un/authorized
test: delete superfluous warps in "withdraw" tests
test: move assertions for recipients at the bottom
test: refer to approved "third-party" as "operator"
test: rename "withdrawAmountZero" to "withdrawAmount"
test: refactor "CallerRecipient" to "OriginalRecipient"
test: use the new operator user in the "approved operator" tests
  • Loading branch information
PaulRBerg committed Oct 23, 2022
1 parent 660cf68 commit 7e9cec0
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 195 deletions.
12 changes: 11 additions & 1 deletion test/unit/SablierV2UnitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract contract SablierV2UnitTest is Test {
struct Users {
address payable alice;
address payable eve;
address payable operator;
address payable recipient;
address payable sender;
}
Expand Down Expand Up @@ -76,13 +77,22 @@ abstract contract SablierV2UnitTest is Test {
STOP_TIME = block.timestamp + TOTAL_DURATION;

// Create 5 users for testing. Order matters.
users = Users({ sender: getNextUser(), recipient: getNextUser(), eve: getNextUser(), alice: getNextUser() });
users = Users({
sender: getNextUser(),
recipient: getNextUser(),
operator: getNextUser(),
eve: getNextUser(),
alice: getNextUser()
});
fundUser(users.sender);
vm.label(users.sender, "Sender");

fundUser(users.recipient);
vm.label(users.recipient, "Recipient");

fundUser(users.operator);
vm.label(users.operator, "Operator");

fundUser(users.eve);
vm.label(users.eve, "Eve");

Expand Down
36 changes: 18 additions & 18 deletions test/unit/sablier-v2-linear/cancel-all/cancelAll.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
}

/// @dev it should cancel and delete the streams.
function testCancelAll__CallerApprovedThirdPartyAllStreams()
function testCancelAll__CallerApprovedOperatorAllStreams()
external
OnlyExistentStreams
AllStreamsCancelable
CallerAuthorizedAllStreams
{
// Approve Alice for all the streams.
sablierV2Linear.setApprovalForAll(users.alice, true);
// Approve the operator for all streams.
sablierV2Linear.setApprovalForAll(users.operator, true);

// Make Alice the `msg.sender` in this test case.
changePrank(users.alice);
// Make the operator the `msg.sender` in this test case.
changePrank(users.operator);

// Run the test.
sablierV2Linear.cancelAll(defaultStreamIds);
Expand All @@ -161,16 +161,16 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
}

/// @dev it should revert.
function testCannotCancelAll__RecipientNotOwnerAllStreams()
function testCannotCancelAll__OriginalRecipientTransferredOwnershipAllStreams()
external
OnlyExistentStreams
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
{
// Transfer the streams to eve.
sablierV2Linear.safeTransferFrom(users.recipient, users.eve, defaultStreamIds[0]);
sablierV2Linear.safeTransferFrom(users.recipient, users.eve, defaultStreamIds[1]);
// Transfer the streams to Alice.
sablierV2Linear.safeTransferFrom(users.recipient, users.alice, defaultStreamIds[0]);
sablierV2Linear.safeTransferFrom(users.recipient, users.alice, defaultStreamIds[1]);

// Run the test.
vm.expectRevert(
Expand All @@ -180,15 +180,15 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
}

/// @dev it should revert.
function testCannotCancelAll__RecipientNotOwnerSomeStreams()
function testCannotCancelAll__OriginalRecipientTransferredOnwershipSomeStreams()
external
OnlyExistentStreams
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
{
// Transfer one of the streams to eve.
sablierV2Linear.safeTransferFrom(users.recipient, users.eve, defaultStreamIds[0]);
sablierV2Linear.safeTransferFrom(users.recipient, users.alice, defaultStreamIds[0]);

// Run the test.
vm.expectRevert(
Expand All @@ -197,7 +197,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
sablierV2Linear.cancelAll(defaultStreamIds);
}

modifier RecipientOwnerAllStreams() {
modifier OriginalRecipientAllStreams() {
_;
}

Expand All @@ -208,7 +208,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
RecipientOwnerAllStreams
OriginalRecipientAllStreams
{
// Warp to the end of the stream.
vm.warp(daiStream.stopTime);
Expand All @@ -231,7 +231,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
RecipientOwnerAllStreams
OriginalRecipientAllStreams
{
// Warp to the end of the stream.
vm.warp(daiStream.stopTime);
Expand All @@ -255,7 +255,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
RecipientOwnerAllStreams
OriginalRecipientAllStreams
{
// Warp to 2,600 seconds after the start time (26% of the default stream duration).
vm.warp(daiStream.startTime + TIME_OFFSET);
Expand All @@ -278,7 +278,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
RecipientOwnerAllStreams
OriginalRecipientAllStreams
{
// Warp to 2,600 seconds after the start time (26% of the default stream duration).
vm.warp(daiStream.startTime + TIME_OFFSET);
Expand All @@ -301,7 +301,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
RecipientOwnerAllStreams
OriginalRecipientAllStreams
{
// Use the first default stream as the ongoing daiStream.
uint256 ongoingStreamId = defaultStreamIds[0];
Expand Down Expand Up @@ -341,7 +341,7 @@ contract SablierV2Linear__CancelAll is SablierV2LinearUnitTest {
AllStreamsCancelable
CallerAuthorizedAllStreams
CallerRecipientAllStreams
RecipientOwnerAllStreams
OriginalRecipientAllStreams
{
// Use the first default stream as the ongoing daiStream.
uint256 ongoingStreamId = defaultStreamIds[0];
Expand Down
12 changes: 6 additions & 6 deletions test/unit/sablier-v2-linear/cancel-all/cancelAll.tree
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ cancelAll.t.sol
├── when some of the streams are non-cancelable
│ └── it should cancel and delete the cancelable streams
└── when all streams are cancelable
├── when the caller is neither the sender nor authorized of any stream
├── when the caller is not authorized for any stream
│ └── it should revert
├── when the caller is neither the sender nor authorized of some of the streams
├── when the caller is not authorized for some streams
│ └── it should revert
├── when the caller is the sender of all streams
│ └── it should cancel and delete the streams
├── when the caller is an approved third-party for all the streams
├── when the caller is an approved operator for all streams
│ └── it should cancel and delete the streams
└── when the caller is the recipient of all streams
├── when the recipient transferred all the streams and does not own any
├── when the original recipient transferred ownership of all streams
│ └── it should revert
├── when the recipient transferred some of the streams and does not own all of them
├── when the original recipient transferred ownership of some of the streams
│ └── it should revert
└── when the recipient owns all the streams
└── when the original recipient did not transfer ownership of any stream
├── when all streams are ended
│ ├── it should cancel and delete the streams
│ └── it should emit multiple Cancel events
Expand Down
18 changes: 9 additions & 9 deletions test/unit/sablier-v2-linear/cancel/cancel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
}

/// @dev it should cancel and delete the stream.
function testCancel__CallerApprovedThirdParty() external StreamExistent StreamCancelable CallerAuthorized {
function testCancel__CallerApprovedOperator() external StreamExistent StreamCancelable CallerAuthorized {
// Approve Alice for the stream.
sablierV2Linear.approve(users.alice, daiStreamId);

Expand All @@ -93,15 +93,15 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
}

/// @dev it should revert.
function testCannotCancel__RecipientNotOwner()
function testCannotCancel__OriginalRecipientTransferredOwnership()
external
StreamExistent
StreamCancelable
CallerAuthorized
CallerRecipient
{
// Transfer the stream to eve.
sablierV2Linear.safeTransferFrom(users.recipient, users.eve, daiStreamId);
// Transfer the stream to Alice.
sablierV2Linear.safeTransferFrom(users.recipient, users.alice, daiStreamId);

// Run the test.
vm.expectRevert(
Expand All @@ -110,7 +110,7 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
sablierV2Linear.cancel(daiStreamId);
}

modifier RecipientOwner() {
modifier OriginalRecipient() {
_;
}

Expand All @@ -121,7 +121,7 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
StreamCancelable
CallerAuthorized
CallerRecipient
RecipientOwner
OriginalRecipient
{
// Warp to the end of the stream.
vm.warp(daiStream.stopTime);
Expand All @@ -140,7 +140,7 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
StreamCancelable
CallerAuthorized
CallerRecipient
RecipientOwner
OriginalRecipient
{
// Warp to the end of the stream.
vm.warp(daiStream.stopTime);
Expand All @@ -159,7 +159,7 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
StreamCancelable
CallerAuthorized
CallerRecipient
RecipientOwner
OriginalRecipient
{
// Warp to 2,600 seconds after the start time (26% of the default stream duration).
vm.warp(daiStream.startTime + TIME_OFFSET);
Expand All @@ -178,7 +178,7 @@ contract SablierV2Linear__Cancel is SablierV2LinearUnitTest {
StreamCancelable
CallerAuthorized
CallerRecipient
RecipientOwner
OriginalRecipient
{
// Warp to 2,600 seconds after the start time (26% of the default stream duration).
vm.warp(daiStream.startTime + TIME_OFFSET);
Expand Down
31 changes: 16 additions & 15 deletions test/unit/sablier-v2-linear/cancel/cancel.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ cancel.t.sol
├── when the stream is non-cancelable
│ └── it should revert
└── when the stream is cancelable
├── when the caller is neither the sender nor authorized
├── when the caller is not authorized
│ └── it should revert
├── when the caller is the sender
│ └── it should cancel and delete the stream
├── when the caller is an approved third-party
│ └── it should cancel and delete the stream
└── when the caller is the recipient
├── when the recipient transferred the stream and does not own it
│ └── it should revert
└── when the recipient owns the stream
├── when the stream ended
│ ├── it should cancel and delete the stream
│ └── it should emit a Cancel event
└── when the stream did not end
├── it should cancel and delete the stream
└── it should emit a Cancel event
└── when the caller is authorized
├── when the caller is the sender
│ └── it should cancel and delete the stream
├── when the caller is an approved operator
│ └── it should cancel and delete the stream
└── when the caller is the recipient
├── when the original recipient transferred ownership of the stream
│ └── it should revert
└── when the original recipient did not transfer ownership of the stream
├── when the stream ended
│ ├── it should cancel and delete the stream
│ └── it should emit a Cancel event
└── when the stream did not end
├── it should cancel and delete the stream
└── it should emit a Cancel event
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ contract SablierV2Linear__CreateWithDuration is SablierV2LinearUnitTest {
daiStream.cancelable
);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);

ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(daiStreamId);
assertEq(actualStream.sender, daiStream.sender);
assertEq(actualStream.depositAmount, daiStream.depositAmount);
Expand All @@ -109,5 +106,8 @@ contract SablierV2Linear__CreateWithDuration is SablierV2LinearUnitTest {
assertEq(actualStream.stopTime, stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);
}
}
24 changes: 12 additions & 12 deletions test/unit/sablier-v2-linear/create/create.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
daiStream.cancelable
);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);

ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(daiStreamId);
assertEq(actualStream.sender, daiStream.sender);
assertEq(actualStream.depositAmount, daiStream.depositAmount);
Expand All @@ -97,6 +94,9 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
assertEq(actualStream.stopTime, stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);
}

modifier StartTimeLessThanStopTime() {
Expand Down Expand Up @@ -150,9 +150,6 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
daiStream.cancelable
);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);

ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(daiStreamId);
assertEq(actualStream.sender, daiStream.sender);
assertEq(actualStream.depositAmount, daiStream.depositAmount);
Expand All @@ -162,6 +159,9 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
assertEq(actualStream.stopTime, daiStream.stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);
}

modifier StartTimeLessThanCliffTime() {
Expand Down Expand Up @@ -217,9 +217,6 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
daiStream.cancelable
);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);

ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(daiStreamId);
assertEq(actualStream.sender, daiStream.sender);
assertEq(actualStream.depositAmount, daiStream.depositAmount);
Expand All @@ -229,6 +226,9 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
assertEq(actualStream.stopTime, daiStream.stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);
}

modifier CliffLessThanStopTime() {
Expand Down Expand Up @@ -285,9 +285,6 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
daiStream.cancelable
);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);

ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(daiStreamId);
assertEq(actualStream.sender, daiStream.sender);
assertEq(actualStream.depositAmount, daiStream.depositAmount);
Expand All @@ -297,6 +294,9 @@ contract SablierV2Linear__Create is SablierV2LinearUnitTest {
assertEq(actualStream.stopTime, daiStream.stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);

address actualRecipient = sablierV2Linear.getRecipient(daiStreamId);
assertEq(actualRecipient, users.recipient);
}

modifier TokenCompliant() {
Expand Down
Loading

0 comments on commit 7e9cec0

Please sign in to comment.