Skip to content

Commit

Permalink
test: update deposit, refundableAmountOf and withdrawMax tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg authored and smol-ninja committed May 22, 2024
1 parent 77d6ace commit 6aa9680
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
13 changes: 8 additions & 5 deletions test/integration/deposit/deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ contract Deposit_Integration_Test is Integration_Test {
openEnded.deposit(nullStreamId, DEPOSIT_AMOUNT);
}

function test_RevertGiven_Paused() external whenNotDelegateCalled givenNotNull {
expectRevertPaused();
openEnded.deposit(defaultStreamId, DEPOSIT_AMOUNT);
}

function test_RevertWhen_DepositAmountZero() external whenNotDelegateCalled givenNotNull givenNotPaused {
vm.expectRevert(Errors.SablierV2OpenEnded_DepositAmountZero.selector);
openEnded.deposit(defaultStreamId, 0);
}

function test_Deposit_Paused() external whenNotDelegateCalled givenNotNull {
openEnded.deposit(defaultStreamId, DEPOSIT_AMOUNT);

uint128 actualStreamBalance = openEnded.getBalance(defaultStreamId);
uint128 expectedStreamBalance = DEPOSIT_AMOUNT;
assertEq(actualStreamBalance, expectedStreamBalance, "stream balance");
}

function test_Deposit_AssetMissingReturnValue_AssetNot18Decimals()
external
whenNotDelegateCalled
Expand Down
10 changes: 5 additions & 5 deletions test/integration/deposit/deposit.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ deposit.t.sol
β”œβ”€β”€ given the id references a null stream
β”‚ └── it should revert
└── given the id does not reference a null stream
β”œβ”€β”€ given the id references a paused stream
β”‚ └── it should revert
└── given the id does not reference a paused stream
β”œβ”€β”€ when the deposit amount is zero
β”œβ”€β”€ when the deposit amount is zero
β”‚ └── it should deposit on the stream
└── when the deposit amount is not zero
β”œβ”€β”€ given the id references a paused stream
β”‚ └── it should revert
└── when the deposit amount is not zero
└── given the id does not reference a paused stream
β”œβ”€β”€ when the asset misses the ERC-20 return
β”‚ └── it should make the deposit
└── when the asset does not miss the ERC-20 return value
Expand Down
16 changes: 11 additions & 5 deletions test/integration/refundable-amount-of/refundableAmountOf.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ contract RefundableAmountOf_Integration_Test is Integration_Test {
openEnded.refundableAmountOf(nullStreamId);
}

function test_RevertGiven_Paused() external givenNotNull {
expectRevertPaused();
openEnded.refundableAmountOf(defaultStreamId);
}

function test_RefundableAmountOf_BalanceZero() external view givenNotNull givenNotPaused {
uint128 refundableAmount = openEnded.refundableAmountOf(defaultStreamId);
assertEq(refundableAmount, 0, "refundable amount");
}

function test_RefundableAmountOf_Paused() external givenNotNull {
defaultDeposit();
openEnded.refundableAmountOf(defaultStreamId);

vm.warp({ newTimestamp: WARP_ONE_MONTH });
openEnded.pause(defaultStreamId);

uint128 refundableAmount = openEnded.refundableAmountOf(defaultStreamId);
assertEq(refundableAmount, ONE_MONTH_REFUNDABLE_AMOUNT, "refundable amount");
}

function test_RefundableAmountOf_BalanceLessThanOrEqualStreamedAmount() external givenNotNull givenNotPaused {
uint128 depositAmount = 1e18;
openEnded.deposit(defaultStreamId, depositAmount);
Expand Down
12 changes: 6 additions & 6 deletions test/integration/refundable-amount-of/refundableAmountOf.tree
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ refundableAmountOf.t.sol
β”œβ”€β”€ given the id references a null stream
β”‚ └── it should revert
└── given the id does not reference a null stream
β”œβ”€β”€ given the id references a paused stream
β”‚ └── it should revert
└── given the id does not reference a paused stream
β”œβ”€β”€ given the stream balance is zero
β”‚ └── it should return zero
└── given the stream balance is not zero
β”œβ”€β”€ given the stream balance is zero
β”‚ └── it should return zero
└── given the stream balance is not zero
β”œβ”€β”€ given the id references a paused stream
β”‚ └── it should return the correct refundable amount
└── given the id does not reference a paused stream
β”œβ”€β”€ given the stream balance is less than or equal to the streamed amount
β”‚ └── it should return zero
└── given the stream balance is greater than the streamed amount
Expand Down
20 changes: 7 additions & 13 deletions test/integration/withdraw-max/withdrawMax.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,25 @@ contract WithdrawMax_Integration_Concrete_Test is Integration_Test {
function test_WithdrawMax_Paused() external {
openEnded.pause(defaultStreamId);

uint128 beforeStreamBalance = openEnded.getBalance(defaultStreamId);
uint128 beforeRemainingAmount = openEnded.getRemainingAmount(defaultStreamId);

vm.expectEmit({ emitter: address(dai) });
emit IERC20.Transfer({
from: address(openEnded),
to: users.recipient,
value: normalizeTransferAmount(defaultStreamId, beforeRemainingAmount)
});
emit IERC20.Transfer({ from: address(openEnded), to: users.recipient, value: ONE_MONTH_STREAMED_AMOUNT });

vm.expectEmit({ emitter: address(openEnded) });
emit WithdrawFromOpenEndedStream({
streamId: defaultStreamId,
to: users.recipient,
asset: dai,
withdrawnAmount: beforeRemainingAmount
withdrawnAmount: ONE_MONTH_STREAMED_AMOUNT
});

openEnded.withdrawMax(defaultStreamId, users.recipient);

uint128 afterStreamBalance = openEnded.getBalance(defaultStreamId);
uint128 afterRemainingAmount = openEnded.getRemainingAmount(defaultStreamId);
uint128 actualStreamBalance = openEnded.getBalance(defaultStreamId);
uint128 expectedStreamBalance = DEPOSIT_AMOUNT - ONE_MONTH_STREAMED_AMOUNT;
assertEq(actualStreamBalance, expectedStreamBalance, "stream balance");

assertEq(beforeStreamBalance, afterStreamBalance, "stream balance should not change");
assertEq(afterRemainingAmount, 0, "remaining amount should be 0");
uint128 actualRemainingAmount = openEnded.getRemainingAmount(defaultStreamId);
assertEq(actualRemainingAmount, 0, "remaining amount");
assertEq(openEnded.getLastTimeUpdate(defaultStreamId), WARP_ONE_MONTH, "last time update not updated");
}

Expand Down
5 changes: 3 additions & 2 deletions test/integration/withdraw-max/withdrawMax.tree
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ withdrawMax.t.sol
β”‚ └── it should withdraw the remaining amount
└── given the end time is not paused
β”œβ”€β”€ it should make the max withdrawal
β”œβ”€β”€ it should update the time
β”œβ”€β”€ it should set the remaining amount to zero
β”œβ”€β”€ it should update the stream balance
β”œβ”€β”€ it should update the time
β”œβ”€β”€ it should perform the ERC-20 transfer
└── it should emit a {Transfer} and {WithdrawFromOpenEndedStream} event
β”œβ”€β”€ it should emit a {Transfer} and {WithdrawFromOpenEndedStream} event
└── it should emit a {MetadataUpdated} event

0 comments on commit 6aa9680

Please sign in to comment.