From 0fd71cd5965171a8925ebcdeb139868a69d5c3e0 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 1 Apr 2020 00:13:26 +0200 Subject: [PATCH] routing/payment_lifecycle_test: add step for terminal failure And modify the MissionControl mock to return a non-nil failure reason in this case. --- routing/mock_test.go | 7 ++++++ routing/payment_lifecycle_test.go | 38 +++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/routing/mock_test.go b/routing/mock_test.go index 594c1483..36523a97 100644 --- a/routing/mock_test.go +++ b/routing/mock_test.go @@ -101,6 +101,13 @@ func (m *mockMissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route failureSourceIdx *int, failure lnwire.FailureMessage) ( *channeldb.FailureReason, error) { + // Report a permanent failure if this is an error caused + // by incorrect details. + if failure.Code() == lnwire.CodeIncorrectOrUnknownPaymentDetails { + reason := channeldb.FailureReasonPaymentDetails + return &reason, nil + } + return nil, nil } diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go index 4c371b06..7e492ea7 100644 --- a/routing/payment_lifecycle_test.go +++ b/routing/payment_lifecycle_test.go @@ -139,10 +139,16 @@ func TestRouterPaymentStateMachine(t *testing.T) { // respond with a successful payment result. getPaymentResultSuccess = "GetPaymentResult:success" - // getPaymentResultFailure is a test step where we expect the + // getPaymentResultTempFailure is a test step where we expect the // router to call the GetPaymentResult method, and we will - // respond with a forwarding error. - getPaymentResultFailure = "GetPaymentResult:failure" + // respond with a forwarding error, expecting the router to retry. + getPaymentResultTempFailure = "GetPaymentResult:temp-failure" + + // getPaymentResultTerminalFailure is a test step where we + // expect the router to call the GetPaymentResult method, and + // we will respond with a terminal error, expecting the router + // to stop making payment attempts. + getPaymentResultTerminalFailure = "GetPaymentResult:terminal-failure" // resendPayment is a test step where we manually try to resend // the same payment, making sure the router responds with an @@ -197,7 +203,7 @@ func TestRouterPaymentStateMachine(t *testing.T) { sendToSwitchSuccess, // Make the first sent attempt fail. - getPaymentResultFailure, + getPaymentResultTempFailure, routerFailAttempt, // The router should retry. @@ -244,7 +250,7 @@ func TestRouterPaymentStateMachine(t *testing.T) { sendToSwitchSuccess, // Make the first sent attempt fail. - getPaymentResultFailure, + getPaymentResultTempFailure, routerFailAttempt, // Since there are no more routes to try, the @@ -343,7 +349,7 @@ func TestRouterPaymentStateMachine(t *testing.T) { resentPaymentError, // Make the first attempt fail. - getPaymentResultFailure, + getPaymentResultTempFailure, routerFailAttempt, // Since we have no more routes to try, the @@ -587,7 +593,7 @@ func TestRouterPaymentStateMachine(t *testing.T) { // In this state we expect the GetPaymentResult method // to be called, and we respond with a forwarding // error, indicating that the router should retry. - case getPaymentResultFailure: + case getPaymentResultTempFailure: failure := htlcswitch.NewForwardingError( &lnwire.FailTemporaryChannelFailure{}, 1, @@ -601,6 +607,24 @@ func TestRouterPaymentStateMachine(t *testing.T) { t.Fatalf("unable to get result") } + // In this state we expect the router to call the + // GetPaymentResult method, and we will respond with a + // terminal error, indiating the router should stop + // making payment attempts. + case getPaymentResultTerminalFailure: + failure := htlcswitch.NewForwardingError( + &lnwire.FailIncorrectDetails{}, + 1, + ) + + select { + case getPaymentResult <- &htlcswitch.PaymentResult{ + Error: failure, + }: + case <-time.After(1 * time.Second): + t.Fatalf("unable to get result") + } + // In this step we manually try to resend the same // payment, making sure the router responds with an // error indicating that it is already in flight.