Skip to content

Commit

Permalink
test: test contract for each testing branch
Browse files Browse the repository at this point in the history
chore: disable "no-empty-blocks" solhint rule
test: refactor all test function names

Closes #77
  • Loading branch information
PaulRBerg committed Jul 19, 2022
1 parent ebc9e7e commit 5841eb2
Show file tree
Hide file tree
Showing 52 changed files with 1,492 additions and 805 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion lib/prb-contracts
2 changes: 1 addition & 1 deletion src/SablierV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract contract SablierV2 is ISablierV2 {

/// @inheritdoc ISablierV2
function cancel(uint256 streamId) external {
// Checks: the `streamId` points to an existing stream.
// Checks: the `streamId` points to an existent stream.
if (getSender(streamId) == address(0)) {
revert SablierV2__StreamNonExistent(streamId);
}
Expand Down
100 changes: 0 additions & 100 deletions src/SablierV2Linear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,106 +180,6 @@ contract SablierV2Linear is
emit Renounce(streamId);
}

/// @inheritdoc ISablierV2
function withdraw(uint256 streamId, uint256 amount)
external
streamExists(streamId)
onlySenderOrRecipient(streamId)
{
address to = streams[streamId].recipient;
withdrawInternal(streamId, to, amount);
}

/// @inheritdoc ISablierV2
function withdrawAll(uint256[] calldata streamIds, uint256[] calldata amounts) external {
// Checks: count of `streamIds` matches count of `amounts`.
uint256 streamIdsCount = streamIds.length;
uint256 amountsCount = amounts.length;
if (streamIdsCount != amountsCount) {
revert SablierV2__WithdrawAllArraysNotEqual(streamIdsCount, amountsCount);
}

// Iterate over the provided array of stream ids and withdraw from each stream.
address sender;
uint256 streamId;
for (uint256 i = 0; i < streamIdsCount; ) {
streamId = streamIds[i];

// If the `streamId` points to a stream that does not exist, skip it.
sender = streams[streamId].sender;
if (sender != address(0)) {
// Checks: the `msg.sender` is either the sender or the recipient of the stream.
if (msg.sender != sender && msg.sender != streams[streamId].recipient) {
revert SablierV2__Unauthorized(streamId, msg.sender);
}

// Checks, Effects and Interactions: make the withdrawal.
withdrawInternal(streamId, streams[streamId].recipient, amounts[i]);
}

// Increment the for loop iterator.
unchecked {
i += 1;
}
}
}

/// @inheritdoc ISablierV2
function withdrawTo(
uint256 streamId,
address to,
uint256 amount
) external streamExists(streamId) onlyRecipient(streamId) {
// Checks: the provided address to withdraw to is not zero.
if (to == address(0)) {
revert SablierV2__WithdrawZeroAddress();
}

// Checks, Effects and Interactions: make the withdrawal.
withdrawInternal(streamId, to, amount);
}

/// @inheritdoc ISablierV2
function withdrawAllTo(
uint256[] calldata streamIds,
address to,
uint256[] calldata amounts
) external {
// Checks: the provided address to withdraw to is not zero.
if (to == address(0)) {
revert SablierV2__WithdrawZeroAddress();
}

// Checks: count of `streamIds` matches count of `amounts`.
uint256 streamIdsCount = streamIds.length;
uint256 amountsCount = amounts.length;
if (streamIdsCount != amountsCount) {
revert SablierV2__WithdrawAllArraysNotEqual(streamIdsCount, amountsCount);
}

// Iterate over the provided array of stream ids and withdraw from each stream.
uint256 streamId;
for (uint256 i = 0; i < streamIdsCount; ) {
streamId = streamIds[i];

// If the `streamId` points to a stream that does not exist, skip it.
if (streams[streamId].sender != address(0)) {
// Checks: the `msg.sender` is the recipient of the stream.
if (msg.sender != streams[streamId].recipient) {
revert SablierV2__Unauthorized(streamId, msg.sender);
}

// Checks, Effects and Interactions: make the withdrawal.
withdrawInternal(streamId, to, amounts[i]);
}

// Increment the for loop iterator.
unchecked {
i += 1;
}
}
}

/// INTERNAL NON-CONSTANT FUNCTIONS ///

/// @dev See the documentation for the public functions that call this internal function.
Expand Down
100 changes: 0 additions & 100 deletions src/SablierV2Pro.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,106 +286,6 @@ contract SablierV2Pro is
emit Renounce(streamId);
}

/// @inheritdoc ISablierV2
function withdraw(uint256 streamId, uint256 amount)
external
streamExists(streamId)
onlySenderOrRecipient(streamId)
{
address to = streams[streamId].recipient;
withdrawInternal(streamId, to, amount);
}

/// @inheritdoc ISablierV2
function withdrawAll(uint256[] calldata streamIds, uint256[] calldata amounts) external {
// Checks: count of `streamIds` matches count of `amounts`.
uint256 streamIdsCount = streamIds.length;
uint256 amountCount = amounts.length;
if (streamIdsCount != amountCount) {
revert SablierV2__WithdrawAllArraysNotEqual(streamIdsCount, amountCount);
}

// Iterate over the provided array of stream ids and withdraw from each stream.
address sender;
uint256 streamId;
for (uint256 i = 0; i < streamIdsCount; ) {
streamId = streamIds[i];

// If the `streamId` points to a stream that does not exist, skip it.
sender = streams[streamId].sender;
if (sender == address(0)) {
// Checks: the `msg.sender` is either the sender or the recipient of the stream.
if (msg.sender != sender && msg.sender != streams[streamId].recipient) {
revert SablierV2__Unauthorized(streamId, msg.sender);
}

// Checks, Effects and Interactions: make the withdrawal.
withdrawInternal(streamId, streams[streamId].recipient, amounts[i]);
}

// Increment the for loop iterator.
unchecked {
i += 1;
}
}
}

