From 888af51ab4bec3f0718ca2d3e82e9afda990ba24 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 24 Mar 2021 19:53:26 -0700 Subject: [PATCH] lntest: make buildRoute method on mppTestContext This will be reused by the amp itest. --- lntest/itest/lnd_mpp_test.go | 63 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/lntest/itest/lnd_mpp_test.go b/lntest/itest/lnd_mpp_test.go index 7ccca9e4..0113a8fa 100644 --- a/lntest/itest/lnd_mpp_test.go +++ b/lntest/itest/lnd_mpp_test.go @@ -74,36 +74,6 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) { payAddr := decodeResp.PaymentAddr - // Helper function for Alice to build a route from pubkeys. - buildRoute := func(amt btcutil.Amount, hops []*lntest.HarnessNode) ( - *lnrpc.Route, error) { - - rpcHops := make([][]byte, 0, len(hops)) - for _, hop := range hops { - k := hop.PubKeyStr - pubkey, err := route.NewVertexFromStr(k) - if err != nil { - return nil, fmt.Errorf("error parsing %v: %v", - k, err) - } - rpcHops = append(rpcHops, pubkey[:]) - } - - req := &routerrpc.BuildRouteRequest{ - AmtMsat: int64(amt * 1000), - FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta, - HopPubkeys: rpcHops, - } - - ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) - routeResp, err := net.Alice.RouterClient.BuildRoute(ctxt, req) - if err != nil { - return nil, err - } - - return routeResp.Route, nil - } - // We'll send shards along three routes from Alice. sendRoutes := [][]*lntest.HarnessNode{ {ctx.carol, ctx.bob}, @@ -114,7 +84,7 @@ func testSendToRouteMultiPath(net *lntest.NetworkHarness, t *harnessTest) { responses := make(chan *lnrpc.HTLCAttempt, len(sendRoutes)) for _, hops := range sendRoutes { // Build a route for the specified hops. - r, err := buildRoute(shardAmt, hops) + r, err := ctx.buildRoute(ctxb, shardAmt, net.Alice, hops) if err != nil { t.Fatalf("unable to build route: %v", err) } @@ -394,3 +364,34 @@ func (c *mppTestContext) waitForChannels() { } } } + +// Helper function for Alice to build a route from pubkeys. +func (c *mppTestContext) buildRoute(ctxb context.Context, amt btcutil.Amount, + sender *lntest.HarnessNode, hops []*lntest.HarnessNode) (*lnrpc.Route, + error) { + + rpcHops := make([][]byte, 0, len(hops)) + for _, hop := range hops { + k := hop.PubKeyStr + pubkey, err := route.NewVertexFromStr(k) + if err != nil { + return nil, fmt.Errorf("error parsing %v: %v", + k, err) + } + rpcHops = append(rpcHops, pubkey[:]) + } + + req := &routerrpc.BuildRouteRequest{ + AmtMsat: int64(amt * 1000), + FinalCltvDelta: chainreg.DefaultBitcoinTimeLockDelta, + HopPubkeys: rpcHops, + } + + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) + routeResp, err := sender.RouterClient.BuildRoute(ctxt, req) + if err != nil { + return nil, err + } + + return routeResp.Route, nil +}