Skip to content

Commit

Permalink
fix(invoice-module): linear/tranched stream-based invoice status on '…
Browse files Browse the repository at this point in the history
…payInvoice' exec
  • Loading branch information
gabrielstoica committed Jul 18, 2024
1 parent d33df80 commit eefae04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/modules/invoice-module/InvoiceModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ contract InvoiceModule is IInvoiceModule, StreamManager {

// Handle the payment workflow depending on the payment method type
if (invoice.payment.method == Types.Method.Transfer) {
// Effects: pay the invoice and update its status to `Paid` or `Ongoing` depending on the payment type
_payByTransfer(id, invoice);
} else {
uint256 streamId;
Expand All @@ -193,8 +194,9 @@ contract InvoiceModule is IInvoiceModule, StreamManager {
streamId = _payByLinearStream(invoice);
} else streamId = _payByTranchedStream(invoice);

// Effects: update the status of the invoice and stream ID
_invoices[id].status = Types.Status.Paid;
// Effects: update the status of the invoice to `Ongoing` and the stream ID
// if dealing with a linear or tranched-based invoice
_invoices[id].status = Types.Status.Ongoing;
_invoices[id].payment.streamId = streamId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ contract PayInvoice_Integration_Concret_Test is PayInvoice_Integration_Shared_Te
emit Events.InvoicePaid({
id: invoiceId,
payer: users.bob,
status: Types.Status.Paid,
status: Types.Status.Ongoing,
payment: Types.Payment({
method: invoices[invoiceId].payment.method,
recurrence: invoices[invoiceId].payment.recurrence,
Expand All @@ -283,7 +283,7 @@ contract PayInvoice_Integration_Concret_Test is PayInvoice_Integration_Shared_Te

// Assert the actual and the expected state of the invoice
Types.Invoice memory invoice = invoiceModule.getInvoice({ id: invoiceId });
assertEq(uint8(invoice.status), uint8(Types.Status.Paid));
assertEq(uint8(invoice.status), uint8(Types.Status.Ongoing));
assertEq(invoice.payment.streamId, 1);
assertEq(invoice.payment.paymentsLeft, 0);

Expand Down Expand Up @@ -319,7 +319,7 @@ contract PayInvoice_Integration_Concret_Test is PayInvoice_Integration_Shared_Te
emit Events.InvoicePaid({
id: invoiceId,
payer: users.bob,
status: Types.Status.Paid,
status: Types.Status.Ongoing,
payment: Types.Payment({
method: invoices[invoiceId].payment.method,
recurrence: invoices[invoiceId].payment.recurrence,
Expand All @@ -335,7 +335,7 @@ contract PayInvoice_Integration_Concret_Test is PayInvoice_Integration_Shared_Te

// Assert the actual and the expected state of the invoice
Types.Invoice memory invoice = invoiceModule.getInvoice({ id: invoiceId });
assertEq(uint8(invoice.status), uint8(Types.Status.Paid));
assertEq(uint8(invoice.status), uint8(Types.Status.Ongoing));
assertEq(invoice.payment.streamId, 1);
assertEq(invoice.payment.paymentsLeft, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ payInvoice.t.sol
│ └── it should emit an {InvoicePaid} event
├── given the payment method is linear stream
│ ├── it should create a Sablier v2 linear stream
│ ├── it should update the invoice status to Ongoing
│ ├── it should update the invoice stream ID
│ └── it should emit an {InvoicePaid} event
└── given the payment method is tranched stream
├── it should create a Sablier v2 tranched stream
├── it should update the invoice status to Ongoing
├── it should update the invoice stream ID
└── it should emit an {InvoicePaid} event

0 comments on commit eefae04

Please sign in to comment.