diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 82bcea0a..831c0b00 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -204,6 +204,7 @@ func parseTestGraph(path string) (*testGraphInstance, error) { aliasMap := make(map[string]route.Vertex) privKeyMap := make(map[string]*btcec.PrivateKey) + channelIDs := make(map[route.Vertex]map[route.Vertex]uint64) var source *channeldb.LightningNode // First we insert all the nodes within the graph as vertexes. @@ -356,6 +357,27 @@ func parseTestGraph(path string) (*testGraphInstance, error) { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { return nil, err } + + // We also store the channel IDs info for each of the node. + node1Vertex, err := route.NewVertexFromBytes(node1Bytes) + if err != nil { + return nil, err + } + + node2Vertex, err := route.NewVertexFromBytes(node2Bytes) + if err != nil { + return nil, err + } + + if _, ok := channelIDs[node1Vertex]; !ok { + channelIDs[node1Vertex] = map[route.Vertex]uint64{} + } + channelIDs[node1Vertex][node2Vertex] = edge.ChannelID + + if _, ok := channelIDs[node2Vertex]; !ok { + channelIDs[node2Vertex] = map[route.Vertex]uint64{} + } + channelIDs[node2Vertex][node1Vertex] = edge.ChannelID } return &testGraphInstance{ @@ -363,6 +385,7 @@ func parseTestGraph(path string) (*testGraphInstance, error) { cleanUp: cleanUp, aliasMap: aliasMap, privKeyMap: privKeyMap, + channelIDs: channelIDs, }, nil } @@ -435,6 +458,9 @@ type testGraphInstance struct { // privKeyMap maps a node alias to its private key. This is used to be // able to mock a remote node's signing behaviour. privKeyMap map[string]*btcec.PrivateKey + + // channelIDs stores the channel ID for each node. + channelIDs map[route.Vertex]map[route.Vertex]uint64 } // createTestGraphFromChannels returns a fully populated ChannelGraph based on a set of diff --git a/routing/router_test.go b/routing/router_test.go index fbbacbd7..f653c8b0 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -38,11 +38,29 @@ type testCtx struct { privKeys map[string]*btcec.PrivateKey + channelIDs map[route.Vertex]map[route.Vertex]uint64 + chain *mockChain chainView *mockChainView } +func (c *testCtx) getChannelIDFromAlias(t *testing.T, a, b string) uint64 { + vertexA, ok := c.aliases[a] + require.True(t, ok, "cannot find aliases for %s", a) + + vertexB, ok := c.aliases[b] + require.True(t, ok, "cannot find aliases for %s", b) + + channelIDMap, ok := c.channelIDs[vertexA] + require.True(t, ok, "cannot find channelID map %s(%s)", vertexA, a) + + channelID, ok := channelIDMap[vertexB] + require.True(t, ok, "cannot find channelID using %s(%s)", vertexB, b) + + return channelID +} + func (c *testCtx) RestartRouter() error { // First, we'll reset the chainView's state as it doesn't persist the // filter between restarts. @@ -151,12 +169,13 @@ func createTestCtxFromGraphInstanceAssumeValid(startingHeight uint32, } ctx := &testCtx{ - router: router, - graph: graphInstance.graph, - aliases: graphInstance.aliasMap, - privKeys: graphInstance.privKeyMap, - chain: chain, - chainView: chainView, + router: router, + graph: graphInstance.graph, + aliases: graphInstance.aliasMap, + privKeys: graphInstance.privKeyMap, + channelIDs: graphInstance.channelIDs, + chain: chain, + chainView: chainView, } cleanUp := func() {