/// @inheritdoc ISablierV2
function withdrawTo(
uint256 streamId,
address to,
uint256 amount
) external streamExists(streamId) onlyRecipient(streamId) {
// Checks: the provided address to withdraw to is not zero.
if (to == address(0)) {
revert SablierV2__WithdrawZeroAddress();
}

// Checks, Effects and Interactions: make the withdrawal.
withdrawInternal(streamId, to, amount);
}

/// @inheritdoc ISablierV2
function withdrawAllTo(
uint256[] calldata streamIds,
address to,
uint256[] calldata amounts
) external {
// Checks: the provided address to withdraw to is not zero.
if (to == address(0)) {
revert SablierV2__WithdrawZeroAddress();
}

// Checks: count of `streamIds` matches count of `amounts`.
uint256 streamIdsCount = streamIds.length;
uint256 amountCount = amounts.length;
if (streamIdsCount != amountCount) {
revert SablierV2__WithdrawAllArraysNotEqual(streamIdsCount, amountCount);
}

// Iterate over the provided array of stream ids and withdraw from each stream.
uint256 streamId;
for (uint256 i = 0; i < streamIdsCount; ) {
streamId = streamIds[i];

// If the `streamId` points to a stream that does not exist, skip it.
if (streams[streamId].sender == address(0)) {
// Checks: the `msg.sender` is the recipient of the stream.
if (msg.sender != streams[streamId].recipient) {
revert SablierV2__Unauthorized(streamId, msg.sender);
}

// Checks, Effects and Interactions: make the withdrawal.
withdrawInternal(streamId, to, amounts[i]);
}

// Increment the for loop iterator.
unchecked {
i += 1;
}
}
}

/// INTERNAL CONSTANT FUNCTIONS ///

/// @dev Checks that the counts of segments match. The counts must be equal and less than or equal to
Expand Down
14 changes: 7 additions & 7 deletions src/interfaces/ISablierV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ interface ISablierV2 {
/// @dev Emits a {Cancel} event.
///
/// Requiremenets:
/// - `streamId` must point to an existing stream.
/// - `streamId` must point to an existent stream.
/// - `msg.sender` must be either the sender or recipient.
/// - The stream must be cancelable.
///
Expand All @@ -138,7 +138,7 @@ interface ISablierV2 {
/// @dev Emits multiple {Cancel} events.
///
/// Requiremenets:
/// - Each stream id in `streamIds` must point to an existing stream.
/// - Each stream id in `streamIds` must point to an existent stream.
/// - `msg.sender` must be either the sender or recipient of every stream.
/// - Each stream must be cancelable.
///
Expand All @@ -154,7 +154,7 @@ interface ISablierV2 {
/// @dev Emits a {Renounce} event.
///
/// Requiremenets:
/// - `streamId` must point to an existing stream.
/// - `streamId` must point to an existent stream.
/// - `msg.sender` must be the sender.
/// - The stream must not be already non-cancelable.
///
Expand All @@ -166,7 +166,7 @@ interface ISablierV2 {
/// @dev Emits a {Withdraw} event.
///
/// Requirements:
/// - `streamId` must point to an existing stream.
/// - `streamId` must point to an existent stream.
/// - `msg.sender` must be either the sender or recipient.
/// - `amount` must not be zero and must not exceed the withdrawable amount.
///
Expand All @@ -181,7 +181,7 @@ interface ISablierV2 {
/// Requirements:
/// - The count of `streamIds` must match the count of `amounts`.
/// - `msg.sender` must be either the sender or recipient of every stream.
/// - Each stream id in `streamIds` must point to an existing stream.
/// - Each stream id in `streamIds` must point to an existent stream.
/// - Each amount in `amounts` must not be zero and must not exceed the withdrawable amount.
///
/// @param streamIds The ids of the streams to withdraw.
Expand All @@ -195,7 +195,7 @@ interface ISablierV2 {
/// Requirements:
/// - `to` must not be the zero address.
/// - The count of `streamIds` must match the count of `amounts`.
/// - Each stream id in `streamIds` must point to an existing stream.
/// - Each stream id in `streamIds` must point to an existent stream.
/// - `msg.sender` must be the recipient of every stream.
/// - Each amount in `amounts` must not be zero and must not exceed the withdrawable amount.
///
Expand All @@ -213,7 +213,7 @@ interface ISablierV2 {
/// @dev Emits a {Withdraw} event.
///
/// Requirements:
/// - `streamId` must point to an existing stream.
/// - `streamId` must point to an existent stream.
/// - `to` must not be the zero address.
/// - `msg.sender` must be the recipient.
/// - `amount` must not be zero and must not exceed the withdrawable amount.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { SablierV2 } from "@sablier/v2-core/SablierV2.sol";
import { SablierV2UnitTest } from "../SablierV2UnitTest.t.sol";

contract AbstractSablierV2 is SablierV2 {
constructor() SablierV2() {
// solhint-disable-previous-line no-empty-blocks
}
constructor() SablierV2() {}

/// CONSTANT FUNCTIONS ///

Expand Down
Loading

0 comments on commit 5841eb2

Please sign in to comment.