routing/payment_lifecycle_test: add step for terminal failure

And modify the MissionControl mock to return a non-nil failure reason in
this case.
This commit is contained in:
Johan T. Halseth 2020-04-01 00:13:26 +02:00
parent 2e63b518b7
commit 0fd71cd596
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 38 additions and 7 deletions

@ -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
}

@ -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.