Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/cancel to pause #113

Merged
merged 12 commits into from
May 24, 2024
Prev Previous commit
Next Next commit
test: update deposit, refundableAmountOf and withdrawMax tests
  • Loading branch information
andreivladbrg authored and smol-ninja committed May 22, 2024
commit 6aa96804f76115a4fecb29dcad3770ff9c8daa98
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