From 47d2e1e0245dd95960da757df46b36ad853f6b05 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Sat, 18 Aug 2018 20:30:02 +0200 Subject: [PATCH] routing: add option to specify explicit id for test channels --- routing/pathfind_test.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 02fdfb078..a014bfb2b 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -308,7 +308,15 @@ func defaultTestChannelEnd(alias string) *testChannelEnd { } func symmetricTestChannel(alias1 string, alias2 string, capacity btcutil.Amount, - policy *testChannelPolicy) *testChannel { + policy *testChannelPolicy, chanID ...uint64) *testChannel { + + // Leaving id zero will result in auto-generation of a channel id during + // graph construction. + var id uint64 + if len(chanID) > 0 { + id = chanID[0] + } + return &testChannel{ Capacity: capacity, Node1: &testChannelEnd{ @@ -319,13 +327,15 @@ func symmetricTestChannel(alias1 string, alias2 string, capacity btcutil.Amount, Alias: alias2, testChannelPolicy: *policy, }, + ChannelID: id, } } type testChannel struct { - Node1 *testChannelEnd - Node2 *testChannelEnd - Capacity btcutil.Amount + Node1 *testChannelEnd + Node2 *testChannelEnd + Capacity btcutil.Amount + ChannelID uint64 } type testGraphInstance struct { @@ -415,7 +425,10 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc return nil, err } - channelID := uint64(0) + // Initialize variable that keeps track of the next channel id to assign + // if none is specified. + nextUnassignedChannelID := uint64(100000) + for _, testChannel := range testChannels { for _, alias := range []string{ testChannel.Node1.Alias, testChannel.Node2.Alias} { @@ -426,6 +439,14 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc } } + channelID := testChannel.ChannelID + + // If no channel id is specified, generate an id. + if channelID == 0 { + channelID = nextUnassignedChannelID + nextUnassignedChannelID++ + } + var hash [sha256.Size]byte hash[len(hash)-1] = byte(channelID)