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:
parent
2e63b518b7
commit
0fd71cd596
@ -101,6 +101,13 @@ func (m *mockMissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route
|
|||||||
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
||||||
*channeldb.FailureReason, error) {
|
*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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,10 +139,16 @@ func TestRouterPaymentStateMachine(t *testing.T) {
|
|||||||
// respond with a successful payment result.
|
// respond with a successful payment result.
|
||||||
getPaymentResultSuccess = "GetPaymentResult:success"
|
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
|
// router to call the GetPaymentResult method, and we will
|
||||||
// respond with a forwarding error.
|
// respond with a forwarding error, expecting the router to retry.
|
||||||
getPaymentResultFailure = "GetPaymentResult:failure"
|
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
|
// resendPayment is a test step where we manually try to resend
|
||||||
// the same payment, making sure the router responds with an
|
// the same payment, making sure the router responds with an
|
||||||
@ -197,7 +203,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
|
|||||||
sendToSwitchSuccess,
|
sendToSwitchSuccess,
|
||||||
|
|
||||||
// Make the first sent attempt fail.
|
// Make the first sent attempt fail.
|
||||||
getPaymentResultFailure,
|
getPaymentResultTempFailure,
|
||||||
routerFailAttempt,
|
routerFailAttempt,
|
||||||
|
|
||||||
// The router should retry.
|
// The router should retry.
|
||||||
@ -244,7 +250,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
|
|||||||
sendToSwitchSuccess,
|
sendToSwitchSuccess,
|
||||||
|
|
||||||
// Make the first sent attempt fail.
|
// Make the first sent attempt fail.
|
||||||
getPaymentResultFailure,
|
getPaymentResultTempFailure,
|
||||||
routerFailAttempt,
|
routerFailAttempt,
|
||||||
|
|
||||||
// Since there are no more routes to try, the
|
// Since there are no more routes to try, the
|
||||||
@ -343,7 +349,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
|
|||||||
resentPaymentError,
|
resentPaymentError,
|
||||||
|
|
||||||
// Make the first attempt fail.
|
// Make the first attempt fail.
|
||||||
getPaymentResultFailure,
|
getPaymentResultTempFailure,
|
||||||
routerFailAttempt,
|
routerFailAttempt,
|
||||||
|
|
||||||
// Since we have no more routes to try, the
|
// 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
|
// In this state we expect the GetPaymentResult method
|
||||||
// to be called, and we respond with a forwarding
|
// to be called, and we respond with a forwarding
|
||||||
// error, indicating that the router should retry.
|
// error, indicating that the router should retry.
|
||||||
case getPaymentResultFailure:
|
case getPaymentResultTempFailure:
|
||||||
failure := htlcswitch.NewForwardingError(
|
failure := htlcswitch.NewForwardingError(
|
||||||
&lnwire.FailTemporaryChannelFailure{},
|
&lnwire.FailTemporaryChannelFailure{},
|
||||||
1,
|
1,
|
||||||
@ -601,6 +607,24 @@ func TestRouterPaymentStateMachine(t *testing.T) {
|
|||||||
t.Fatalf("unable to get result")
|
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
|
// In this step we manually try to resend the same
|
||||||
// payment, making sure the router responds with an
|
// payment, making sure the router responds with an
|
||||||
// error indicating that it is already in flight.
|
// error indicating that it is already in flight.
|
||||||
|
Loading…
Reference in New Issue
Block a user