From 649ee875fd226a4399a60c0037fbf2ce8955ffeb Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 24 May 2019 12:34:46 +0200 Subject: [PATCH] routing/router_test: add test case for ForwardingError on SendHTLC --- routing/router_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/routing/router_test.go b/routing/router_test.go index d1cafddd..9dd2e85e 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -2601,6 +2601,12 @@ func TestRouterPaymentStateMachine(t *testing.T) { // attempt was successfully forwarded. sendToSwitchSuccess = "SendToSwitch:success" + // sendToSwitchResultFailure is a step where we expect the + // router to send the payment attempt to the switch, and we + // will respond with a forwarding error. This can happen when + // forwarding fail on our local links. + sendToSwitchResultFailure = "SendToSwitch:failure" + // getPaymentResultSuccess is a test step where we expect the // router to call the GetPaymentResult method, and we will // respond with a successful payment result. @@ -2677,6 +2683,28 @@ func TestRouterPaymentStateMachine(t *testing.T) { }, routes: []*route.Route{rt, rt}, }, + { + // A payment flow with a forwarding failure first time + // sending to the switch, but that succeeds on the + // second attempt. + steps: []string{ + routerInitPayment, + routerRegisterAttempt, + + // Make the first sent attempt fail. + sendToSwitchResultFailure, + + // The router should retry. + routerRegisterAttempt, + sendToSwitchSuccess, + + // Make the second sent attempt succeed. + getPaymentResultSuccess, + routerSuccess, + paymentSuccess, + }, + routes: []*route.Route{rt, rt}, + }, { // A payment that fails on the first attempt, and has // only one route available to try. It will therefore @@ -2982,6 +3010,18 @@ func TestRouterPaymentStateMachine(t *testing.T) { t.Fatalf("unable to send result") } + // In this step we expect the SendToSwitch method to be + // called, and we respond with a forwarding error + case sendToSwitchResultFailure: + select { + case sendResult <- &htlcswitch.ForwardingError{ + ErrorSource: errSource, + FailureMessage: &lnwire.FailTemporaryChannelFailure{}, + }: + case <-time.After(1 * time.Second): + t.Fatalf("unable to send result") + } + // In this step we expect the GetPaymentResult method // to be called, and we respond with the preimage to // complete the payment.