From efcd7fe703d1ff7de4d60cf612d817092759e2a7 Mon Sep 17 00:00:00 2001 From: gabrielstoica Date: Wed, 14 Aug 2024 14:36:24 +0300 Subject: [PATCH] test: merge linear and tranched withdraw integration concrete tests --- .../withdrawLinearStream.tree | 4 -- .../withdrawStream.sol} | 40 ++++++++++++++++- .../withdraw-stream/withdrawStream.tree | 7 +++ .../withdrawTranchedStream.t.sol | 45 ------------------- .../withdrawTranchedStream.tree | 4 -- 5 files changed, 45 insertions(+), 55 deletions(-) delete mode 100644 test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.tree rename test/integration/concrete/invoice-module/{withdraw-linear-stream/withdrawLinearStream.t.sol => withdraw-stream/withdrawStream.sol} (50%) create mode 100644 test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.tree delete mode 100644 test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol delete mode 100644 test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree diff --git a/test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.tree b/test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.tree deleted file mode 100644 index c7a19fb8..00000000 --- a/test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.tree +++ /dev/null @@ -1,4 +0,0 @@ -withdrawLinearStream.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 \ No newline at end of file diff --git a/test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.t.sol b/test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.sol similarity index 50% rename from test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.t.sol rename to test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.sol index e6522042..bbbc2c84 100644 --- a/test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.t.sol +++ b/test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.sol @@ -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; @@ -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 }); @@ -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)); + } } diff --git a/test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.tree b/test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.tree new file mode 100644 index 00000000..e5dc7ad8 --- /dev/null +++ b/test/integration/concrete/invoice-module/withdraw-stream/withdrawStream.tree @@ -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 \ No newline at end of file diff --git a/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol b/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol deleted file mode 100644 index 02759f32..00000000 --- a/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -import { WithdrawTranchedStream_Integration_Shared_Test } from "../../../shared/withdrawTranchedStream.t.sol"; -import { Types } from "./../../../../../src/modules/invoice-module/libraries/Types.sol"; - -contract WithdrawTranchedStream_Integration_Concret_Test is WithdrawTranchedStream_Integration_Shared_Test { - function setUp() public virtual override { - WithdrawTranchedStream_Integration_Shared_Test.setUp(); - } - - function test_WithdrawTranchedStream() 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 = sablierV2LockupTranched.withdrawableAmountOf(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.withdrawStream({ streamType: Types.Method.TranchedStream, streamId: streamId, to: users.eve }); - - // Assert the current and expected USDT balance of Eve - assertEq(balanceOfBefore + maxWithdrawableAmount, usdt.balanceOf(users.eve)); - } -} diff --git a/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree b/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree deleted file mode 100644 index 423bc31d..00000000 --- a/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree +++ /dev/null @@ -1,4 +0,0 @@ -withdrawTranchedStream.t.sol -└── given the payment method is tranched stream - └── given the invoice status is Ongoing - └── it should allow the invoice recipient to withdraw from the stream \ No newline at end of file