-
Notifications
You must be signed in to change notification settings - Fork 25
fix(restore): show new-invoice prompt for failed payout in settled-hold-invoice #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndreaDiazCorreia
wants to merge
2
commits into
main
Choose a base branch
from
feat/restore-failed-payout-invoice-prompt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,119 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mostro_mobile/data/models.dart'; | ||
| import 'package:mostro_mobile/data/enums.dart'; | ||
| import 'package:mostro_mobile/features/order/models/order_state.dart'; | ||
| import 'package:mostro_mobile/features/restore/restore_manager.dart'; | ||
|
|
||
| /// Regression coverage for issue #615: restoring an order that Mostro reports | ||
| /// as `settled-hold-invoice` after a failed Lightning payout must land on the | ||
| /// new-invoice prompt (`add-invoice` + `payment-failed`), not "paying sats" | ||
| /// (`released` + `settled-hold-invoice`). | ||
|
|
||
| MostroMessage<Order> _msg(Action action, {int? timestamp}) => | ||
| MostroMessage<Order>( | ||
| action: action, | ||
| id: 'order-1', | ||
| timestamp: timestamp, | ||
| payload: const Order( | ||
| id: 'order-1', | ||
| kind: OrderType.buy, | ||
| status: Status.settledHoldInvoice, | ||
| amount: 500, | ||
| fiatCode: 'USD', | ||
| fiatAmount: 50, | ||
| paymentMethod: 'Cash', | ||
| ), | ||
| ); | ||
|
|
||
| /// Replays a sequence of actions onto a fresh order state, mirroring how | ||
| /// RestoreService.restore() applies snapshot-derived messages via | ||
| /// OrderNotifier.updateStateFromMessage(). | ||
| OrderState _replay(List<Action> actions) { | ||
| OrderState state = OrderState( | ||
| action: Action.newOrder, | ||
| status: Status.pending, | ||
| order: null, | ||
| ); | ||
| for (final action in actions) { | ||
| state = state.updateWith(_msg(action)); | ||
| } | ||
| return state; | ||
| } | ||
|
|
||
| void main() { | ||
| group('restoreHasFailedPayoutSignal', () { | ||
| test('returns false for empty history', () { | ||
| expect(restoreHasFailedPayoutSignal([]), isFalse); | ||
| }); | ||
|
|
||
| test('returns true when payment-failed is present', () { | ||
| expect( | ||
| restoreHasFailedPayoutSignal([_msg(Action.paymentFailed, timestamp: 1)]), | ||
| isTrue, | ||
| ); | ||
| }); | ||
|
|
||
| // Per mostro#754 the daemon re-sends ONLY a bare `add-invoice` (no | ||
| // `payment-failed`, no `released`) for a failed payout, and restore clears | ||
| // storage first, so a lone post-clear `add-invoice` is the failed-payout | ||
| // prompt and must be honored. Weakening this to require `payment-failed` or | ||
| // a preceding release would reintroduce the money-at-risk bug in #615. | ||
| test('lone re-sent add-invoice is a failed-payout signal (mostro#754)', () { | ||
| expect( | ||
| restoreHasFailedPayoutSignal([_msg(Action.addInvoice, timestamp: 1)]), | ||
| isTrue, | ||
| ); | ||
| }); | ||
|
|
||
| test('returns true when add-invoice arrives after the hold was released', | ||
| () { | ||
| expect( | ||
| restoreHasFailedPayoutSignal([ | ||
| _msg(Action.released, timestamp: 1), | ||
| _msg(Action.addInvoice, timestamp: 2), | ||
| ]), | ||
| isTrue, | ||
| ); | ||
| }); | ||
|
|
||
| test('returns false for an early add-invoice that precedes the release', () { | ||
| // Happy path where the daemon re-sends full history: the only add-invoice | ||
| // is the early waiting-buyer-invoice one, before the release. | ||
| expect( | ||
| restoreHasFailedPayoutSignal([ | ||
| _msg(Action.addInvoice, timestamp: 1), | ||
| _msg(Action.released, timestamp: 2), | ||
| ]), | ||
| isFalse, | ||
| ); | ||
| }); | ||
|
|
||
| test('returns false for a settled order with no failed-payout signal', () { | ||
| expect( | ||
| restoreHasFailedPayoutSignal([ | ||
| _msg(Action.holdInvoicePaymentSettled, timestamp: 1), | ||
| ]), | ||
| isFalse, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| group('restore state rebuild for settled-hold-invoice + buyer', () { | ||
| test( | ||
| 'failed payout replays to payment-failed + add-invoice (new-invoice prompt)', | ||
| () { | ||
| final state = _replay([Action.paymentFailed, Action.addInvoice]); | ||
|
|
||
| expect(state.status, equals(Status.paymentFailed)); | ||
| expect(state.action, equals(Action.addInvoice)); | ||
| }); | ||
|
|
||
| test('happy path replays to settled-hold-invoice + released (paying sats)', | ||
| () { | ||
| final state = _replay([Action.released]); | ||
|
|
||
| expect(state.status, equals(Status.settledHoldInvoice)); | ||
| expect(state.action, equals(Action.released)); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.