From aeeff4714d3279357342c7c5438108b570f9ded3 Mon Sep 17 00:00:00 2001
From: "Johan T. Halseth" <johanth@gmail.com>
Date: Mon, 10 Dec 2018 14:56:54 +0100
Subject: [PATCH] autopilot/graph: define addRandNode

---
 autopilot/graph.go           | 42 ++++++++++++++++++++++++++++++++++++
 autopilot/prefattach_test.go |  2 ++
 2 files changed, 44 insertions(+)

diff --git a/autopilot/graph.go b/autopilot/graph.go
index 5ee547378..15440caf7 100644
--- a/autopilot/graph.go
+++ b/autopilot/graph.go
@@ -270,6 +270,30 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
 		nil
 }
 
+func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) {
+	nodeKey, err := randKey()
+	if err != nil {
+		return nil, err
+	}
+	dbNode := &channeldb.LightningNode{
+		HaveNodeAnnouncement: true,
+		Addresses: []net.Addr{
+			&net.TCPAddr{
+				IP: bytes.Repeat([]byte("a"), 16),
+			},
+		},
+		Features:     lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures),
+		AuthSigBytes: testSig.Serialize(),
+	}
+	dbNode.AddPubKey(nodeKey)
+	if err := d.db.AddLightningNode(dbNode); err != nil {
+		return nil, err
+	}
+
+	return nodeKey, nil
+
+}
+
 // memChannelGraph is an implementation of the autopilot.ChannelGraph backed by
 // an in-memory graph.
 type memChannelGraph struct {
@@ -407,6 +431,24 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
 	return &edge1, &edge2, nil
 }
 
+func (m *memChannelGraph) addRandNode() (*btcec.PublicKey, error) {
+	newPub, err := randKey()
+	if err != nil {
+		return nil, err
+	}
+	vertex := memNode{
+		pub: newPub,
+		addrs: []net.Addr{
+			&net.TCPAddr{
+				IP: bytes.Repeat([]byte("a"), 16),
+			},
+		},
+	}
+	m.graph[NewNodeID(newPub)] = vertex
+
+	return newPub, nil
+}
+
 // memNode is a purely in-memory implementation of the autopilot.Node
 // interface.
 type memNode struct {
diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go
index c647c2d92..5801c00de 100644
--- a/autopilot/prefattach_test.go
+++ b/autopilot/prefattach_test.go
@@ -182,6 +182,8 @@ type testGraph interface {
 
 	addRandChannel(*btcec.PublicKey, *btcec.PublicKey,
 		btcutil.Amount) (*ChannelEdge, *ChannelEdge, error)
+
+	addRandNode() (*btcec.PublicKey, error)
 }
 
 func newDiskChanGraph() (testGraph, func(), error) {