-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from metadock/tests/withdraw-stream
Implement `withdrawLinearStream` and `withdrawTranchedStream` integration tests
- Loading branch information
Showing
8 changed files
with
139 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { WithdrawLinearStream_Integration_Shared_Test } from "../../../shared/withdrawLinearStream.t.sol"; | ||
|
||
contract WithdrawLinearStream_Integration_Concret_Test is WithdrawLinearStream_Integration_Shared_Test { | ||
function setUp() public virtual override { | ||
WithdrawLinearStream_Integration_Shared_Test.setUp(); | ||
} | ||
|
||
function test_WithdrawLinearStream() external givenPaymentMethodLinearStream givenInvoiceStatusOngoing { | ||
// Set current invoice as a linear stream-based one | ||
uint256 invoiceId = 3; | ||
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 = sablierV2LockupLinear.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.withdrawLinearStream({ streamId: streamId, to: users.eve }); | ||
|
||
// Assert the current and expected USDT balance of Eve | ||
assertEq(balanceOfBefore + maxWithdrawableAmount, usdt.balanceOf(users.eve)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
test/integration/concrete/invoice-module/withdraw-linear-stream/withdrawLinearStream.tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
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 |
44 changes: 44 additions & 0 deletions
44
...integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../integration/concrete/invoice-module/withdraw-tranched-stream/withdrawTranchedStream.tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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 WithdrawLinearStream_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() { | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
_; | ||
} | ||
} |