Skip to content

Commit

Permalink
test: merge linear and tranched withdraw integration concrete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielstoica committed Aug 14, 2024
1 parent e7877ef commit efcd7fe
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 55 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract WithdrawLinearStream_Integration_Concret_Test is WithdrawLinearStream_I
WithdrawLinearStream_Integration_Shared_Test.setUp();
}

function test_WithdrawLinearStream() external givenPaymentMethodLinearStream givenInvoiceStatusOngoing {
function test_WithdrawStream_LinearStream() external givenPaymentMethodLinearStream givenInvoiceStatusOngoing {
// Set current invoice as a linear stream-based one
uint256 invoiceId = 4;
uint256 streamId = 1;
Expand All @@ -31,7 +31,8 @@ contract WithdrawLinearStream_Integration_Concret_Test is WithdrawLinearStream_I
uint256 balanceOfBefore = usdt.balanceOf(users.eve);

// Get the maximum withdrawable amount from the stream
uint128 maxWithdrawableAmount = sablierV2LockupLinear.withdrawableAmountOf(streamId);
uint128 maxWithdrawableAmount =
invoiceModule.withdrawableAmountOf({ streamType: Types.Method.LinearStream, streamId: streamId });

// Make Eve the caller in this test suite as she's the recipient of the invoice
vm.startPrank({ msgSender: users.eve });
Expand All @@ -42,4 +43,39 @@ contract WithdrawLinearStream_Integration_Concret_Test is WithdrawLinearStream_I
// Assert the current and expected USDT balance of Eve
assertEq(balanceOfBefore + maxWithdrawableAmount, usdt.balanceOf(users.eve));
}

function test_WithdrawStream_TranchedStream() external givenPaymentMethodTranchedStream givenInvoiceStatusOngoing {
// Set current invoice as a tranched stream-based one
uint256 invoiceId = 5;
uint256 streamId = 1;

// The invoice must be paid for its status to be updated to `Ongoing`
// Make Bob the payer of the invoice (also Bob will be the initial stream sender)
vm.startPrank({ msgSender: users.bob });

// Approve the {InvoiceModule} to transfer the USDT tokens on Bob's behalf
usdt.approve({ spender: address(invoiceModule), amount: invoices[invoiceId].payment.amount });

// Pay the invoice first (status will be updated to `Ongoing`)
invoiceModule.payInvoice{ value: invoices[invoiceId].payment.amount }({ id: invoiceId });

// Advance the timestamp by 3 weeks to simulate the withdrawal
vm.warp(block.timestamp + 3 weeks);

// Store Eve's balance before withdrawing the USDT tokens
uint256 balanceOfBefore = usdt.balanceOf(users.eve);

// Get the maximum withdrawable amount from the stream
uint128 maxWithdrawableAmount =
invoiceModule.withdrawableAmountOf({ streamType: Types.Method.TranchedStream, streamId: streamId });

// Make Eve the caller in this test suite as she's the recipient of the invoice
vm.startPrank({ msgSender: users.eve });

// Run the test
invoiceModule.withdrawInvoiceStream(invoiceId);

// Assert the current and expected USDT balance of Eve
assertEq(balanceOfBefore + maxWithdrawableAmount, usdt.balanceOf(users.eve));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
withdrawStream.t.sol
├── given the payment method is linear stream
│ └── given the invoice status is Ongoing
│ └── it should allow the invoice recipient to withdraw from the stream
└── given the payment method is tranched stream
└── given the invoice status is Ongoing
└── it should allow the invoice recipient to withdraw from the stream

This file was deleted.

This file was deleted.

0 comments on commit efcd7fe

Please sign in to comment.