From b0bf41c1cfc52dcb975c6e6527754df06f412277 Mon Sep 17 00:00:00 2001 From: gabrielstoica Date: Tue, 23 Jul 2024 18:38:19 +0300 Subject: [PATCH] test: add integration concrete tests for 'withdrawTranchedStream' --- .../withdrawTranchedStream.t.sol | 44 +++++++++++++++++++ .../withdrawTranchedStream.tree | 4 ++ .../shared/withdrawTranchedStream.t.sol | 18 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol create mode 100644 test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree create mode 100644 test/integration/shared/withdrawTranchedStream.t.sol 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 new file mode 100644 index 00000000..5718225e --- /dev/null +++ b/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.26; + +import { WithdrawTranchedStream_Integration_Shared_Test } from "../../../shared/withdrawTranchedStream.t.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 = 4; + 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.withdrawTranchedStream({ 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 new file mode 100644 index 00000000..423bc31d --- /dev/null +++ b/test/integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree @@ -0,0 +1,4 @@ +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 diff --git a/test/integration/shared/withdrawTranchedStream.t.sol b/test/integration/shared/withdrawTranchedStream.t.sol new file mode 100644 index 00000000..128535b4 --- /dev/null +++ b/test/integration/shared/withdrawTranchedStream.t.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.26; + +import { Integration_Test } from "../Integration.t.sol"; +import { PayInvoice_Integration_Shared_Test } from "./payInvoice.t.sol"; + +abstract contract WithdrawTranchedStream_Integration_Shared_Test is + Integration_Test, + PayInvoice_Integration_Shared_Test +{ + function setUp() public virtual override(Integration_Test, PayInvoice_Integration_Shared_Test) { + PayInvoice_Integration_Shared_Test.setUp(); + } + + modifier givenInvoiceStatusOngoing() { + _; + } +}