@@ -138,6 +138,10 @@ var versionedTests = []versionedTest{
138138 name : "alias lookup" ,
139139 test : testAliasLookup ,
140140 },
141+ {
142+ name : "edge insertion deletion" ,
143+ test : testEdgeInsertionDeletion ,
144+ },
141145 {
142146 name : "partial node" ,
143147 test : testPartialNode ,
@@ -488,79 +492,41 @@ func testSourceNode(t *testing.T, v lnwire.GossipVersion) {
488492 compareNodes (t , testNode , sourceNode )
489493}
490494
491- // TestEdgeInsertionDeletion tests the basic CRUD operations for channel edges.
492- func TestEdgeInsertionDeletion (t * testing.T ) {
495+ // testEdgeInsertionDeletion tests the basic CRUD operations for channel edges.
496+ func testEdgeInsertionDeletion (t * testing.T , v lnwire. GossipVersion ) {
493497 t .Parallel ()
494498 ctx := t .Context ()
495499
496- graph := MakeTestGraph (t )
500+ graph := NewVersionedGraph ( MakeTestGraph (t ), v )
497501
498502 // We'd like to test the insertion/deletion of edges, so we create two
499503 // vertexes to connect.
500- node1 := createTestVertex (t , lnwire .GossipVersion1 )
501- node2 := createTestVertex (t , lnwire .GossipVersion1 )
502-
503- // In addition to the fake vertexes we create some fake channel
504- // identifiers.
505- chanID := uint64 (prand .Int63 ())
506- outpoint := wire.OutPoint {
507- Hash : rev ,
508- Index : 9 ,
509- }
510-
511- // Add the new edge to the database, this should proceed without any
512- // errors.
513- node1Pub , err := node1 .PubKey ()
514- require .NoError (t , err , "unable to generate node key" )
515- node2Pub , err := node2 .PubKey ()
516- require .NoError (t , err , "unable to generate node key" )
517-
518- node1Vertex , err := route .NewVertexFromBytes (
519- node1Pub .SerializeCompressed (),
520- )
521- require .NoError (t , err )
522- node2Vertex , err := route .NewVertexFromBytes (
523- node2Pub .SerializeCompressed (),
524- )
525- require .NoError (t , err )
526-
527- btcKey1 , err := route .NewVertexFromBytes (
528- node1Pub .SerializeCompressed (),
529- )
530- require .NoError (t , err )
531- btcKey2 , err := route .NewVertexFromBytes (
532- node2Pub .SerializeCompressed (),
533- )
534- require .NoError (t , err )
504+ node1 := createTestVertex (t , v )
505+ node2 := createTestVertex (t , v )
535506
536- proof := models .NewV1ChannelAuthProof (
537- testSig .Serialize (),
538- testSig .Serialize (),
539- testSig .Serialize (),
540- testSig .Serialize (),
507+ // Create a fake channel and add it to the graph.
508+ const (
509+ blockHeight = 1234
510+ txIndex = 1
511+ txPosition = 0
512+ outPointIndex = 9
541513 )
542514
543- edgeInfo , err := models .NewV1Channel (
544- chanID ,
545- * chaincfg .MainNetParams .GenesisHash ,
546- node1Vertex ,
547- node2Vertex ,
548- & models.ChannelV1Fields {
549- BitcoinKey1Bytes : btcKey1 ,
550- BitcoinKey2Bytes : btcKey2 ,
551- },
552- models .WithChanProof (proof ),
553- models .WithChannelPoint (outpoint ),
554- models .WithCapacity (9000 ),
515+ edgeInfo , shortChanID := createEdge (
516+ v , blockHeight , txIndex , txPosition , outPointIndex , node1 , node2 ,
555517 )
556- require .NoError (t , err )
518+ chanID := shortChanID .ToUint64 ()
519+ outpoint := wire.OutPoint {
520+ Hash : rev ,
521+ Index : outPointIndex ,
522+ }
557523
558524 require .NoError (t , graph .AddChannelEdge (ctx , edgeInfo ))
559- assertEdgeWithNoPoliciesInCache (t , graph , edgeInfo )
525+ assertEdgeWithNoPoliciesInCache (t , graph . ChannelGraph , edgeInfo )
560526
561527 // Show that trying to insert the same channel again will return the
562528 // expected error.
563- err = graph .AddChannelEdge (ctx , edgeInfo )
529+ err : = graph .AddChannelEdge (ctx , edgeInfo )
564530 require .ErrorIs (t , err , ErrEdgeAlreadyExist )
565531
566532 // Ensure that both policies are returned as unknown (nil).
@@ -572,7 +538,7 @@ func TestEdgeInsertionDeletion(t *testing.T) {
572538 // Next, attempt to delete the edge from the database, again this
573539 // should proceed without any issues.
574540 require .NoError (t , graph .DeleteChannelEdges (false , true , chanID ))
575- assertNoEdge (t , graph , chanID )
541+ assertNoEdge (t , graph . ChannelGraph , chanID )
576542
577543 // Ensure that any query attempts to lookup the delete channel edge are
578544 // properly deleted.
0 commit comments