routing: mark payment as failed when no route can be found
This commit is contained in:
2 files changed
+32
-90
No files matched your search
@@ -419,13 +419,8 @@ func TestRequestRouteHandleCriticalErr(t *testing.T) {
|
||||
func TestRequestRouteHandleNoRouteErr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
p := createTestPaymentLifecycle()
|
||||
|
||||
// Create a mock payment session.
|
||||
paySession := &mockPaymentSession{}
|
||||
|
||||
// Mount the mocked payment session.
|
||||
p.paySession = paySession
|
||||
// Create a paymentLifecycle with mockers.
|
||||
p, m := newTestPaymentLifecycle(t)
|
||||
|
||||
// Create a dummy payment state.
|
||||
ps := &channeldb.MPPaymentState{
|
||||
@@ -437,68 +432,22 @@ func TestRequestRouteHandleNoRouteErr(t *testing.T) {
|
||||
// Mock remainingFees to be 1.
|
||||
p.feeLimit = ps.FeesPaid + 1
|
||||
|
||||
// Mock the paySession's `RequestRoute` method to return an error.
|
||||
paySession.On("RequestRoute",
|
||||
// Mock the paySession's `RequestRoute` method to return a NoRouteErr
|
||||
// type.
|
||||
m.paySession.On("RequestRoute",
|
||||
mock.Anything, mock.Anything, mock.Anything, mock.Anything,
|
||||
).Return(nil, errNoTlvPayload)
|
||||
|
||||
// The payment should be failed with reason no route.
|
||||
m.control.On("FailPayment",
|
||||
p.identifier, channeldb.FailureReasonNoRoute,
|
||||
).Return(nil).Once()
|
||||
|
||||
result, err := p.requestRoute(ps)
|
||||
|
||||
// Expect no error is returned since it's not critical.
|
||||
require.NoError(t, err, "expected no error")
|
||||
require.Nil(t, result, "expected no route returned")
|
||||
|
||||
// Assert that `RequestRoute` is called as expected.
|
||||
paySession.AssertExpectations(t)
|
||||
}
|
||||
|
||||
// TestRequestRouteFailPaymentSucceed checks that `requestRoute` fails the
|
||||
// payment when received an `noRouteError` returned from payment session while
|
||||
// it has no inflight attempts.
|
||||
func TestRequestRouteFailPaymentSucceed(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
p := createTestPaymentLifecycle()
|
||||
|
||||
// Create a mock payment session.
|
||||
paySession := &mockPaymentSession{}
|
||||
|
||||
// Mock the control tower's `FailPayment` method.
|
||||
ct := &mockControlTower{}
|
||||
ct.On("FailPayment",
|
||||
p.identifier, errNoTlvPayload.FailureReason(),
|
||||
).Return(nil)
|
||||
|
||||
// Mount the mocked control tower and payment session.
|
||||
p.router.cfg.Control = ct
|
||||
p.paySession = paySession
|
||||
|
||||
// Create a dummy payment state with zero inflight attempts.
|
||||
ps := &channeldb.MPPaymentState{
|
||||
NumAttemptsInFlight: 0,
|
||||
RemainingAmt: 1,
|
||||
FeesPaid: 100,
|
||||
}
|
||||
|
||||
// Mock remainingFees to be 1.
|
||||
p.feeLimit = ps.FeesPaid + 1
|
||||
|
||||
// Mock the paySession's `RequestRoute` method to return an error.
|
||||
paySession.On("RequestRoute",
|
||||
mock.Anything, mock.Anything, mock.Anything, mock.Anything,
|
||||
).Return(nil, errNoTlvPayload)
|
||||
|
||||
result, err := p.requestRoute(ps)
|
||||
|
||||
// Expect no error is returned since it's not critical.
|
||||
require.NoError(t, err, "expected no error")
|
||||
require.Nil(t, result, "expected no route returned")
|
||||
|
||||
// Assert that `RequestRoute` is called as expected.
|
||||
paySession.AssertExpectations(t)
|
||||
|
||||
// Assert that `FailPayment` is called as expected.
|
||||
ct.AssertExpectations(t)
|
||||
}
|
||||
|
||||
// TestRequestRouteFailPaymentError checks that `requestRoute` returns the
|
||||
|
||||
Reference in new issue
Block a user