Skip to content

Commit

Permalink
test: add integration concrete tests for 'withdrawTranchedStream'
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielstoica committed Jul 23, 2024
1 parent 872bad2 commit b0bf41c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions test/integration/shared/withdrawTranchedStream.t.sol
Original file line number Diff line number Diff line change
@@ -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() {
_;
}
}

0 comments on commit b0bf41c

Please sign in to comment.