graph/db: adjust TestPartialNode
The test as it stands today does not make sense as it adds a Partial/Shell node to the graph via AddLightningNode which will never happen since this is only ever triggered by the gossiper which only calls the method with a full node announcement. Shell/Partial nodes are only ever added via AddChannelEdge which will insert a partial node if we are adding a channel edge which has node pub keys that we dont have a node entry for. So we adjust the test to use this more accurate flow.
This commit is contained in:
1 file changed
+38
-30
+38
-30
@@ -155,62 +155,70 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestPartialNode checks that we can add and retrieve a LightningNode where
|
// TestPartialNode checks that we can add and retrieve a LightningNode where
|
||||||
// where only the pubkey is known to the database.
|
// only the pubkey is known to the database.
|
||||||
func TestPartialNode(t *testing.T) {
|
func TestPartialNode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
graph, err := MakeTestGraph(t)
|
graph, err := MakeTestGraph(t)
|
||||||
require.NoError(t, err, "unable to make test database")
|
require.NoError(t, err, "unable to make test database")
|
||||||
|
|
||||||
// We want to be able to insert nodes into the graph that only has the
|
// To insert a partial node, we need to add a channel edge that has
|
||||||
// PubKey set.
|
// node keys for nodes we are not yet aware
|
||||||
node := &models.LightningNode{
|
var node1, node2 models.LightningNode
|
||||||
HaveNodeAnnouncement: false,
|
copy(node1.PubKeyBytes[:], pubKey1Bytes)
|
||||||
PubKeyBytes: testPub,
|
copy(node2.PubKeyBytes[:], pubKey2Bytes)
|
||||||
}
|
|
||||||
|
|
||||||
if err := graph.AddLightningNode(node); err != nil {
|
// Create an edge attached to these nodes and add it to the graph.
|
||||||
t.Fatalf("unable to add node: %v", err)
|
edgeInfo, _ := createEdge(140, 0, 0, 0, &node1, &node2)
|
||||||
}
|
require.NoError(t, graph.AddChannelEdge(&edgeInfo))
|
||||||
assertNodeInCache(t, graph, node, nil)
|
|
||||||
|
|
||||||
// Next, fetch the node from the database to ensure everything was
|
// Both of the nodes should now be in both the graph (as partial/shell)
|
||||||
|
// nodes _and_ the cache should also have an awareness of both nodes.
|
||||||
|
assertNodeInCache(t, graph, &node1, nil)
|
||||||
|
assertNodeInCache(t, graph, &node2, nil)
|
||||||
|
|
||||||
|
// Next, fetch the node2 from the database to ensure everything was
|
||||||
// serialized properly.
|
// serialized properly.
|
||||||
dbNode, err := graph.FetchLightningNode(testPub)
|
dbNode1, err := graph.FetchLightningNode(pubKey1)
|
||||||
require.NoError(t, err, "unable to locate node")
|
require.NoError(t, err)
|
||||||
|
dbNode2, err := graph.FetchLightningNode(pubKey2)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes)
|
_, exists, err := graph.HasLightningNode(dbNode1.PubKeyBytes)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatalf("unable to query for node: %v", err)
|
require.True(t, exists)
|
||||||
} else if !exists {
|
|
||||||
t.Fatalf("node should be found but wasn't")
|
|
||||||
}
|
|
||||||
|
|
||||||
// The two nodes should match exactly! (with default values for
|
// The two nodes should match exactly! (with default values for
|
||||||
// LastUpdate and db set to satisfy compareNodes())
|
// LastUpdate and db set to satisfy compareNodes())
|
||||||
node = &models.LightningNode{
|
expectedNode1 := &models.LightningNode{
|
||||||
HaveNodeAnnouncement: false,
|
HaveNodeAnnouncement: false,
|
||||||
LastUpdate: time.Unix(0, 0),
|
LastUpdate: time.Unix(0, 0),
|
||||||
PubKeyBytes: testPub,
|
PubKeyBytes: pubKey1,
|
||||||
}
|
}
|
||||||
|
require.NoError(t, compareNodes(dbNode1, expectedNode1))
|
||||||
|
|
||||||
if err := compareNodes(node, dbNode); err != nil {
|
_, exists, err = graph.HasLightningNode(dbNode2.PubKeyBytes)
|
||||||
t.Fatalf("nodes don't match: %v", err)
|
require.NoError(t, err)
|
||||||
|
require.True(t, exists)
|
||||||
|
|
||||||
|
// The two nodes should match exactly! (with default values for
|
||||||
|
// LastUpdate and db set to satisfy compareNodes())
|
||||||
|
expectedNode2 := &models.LightningNode{
|
||||||
|
HaveNodeAnnouncement: false,
|
||||||
|
LastUpdate: time.Unix(0, 0),
|
||||||
|
PubKeyBytes: pubKey2,
|
||||||
}
|
}
|
||||||
|
require.NoError(t, compareNodes(dbNode2, expectedNode2))
|
||||||
|
|
||||||
// Next, delete the node from the graph, this should purge all data
|
// Next, delete the node from the graph, this should purge all data
|
||||||
// related to the node.
|
// related to the node.
|
||||||
if err := graph.DeleteLightningNode(testPub); err != nil {
|
require.NoError(t, graph.DeleteLightningNode(pubKey1))
|
||||||
t.Fatalf("unable to delete node: %v", err)
|
|
||||||
}
|
|
||||||
assertNodeNotInCache(t, graph, testPub)
|
assertNodeNotInCache(t, graph, testPub)
|
||||||
|
|
||||||
// Finally, attempt to fetch the node again. This should fail as the
|
// Finally, attempt to fetch the node again. This should fail as the
|
||||||
// node should have been deleted from the database.
|
// node should have been deleted from the database.
|
||||||
_, err = graph.FetchLightningNode(testPub)
|
_, err = graph.FetchLightningNode(testPub)
|
||||||
if err != ErrGraphNodeNotFound {
|
require.ErrorIs(t, err, ErrGraphNodeNotFound)
|
||||||
t.Fatalf("fetch after delete should fail!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAliasLookup(t *testing.T) {
|
func TestAliasLookup(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user