diff --git a/routing/router_test.go b/routing/router_test.go index 1ceb0a90b..7d7312fb8 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -9,14 +9,14 @@ import ( "testing" "time" + "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/htlcswitch" - "github.com/btcsuite/btcd/wire" + "github.com/btcsuite/btcd/btcec" "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lightning-onion" "github.com/lightningnetwork/lnd/lnwire" - "github.com/btcsuite/btcd/btcec" ) // defaultNumRoutes is the default value for the maximum number of routes to @@ -1941,3 +1941,16 @@ func TestIsStaleEdgePolicy(t *testing.T) { t.Fatalf("router failed to detect fresh edge policy") } } + +// TestEmptyRoutesGenerateSphinxPacket tests that the generateSphinxPacket +// function is able to gracefully handle being passed a nil set of hops for the +// route by the caller. +func TestEmptyRoutesGenerateSphinxPacket(t *testing.T) { + t.Parallel() + + emptyRoute := &Route{} + _, _, err := generateSphinxPacket(emptyRoute, testHash[:]) + if err != ErrNoRouteHopsProvided { + t.Fatalf("expected empty hops error: instead got: %v", err) + } +}