Skip to content

Commit

Permalink
test: when caller is not the sender of the stream
Browse files Browse the repository at this point in the history
chore: set "indent_size" for "*.tree" files in ".editorconfig"
test: rename "createdStream" to "actualStream"
test: reverse order of streams in "assertEq"
  • Loading branch information
PaulRBerg committed Jun 22, 2022
1 parent 9e4a546 commit bf3e863
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 73 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{toml,sol}]
[*.{sol,toml}]
indent_size = 4

[*.tree]
indent_size = 1
6 changes: 6 additions & 0 deletions test/unit/sablier-v2-cliff/SablierV2CliffUnitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ abstract contract SablierV2CliffUnitTest is SablierV2UnitTest {
usdc.approve(address(sablierV2Cliff), MAX_UINT_256);
nonStandardToken.approve(address(sablierV2Cliff), MAX_UINT_256);

// Approve the SablierV2Cliff contract to spend tokens from Alice.
changePrank(users.alice);
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 tokens from Eve.
changePrank(users.eve);
dai.approve(address(sablierV2Cliff), MAX_UINT_256);
Expand Down
72 changes: 65 additions & 7 deletions test/unit/sablier-v2-cliff/create/create.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest {
function testCreate__6Decimals__Event() external {
uint256 streamId = sablierV2Cliff.nextStreamId();
vm.expectEmit(true, true, true, true);
address funder = usdcStream.sender;
emit CreateStream(
streamId,
usdcStream.sender,
funder,
usdcStream.sender,
usdcStream.recipient,
usdcStream.depositAmount,
Expand All @@ -237,29 +238,86 @@ contract SablierV2Cliff__UnitTest__Create is SablierV2CliffUnitTest {
createDefaultUsdcStream();
}

/// @dev When all checks pass and the token has 18 decimals, it should create the stream.
function testCreate__18Decimals() external {
/// @dev When all checks pass, the token has 18 decimals and the caller is the sender of the stream,
/// it should create the stream.
function testCreate__18Decimals__CallerSender() external {
uint256 streamId = createDefaultDaiStream();
ISablierV2Cliff.Stream memory createdStream = sablierV2Cliff.getStream(streamId);
assertEq(daiStream, createdStream);
}

/// @dev When all checks pass and the token has 18 decimals, it should bump the next stream id.
function testCreate__18Decimals__NextStreamId() external {
/// @dev When all checks pass and the token has 18 decimals and the caller is the sender of the stream,
/// it should bump the next stream id.
function testCreate__18Decimals__CallerSender__NextStreamId() external {
uint256 nextStreamId = sablierV2Cliff.nextStreamId();
createDefaultDaiStream();
uint256 actualNextStreamId = sablierV2Cliff.nextStreamId();
uint256 expectedNextStreamId = nextStreamId + 1;
assertEq(actualNextStreamId, expectedNextStreamId);
}

/// @dev When all checks pass and the token has 18 decimals, it should emit a CreateStream event.
function testCreate__18Decimals__Event() external {
/// @dev When all checks pass, the token has 18 decimals and the caller is the sender of the stream,
/// it should emit a CreateStream event.
function testCreate__18Decimals__CallerSender__Event() external {
uint256 streamId = sablierV2Cliff.nextStreamId();
vm.expectEmit(true, true, true, true);
address funder = daiStream.sender;
emit CreateStream(
streamId,
funder,
daiStream.sender,
daiStream.recipient,
daiStream.depositAmount,
daiStream.token,
daiStream.startTime,
daiStream.cliffTime,
daiStream.stopTime,
daiStream.cancelable
);
createDefaultDaiStream();
}

/// @dev When all checks pass, the token has 18 decimals and the caller is not the sender of the stream,
/// it should create the stream.
function testCreate__18Decimals__CallerNotSender() external {
// Make Alice the funder of the stream.
changePrank(users.alice);
uint256 streamId = createDefaultDaiStream();

// Run the test.
ISablierV2Cliff.Stream memory actualStream = sablierV2Cliff.getStream(streamId);
ISablierV2Cliff.Stream memory expectedStream = daiStream;
assertEq(actualStream, expectedStream);
}

/// @dev When all checks pass, the token has 18 decimals and the caller is not the sender of the stream,
/// it should bump the next stream id.
function testCreate__18Decimals__CallerNotSender__NextStreamId() external {
uint256 nextStreamId = sablierV2Cliff.nextStreamId();

// Make Alice the funder of the stream.
changePrank(users.alice);
createDefaultDaiStream();

// Run the test.
uint256 actualNextStreamId = sablierV2Cliff.nextStreamId();
uint256 expectedNextStreamId = nextStreamId + 1;
assertEq(actualNextStreamId, expectedNextStreamId);
}

/// @dev When all checks pass, the token has 18 decimals and the caller is not the sender of the stream,
/// it should emit a CreateStream event.
function testCreate__18Decimals__CallerNotSender__Event() external {
// Make Alice the funder of the stream.
changePrank(users.alice);

// Run the test.
uint256 streamId = sablierV2Cliff.nextStreamId();
vm.expectEmit(true, true, true, true);
address funder = users.alice;
emit CreateStream(
streamId,
funder,
daiStream.sender,
daiStream.recipient,
daiStream.depositAmount,
Expand Down
34 changes: 21 additions & 13 deletions test/unit/sablier-v2-cliff/create/create.tree
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ create.t.sol
├── when the cliff time is equal to the stop time
│ └── it should create the stream
└── when the cliff time is less than the stop time
├── when the token is not a contract
│ └── it should revert
├── when the token misses the return value
│ └── it should create the stream
└── when the token is ERC-20 compliant
├── 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
├── when the caller is not the same as the sender
│ └── it should create the stream
└── when the caller is the same as the sender
├── when the token is not a contract
│ └── it should revert
├── when the token misses the return value
│ └── it should create the stream
└── when the token is ERC-20 compliant
├── 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
├── when the caller is not the same as the sender of the stream
│ ├── it should create the stream
│ ├── it should bump the next stream id
│ └── it should emit a CreateStream event
└── when the caller is the same as the sender of the stream
├── it should create the stream
├── it should bump the next stream id
└── it should emit a CreateStream event
6 changes: 6 additions & 0 deletions test/unit/sablier-v2-linear/SablierV2LinearUnitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ abstract contract SablierV2LinearUnitTest is SablierV2UnitTest {
usdc.approve(address(sablierV2Linear), MAX_UINT_256);
nonStandardToken.approve(address(sablierV2Linear), MAX_UINT_256);

// Approve the SablierV2Cliff contract to spend tokens from Alice.
changePrank(users.alice);
dai.approve(address(sablierV2Linear), MAX_UINT_256);
usdc.approve(address(sablierV2Linear), MAX_UINT_256);
nonStandardToken.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);
Expand Down
113 changes: 85 additions & 28 deletions test/unit/sablier-v2-linear/create/create.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest {
);
}

/// @dev When the start time is the equal to the stop time, it should create the stream.
/// @dev When the start time is equal to the stop time, it should create the stream.
function testCreate__StartTimeEqualToStopTime() external {
uint256 stopTime = daiStream.startTime;
uint256 streamId = sablierV2Linear.create(
Expand All @@ -70,15 +70,15 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest {
stopTime,
daiStream.cancelable
);
ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId);
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(daiStream.cancelable, createdStream.cancelable);
assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount);
ISablierV2Linear.Stream memory actualStream = sablierV2Linear.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.stopTime, stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);
}

/// @dev When the token is not a contract, it should revert.
Expand Down Expand Up @@ -110,15 +110,15 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest {
daiStream.cancelable
);

ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId);
assertEq(daiStream.sender, createdStream.sender);
assertEq(daiStream.recipient, createdStream.recipient);
assertEq(daiStream.depositAmount, createdStream.depositAmount);
assertEq(address(nonStandardToken), address(createdStream.token));
assertEq(daiStream.startTime, createdStream.startTime);
assertEq(daiStream.stopTime, createdStream.stopTime);
assertEq(daiStream.cancelable, createdStream.cancelable);
assertEq(daiStream.withdrawnAmount, createdStream.withdrawnAmount);
ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId);
assertEq(actualStream.sender, daiStream.sender);
assertEq(actualStream.recipient, daiStream.recipient);
assertEq(actualStream.depositAmount, daiStream.depositAmount);
assertEq(address(actualStream.token), address(nonStandardToken));
assertEq(actualStream.startTime, daiStream.startTime);
assertEq(actualStream.stopTime, daiStream.stopTime);
assertEq(actualStream.cancelable, daiStream.cancelable);
assertEq(actualStream.withdrawnAmount, daiStream.withdrawnAmount);
}

/// @dev When all checks pass and the token has 6 decimals, it should create the stream.
Expand All @@ -142,9 +142,10 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest {
function testCreate__6Decimals__Event() external {
uint256 streamId = sablierV2Linear.nextStreamId();
vm.expectEmit(true, true, true, true);
address funder = usdcStream.sender;
emit CreateStream(
streamId,
usdcStream.sender,
funder,
usdcStream.sender,
usdcStream.recipient,
usdcStream.depositAmount,
Expand All @@ -156,29 +157,85 @@ contract SablierV2Linear__UnitTest__Create is SablierV2LinearUnitTest {
createDefaultUsdcStream();
}

/// @dev When all checks pass and the token has 18 decimals, it should create the stream.
function testCreate__18Decimals() external {
/// @dev When all checks pass, the token has 18 decimals and the caller is the sender of the stream,
/// it should create the stream.
function testCreate__18Decimals__CallerSender() external {
uint256 streamId = createDefaultDaiStream();
ISablierV2Linear.Stream memory createdStream = sablierV2Linear.getStream(streamId);
assertEq(daiStream, createdStream);
ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId);
assertEq(daiStream, actualStream);
}

/// @dev When all checks pass and the token has 18 decimals, it should bump the next stream id.
function testCreate__18Decimals__NextStreamId() external {
/// @dev When all checks pass, the token has 18 decimals and the caller is the sender of the stream,\
/// it should bump the next stream id.
function testCreate__18Decimals__CallerSender__NextStreamId() external {
uint256 nextStreamId = sablierV2Linear.nextStreamId();
createDefaultDaiStream();
uint256 actualNextStreamId = sablierV2Linear.nextStreamId();
uint256 expectedNextStreamId = nextStreamId + 1;
assertEq(actualNextStreamId, expectedNextStreamId);
}

/// @dev When all checks pass and the token has 18 decimals, it should emit a CreateStream event.
function testCreate__18Decimals__Event() external {
/// @dev When all checks pass, the token has 18 decimals and the caller is the sender of the stream,
/// it should emit a CreateStream event.
function testCreate__18Decimals__CallerSender__Event() external {
uint256 streamId = sablierV2Linear.nextStreamId();
vm.expectEmit(true, true, true, true);
address funder = daiStream.sender;
emit CreateStream(
streamId,
funder,
daiStream.sender,
daiStream.recipient,
daiStream.depositAmount,
daiStream.token,
daiStream.startTime,
daiStream.stopTime,
daiStream.cancelable
);
createDefaultDaiStream();
}

/// @dev When all checks pass, the token has 18 decimals and the caller is not the sender of the stream,
/// it should create the stream.
function testCreate__18Decimals__CallerNotSender() external {
// Make Alice the funder of the stream.
changePrank(users.alice);
uint256 streamId = createDefaultDaiStream();

// Run the test.
ISablierV2Linear.Stream memory actualStream = sablierV2Linear.getStream(streamId);
ISablierV2Linear.Stream memory expectedStream = daiStream;
assertEq(actualStream, expectedStream);
}

/// @dev When all checks pass, the token has 18 decimals and the caller is not the sender of the stream,
/// it should bump the next stream id.
function testCreate__18Decimals__CallerNotSender__NextStreamId() external {
uint256 nextStreamId = sablierV2Linear.nextStreamId();

// Make Alice the funder of the stream.
changePrank(users.alice);
createDefaultDaiStream();

// Run the test.
uint256 actualNextStreamId = sablierV2Linear.nextStreamId();
uint256 expectedNextStreamId = nextStreamId + 1;
assertEq(actualNextStreamId, expectedNextStreamId);
}

/// @dev When all checks pass, the token has 18 decimals and the caller is not the sender of the stream,
/// it should emit a CreateStream event.
function testCreate__18Decimals__CallerNotSender__Event() external {
// Make Alice the funder of the stream.
changePrank(users.alice);

// Run the test.
uint256 streamId = sablierV2Linear.nextStreamId();
vm.expectEmit(true, true, true, true);
address funder = users.alice;
emit CreateStream(
streamId,
funder,
daiStream.sender,
daiStream.recipient,
daiStream.depositAmount,
Expand Down
32 changes: 20 additions & 12 deletions test/unit/sablier-v2-linear/create/create.tree
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@ create.t.sol
├── when the start time is equal to the stop time
│ └── it should create the stream
└── when the start time is less than the stop time
├── when the token is not a contract
│ └── it should revert
├── when the token misses the return value
├── when the caller is not the same as the sender
│ └── it should create the stream
└── when the token is ERC-20 compliant
├── 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
└── when the caller is the same as the sender
├── when the token is not a contract
│ └── it should revert
├── when the token misses the return value
│ └── it should create the stream
└── when the token is ERC-20 compliant
├── 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
├── when the caller is not the same as the sender of the stream
│ ├── it should create the stream
│ ├── it should bump the next stream id
│ └── it should emit a CreateStream event
└── when the caller is the same as the sender of the stream
├── it should create the stream
├── it should bump the next stream id
└── it should emit a CreateStream event
6 changes: 6 additions & 0 deletions test/unit/sablier-v2-pro/SablierV2ProUnitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ abstract contract SablierV2ProUnitTest is SablierV2UnitTest {
usdc.approve(address(sablierV2Pro), MAX_UINT_256);
nonStandardToken.approve(address(sablierV2Pro), MAX_UINT_256);

// Approve the SablierV2Cliff contract to spend tokens from Alice.
changePrank(users.alice);
dai.approve(address(sablierV2Pro), MAX_UINT_256);
usdc.approve(address(sablierV2Pro), MAX_UINT_256);
nonStandardToken.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);
Expand Down
Loading

0 comments on commit bf3e863

Please sign in to comment.