From f8899dd3249300d5ae97607fc7fab1b3131a944e Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 25 Feb 2026 08:32:39 +0200 Subject: [PATCH 1/5] graph/db: migrate tests from Fatal to require helpers Replace remaining fatal-style assertions in graph/db tests with direct testify/require helpers. This simplifies control flow and reduces indentation by using NoError, True/False, Equal, Len, Empty, and Nil assertions directly. --- graph/db/addr_test.go | 25 +- graph/db/channel_cache_test.go | 19 +- graph/db/graph_test.go | 527 ++++++++------------------------- graph/db/reject_cache_test.go | 19 +- 4 files changed, 135 insertions(+), 455 deletions(-) diff --git a/graph/db/addr_test.go b/graph/db/addr_test.go index d3c3700a3..4e0e53d72 100644 --- a/graph/db/addr_test.go +++ b/graph/db/addr_test.go @@ -3,7 +3,6 @@ package graphdb import ( "bytes" "net" - "strings" "testing" "github.com/lightningnetwork/lnd/lnwire" @@ -148,29 +147,15 @@ func TestAddrSerialization(t *testing.T) { var b bytes.Buffer for _, test := range addrTests { err := SerializeAddr(&b, test.expAddr) - switch { - case err == nil && test.serErr != "": - t.Fatalf("expected serialization err for addr %v", - test.expAddr) - - case err != nil && test.serErr == "": - t.Fatalf("unexpected serialization err for addr %v: %v", - test.expAddr, err) - - case err != nil && !strings.Contains(err.Error(), test.serErr): - t.Fatalf("unexpected serialization err for addr %v, "+ - "want: %v, got %v", test.expAddr, test.serErr, - err) - - case err != nil: + if test.serErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, test.serErr) continue } + require.NoError(t, err) addr, err := DeserializeAddr(&b) - if err != nil { - t.Fatalf("unable to deserialize address: %v", err) - } - + require.NoError(t, err) require.Equal(t, test.expAddr, addr) } } diff --git a/graph/db/channel_cache_test.go b/graph/db/channel_cache_test.go index 6ecbed8f3..28d612724 100644 --- a/graph/db/channel_cache_test.go +++ b/graph/db/channel_cache_test.go @@ -1,13 +1,13 @@ package graphdb import ( - "reflect" "testing" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" + "github.com/stretchr/testify/require" ) // TestChannelCache checks the behavior of the channelCache with respect to @@ -23,9 +23,7 @@ func TestChannelCache(t *testing.T) { // As a sanity check, assert that querying the empty cache does not // return an entry. _, ok := c.get(v, 0) - if ok { - t.Fatalf("channel cache should be empty") - } + require.False(t, ok) // Now, fill up the cache entirely. for i := uint64(0); i < cacheSize; i++ { @@ -55,9 +53,7 @@ func TestChannelCache(t *testing.T) { // Assert that exactly one element has been evicted. numEvicted := len(evicted) - if numEvicted != 1 { - t.Fatalf("expected one evicted entry, got: %d", numEvicted) - } + require.Equal(t, 1, numEvicted) // Remove the highest item which initially caused the eviction and // reinsert the element that was evicted prior. @@ -92,15 +88,10 @@ func assertHasChanEntries(t *testing.T, c *channelCache, for i := start; i < end; i++ { entry, ok := c.get(v, i) - if !ok { - t.Fatalf("channel cache should contain chan %d", i) - } + require.True(t, ok) expEntry := channelForInt(i) - if !reflect.DeepEqual(entry, expEntry) { - t.Fatalf("entry mismatch, want: %v, got: %v", - expEntry, entry) - } + require.Equal(t, expEntry, entry) } } diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 0398031a7..9dd5a6adc 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -12,7 +12,6 @@ import ( prand "math/rand" "net" "reflect" - "runtime" "sync" "testing" "time" @@ -846,9 +845,7 @@ func TestDisconnectBlockAtHeight(t *testing.T) { graph := MakeTestGraph(t) sourceNode := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.SetSourceNode(ctx, sourceNode); err != nil { - t.Fatalf("unable to set source node: %v", err) - } + require.NoError(t, graph.SetSourceNode(ctx, sourceNode)) // We'd like to test the insertion/deletion of edges, so we create two // vertexes to connect. @@ -896,17 +893,9 @@ func TestDisconnectBlockAtHeight(t *testing.T) { ) // Now add all these new edges to the database. - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } - - if err := graph.AddChannelEdge(ctx, edgeInfo2); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } - - if err := graph.AddChannelEdge(ctx, edgeInfo3); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo2)) + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo3)) assertEdgeWithNoPoliciesInCache(t, graph, edgeInfo) assertEdgeWithNoPoliciesInCache(t, graph, edgeInfo2) assertEdgeWithNoPoliciesInCache(t, graph, edgeInfo3) @@ -914,58 +903,37 @@ func TestDisconnectBlockAtHeight(t *testing.T) { // Call DisconnectBlockAtHeight, which should prune every channel // that has a funding height of 'height' or greater. removed, err := graph.DisconnectBlockAtHeight(uint32(height)) - if err != nil { - t.Fatalf("unable to prune %v", err) - } + require.NoError(t, err) assertNoEdge(t, graph, edgeInfo.ChannelID) assertNoEdge(t, graph, edgeInfo2.ChannelID) assertEdgeWithNoPoliciesInCache(t, graph, edgeInfo3) // The two edges should have been removed. - if len(removed) != 2 { - t.Fatalf("expected two edges to be removed from graph, "+ - "only %d were", len(removed)) - } - if removed[0].ChannelID != edgeInfo.ChannelID { - t.Fatalf("expected edge to be removed from graph") - } - if removed[1].ChannelID != edgeInfo2.ChannelID { - t.Fatalf("expected edge to be removed from graph") - } + require.Len(t, removed, 2) + require.Equal(t, edgeInfo.ChannelID, removed[0].ChannelID) + require.Equal(t, edgeInfo2.ChannelID, removed[1].ChannelID) // The two first edges should be removed from the db. has, isZombie, err := graph.HasChannelEdge( lnwire.GossipVersion1, edgeInfo.ChannelID, ) require.NoError(t, err, "unable to query for edge") - if has { - t.Fatalf("edge1 was not pruned from the graph") - } - if isZombie { - t.Fatal("reorged edge1 should not be marked as zombie") - } + require.False(t, has) + require.False(t, isZombie) has, isZombie, err = graph.HasChannelEdge( lnwire.GossipVersion1, edgeInfo2.ChannelID, ) require.NoError(t, err, "unable to query for edge") - if has { - t.Fatalf("edge2 was not pruned from the graph") - } - if isZombie { - t.Fatal("reorged edge2 should not be marked as zombie") - } + require.False(t, has) + require.False(t, isZombie) // Edge 3 should not be removed. has, isZombie, err = graph.HasChannelEdge( lnwire.GossipVersion1, edgeInfo3.ChannelID, ) require.NoError(t, err, "unable to query for edge") - if !has { - t.Fatalf("edge3 was pruned from the graph") - } - if isZombie { - t.Fatal("edge3 was marked as zombie") - } + require.True(t, has) + require.False(t, isZombie) // PruneTip should be set to the blockHash we specified for the block // at height 155. @@ -977,38 +945,17 @@ func TestDisconnectBlockAtHeight(t *testing.T) { func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo, e2 *models.ChannelEdgeInfo) { - - if e1.ChannelID != e2.ChannelID { - t.Fatalf("chan id's don't match: %v vs %v", e1.ChannelID, - e2.ChannelID) - } - - if e1.ChainHash != e2.ChainHash { - t.Fatalf("chain hashes don't match: %v vs %v", e1.ChainHash, - e2.ChainHash) - } - - if !bytes.Equal(e1.NodeKey1Bytes[:], e2.NodeKey1Bytes[:]) { - t.Fatalf("nodekey1 doesn't match") - } - if !bytes.Equal(e1.NodeKey2Bytes[:], e2.NodeKey2Bytes[:]) { - t.Fatalf("nodekey2 doesn't match") - } + require.Equal(t, e2.ChannelID, e1.ChannelID) + require.Equal(t, e2.ChainHash, e1.ChainHash) + require.Equal(t, e2.NodeKey1Bytes[:], e1.NodeKey1Bytes[:]) + require.Equal(t, e2.NodeKey2Bytes[:], e1.NodeKey2Bytes[:]) btcKey1E1 := e1.BitcoinKey1Bytes.UnwrapOr(route.Vertex{}) btcKey1E2 := e2.BitcoinKey1Bytes.UnwrapOr(route.Vertex{}) - if !bytes.Equal(btcKey1E1[:], btcKey1E2[:]) { - t.Fatalf("bitcoinkey1 doesn't match") - } + require.Equal(t, btcKey1E2[:], btcKey1E1[:]) btcKey2E1 := e1.BitcoinKey2Bytes.UnwrapOr(route.Vertex{}) btcKey2E2 := e2.BitcoinKey2Bytes.UnwrapOr(route.Vertex{}) - if !bytes.Equal(btcKey2E1[:], btcKey2E2[:]) { - t.Fatalf("bitcoinkey2 doesn't match") - } - - if !e1.Features.Equals(e2.Features.RawFeatureVector) { - t.Fatalf("features don't match: %v vs %v", e1.Features, - e2.Features) - } + require.Equal(t, btcKey2E2[:], btcKey2E1[:]) + require.True(t, e1.Features.Equals(e2.Features.RawFeatureVector)) require.True(t, bytes.Equal( e1.AuthProof.NodeSig1(), @@ -1027,20 +974,9 @@ func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo, e2.AuthProof.BitcoinSig2(), )) - if e1.ChannelPoint != e2.ChannelPoint { - t.Fatalf("channel point match: %v vs %v", e1.ChannelPoint, - e2.ChannelPoint) - } - - if e1.Capacity != e2.Capacity { - t.Fatalf("capacity doesn't match: %v vs %v", e1.Capacity, - e2.Capacity) - } - - if !bytes.Equal(e1.ExtraOpaqueData, e2.ExtraOpaqueData) { - t.Fatalf("extra data doesn't match: %v vs %v", - e2.ExtraOpaqueData, e2.ExtraOpaqueData) - } + require.Equal(t, e2.ChannelPoint, e1.ChannelPoint) + require.Equal(t, e2.Capacity, e1.Capacity) + require.Equal(t, e2.ExtraOpaqueData, e1.ExtraOpaqueData) } func createChannelEdge(node1, node2 *models.Node, @@ -1210,14 +1146,10 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { // We'd like to test the update of edges inserted into the database, so // we create two vertexes to connect. node1 := createTestVertex(t, v) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) assertNodeInCache(t, graph.ChannelGraph, node1, testFeatures) node2 := createTestVertex(t, v) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) assertNodeInCache(t, graph.ChannelGraph, node2, testFeatures) // Create an edge and add it to the db. @@ -1230,9 +1162,7 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { require.Len(t, graph.graphCache.nodeChannels, 0) // Add the edge info. - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) assertEdgeWithNoPoliciesInCache(t, graph.ChannelGraph, edgeInfo) chanID := edgeInfo.ChannelID @@ -1240,15 +1170,11 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { // Next, insert both edge policies into the database, they should both // be inserted without any issues. - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) assertEdgeWithPolicyInCache( t, graph.ChannelGraph, edgeInfo, edge1, true, ) - if err := graph.UpdateEdgePolicy(ctx, edge2); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2)) assertEdgeWithPolicyInCache( t, graph.ChannelGraph, edgeInfo, edge2, false, ) @@ -1257,32 +1183,21 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { // found. found, isZombie, err := graph.HasChannelEdge(chanID) require.NoError(t, err, "unable to query for edge") - if !found { - t.Fatalf("graph should have of inserted edge") - } - if isZombie { - t.Fatal("live edge should not be marked as zombie") - } + require.True(t, found) + require.False(t, isZombie) // We should also be able to retrieve the channelID only knowing the // channel point of the channel. dbChanID, err := graph.ChannelID(&outpoint) require.NoError(t, err, "unable to retrieve channel ID") - if dbChanID != chanID { - t.Fatalf("chan ID's mismatch, expected %v got %v", dbChanID, - chanID) - } + require.Equal(t, chanID, dbChanID) // With the edges inserted, perform some queries to ensure that they've // been inserted properly. dbEdgeInfo, dbEdge1, dbEdge2, err := graph.FetchChannelEdgesByID(chanID) require.NoError(t, err, "unable to fetch channel by ID") - if err := compareEdgePolicies(dbEdge1, edge1); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } - if err := compareEdgePolicies(dbEdge2, edge2); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } + require.NoError(t, compareEdgePolicies(dbEdge1, edge1)) + require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) // Next, attempt to query the channel edges according to the outpoint @@ -1291,12 +1206,8 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { &outpoint, ) require.NoError(t, err, "unable to fetch channel by ID") - if err := compareEdgePolicies(dbEdge1, edge1); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } - if err := compareEdgePolicies(dbEdge2, edge2); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } + require.NoError(t, compareEdgePolicies(dbEdge1, edge1)) + require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) } @@ -2205,20 +2116,9 @@ func assertPruneTip(t *testing.T, graph *ChannelGraph, blockHash *chainhash.Hash, blockHeight uint32) { pruneHash, pruneHeight, err := graph.PruneTip() - if err != nil { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: unable to fetch prune tip: %v", line, err) - } - if !bytes.Equal(blockHash[:], pruneHash[:]) { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line: %v, prune tips don't match, expected %x got %x", - line, blockHash, pruneHash) - } - if pruneHeight != blockHeight { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: prune heights don't match, expected %v "+ - "got %v", line, blockHeight, pruneHeight) - } + require.NoError(t, err) + require.Equal(t, blockHash[:], pruneHash[:]) + require.Equal(t, blockHeight, pruneHeight) } func assertNumChans(t *testing.T, graph *ChannelGraph, n int) { @@ -2247,23 +2147,12 @@ func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) { return nil }, func() {}) - if err != nil { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: unable to scan nodes: %v", line, err) - } - - if numNodes != n { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: expected %v nodes, got %v", line, n, - numNodes) - } + require.NoError(t, err) + require.Equal(t, n, numNodes) } func assertChanViewEqual(t *testing.T, a []EdgePoint, b []EdgePoint) { - if len(a) != len(b) { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: chan views don't match", line) - } + require.Len(t, b, len(a)) chanViewSet := make(map[wire.OutPoint]struct{}) for _, op := range a { @@ -2271,21 +2160,15 @@ func assertChanViewEqual(t *testing.T, a []EdgePoint, b []EdgePoint) { } for _, op := range b { - if _, ok := chanViewSet[op.OutPoint]; !ok { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: chanPoint(%v) not found in first "+ - "view", line, op) - } + _, ok := chanViewSet[op.OutPoint] + require.True(t, ok) } } func assertChanViewEqualChanPoints(t *testing.T, a []EdgePoint, b []*wire.OutPoint) { - if len(a) != len(b) { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: chan views don't match", line) - } + require.Len(t, b, len(a)) chanViewSet := make(map[wire.OutPoint]struct{}) for _, op := range a { @@ -2293,11 +2176,8 @@ func assertChanViewEqualChanPoints(t *testing.T, a []EdgePoint, } for _, op := range b { - if _, ok := chanViewSet[*op]; !ok { - _, _, line, _ := runtime.Caller(1) - t.Fatalf("line %v: chanPoint(%v) not found in first "+ - "view", line, op) - } + _, ok := chanViewSet[*op] + require.True(t, ok) } } @@ -2308,9 +2188,7 @@ func TestGraphPruning(t *testing.T) { graph := MakeTestGraph(t) sourceNode := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.SetSourceNode(ctx, sourceNode); err != nil { - t.Fatalf("unable to set source node: %v", err) - } + require.NoError(t, graph.SetSourceNode(ctx, sourceNode)) // As initial set up for the test, we'll create a graph with 5 vertexes // and enough edges to create a fully connected graph. The graph will @@ -2319,10 +2197,7 @@ func TestGraphPruning(t *testing.T) { graphNodes := make([]*models.Node, numNodes) for i := 0; i < numNodes; i++ { node := createTestVertex(t, lnwire.GossipVersion1) - - if err := graph.AddNode(ctx, node); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node)) graphNodes[i] = node } @@ -2362,12 +2237,8 @@ func TestGraphPruning(t *testing.T) { models.WithChannelPoint(op), models.WithCapacity(1000), ) - if err != nil { - t.Fatalf("unable to create edge: %v", err) - } - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, err) + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) pkScript, err := edgeInfo.FundingPKScript() require.NoError(t, err) @@ -2383,9 +2254,7 @@ func TestGraphPruning(t *testing.T) { edge.ChannelFlags = 0 edge.ToNode = graphNodes[i].PubKeyBytes edge.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge)) // Create another random edge that points from node_i+1 -> // node_i this time. @@ -2393,9 +2262,7 @@ func TestGraphPruning(t *testing.T) { edge.ChannelFlags = 1 edge.ToNode = graphNodes[i].PubKeyBytes edge.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge)) } // With all the channel points added, we'll consult the graph to ensure @@ -2415,10 +2282,7 @@ func TestGraphPruning(t *testing.T) { block := channelPoints[:2] prunedChans, err := graph.PruneGraph(block, &blockHash, blockHeight) require.NoError(t, err, "unable to prune graph") - if len(prunedChans) != 2 { - t.Fatalf("incorrect number of channels pruned: "+ - "expected %v, got %v", 2, prunedChans) - } + require.Len(t, prunedChans, 2) // Now ensure that the prune tip has been updated. assertPruneTip(t, graph, &blockHash, blockHeight) @@ -2447,9 +2311,7 @@ func TestGraphPruning(t *testing.T) { require.NoError(t, err, "unable to prune graph") // No channels should have been detected as pruned. - if len(prunedChans) != 0 { - t.Fatalf("channels were pruned but shouldn't have been") - } + require.Empty(t, prunedChans) // Once again, the prune tip should have been updated. We should still // see both channels and their participants, along with the source node. @@ -2468,10 +2330,7 @@ func TestGraphPruning(t *testing.T) { // The remainder of the channels should have been pruned from the // graph. - if len(prunedChans) != 2 { - t.Fatalf("incorrect number of channels pruned: "+ - "expected %v, got %v", 2, len(prunedChans)) - } + require.Len(t, prunedChans, 2) // The prune tip should be updated, no channels should be found, and // only the source node should remain within the current graph. @@ -2484,10 +2343,7 @@ func TestGraphPruning(t *testing.T) { // channel view. channelView, err = graph.ChannelView() require.NoError(t, err, "unable to get graph channel view") - if len(channelView) != 0 { - t.Fatalf("channel view should be empty, instead have: %v", - channelView) - } + require.Empty(t, channelView) } // TestHighestChanID tests that we're able to properly retrieve the highest @@ -2502,9 +2358,7 @@ func testHighestChanID(t *testing.T, v lnwire.GossipVersion) { // get a channel ID of zero if we ask for the highest channel ID. bestID, err := graph.HighestChanID(ctx) require.NoError(t, err, "unable to get highest ID") - if bestID != 0 { - require.Equal(t, uint64(0), bestID) - } + require.Zero(t, bestID) // Next, we'll insert two channels into the database, with each channel // connecting the same two nodes. @@ -2523,10 +2377,7 @@ func testHighestChanID(t *testing.T, v lnwire.GossipVersion) { // known channel ID in the database. bestID, err = graph.HighestChanID(ctx) require.NoError(t, err, "unable to get highest ID") - - if bestID != chanID2.ToUint64() { - require.Equal(t, chanID2.ToUint64(), bestID) - } + require.Equal(t, chanID2.ToUint64(), bestID) // If we add another edge, then the current best chan ID should be // updated as well. @@ -2555,21 +2406,13 @@ func TestChanUpdatesInHorizon(t *testing.T) { chanUpdates, err := fn.CollectErr(chanIter) require.NoError(t, err, "unable to updates for updates") - - if len(chanUpdates) != 0 { - t.Fatalf("expected 0 chan updates, instead got %v", - len(chanUpdates)) - } + require.Empty(t, chanUpdates) // We'll start by creating two nodes which will seed our test graph. node1 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) node2 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) // We'll now create 10 channels between the two nodes, with update // times 10 seconds after each other. @@ -2582,10 +2425,7 @@ func TestChanUpdatesInHorizon(t *testing.T) { lnwire.GossipVersion1, uint32(i*10), 0, 0, 0, node1, node2, ) - - if err := graph.AddChannelEdge(ctx, channel); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, channel)) edge1UpdateTime := endTime edge2UpdateTime := edge1UpdateTime.Add(time.Second) @@ -2598,9 +2438,7 @@ func TestChanUpdatesInHorizon(t *testing.T) { edge1.ChannelFlags = 0 edge1.ToNode = node2.PubKeyBytes edge1.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) edge2 := newEdgePolicy( lnwire.GossipVersion1, chanID.ToUint64(), @@ -2609,9 +2447,7 @@ func TestChanUpdatesInHorizon(t *testing.T) { edge2.ChannelFlags = 1 edge2.ToNode = node1.PubKeyBytes edge2.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge2); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2)) edges = append(edges, ChannelEdge{ Info: channel, @@ -2676,15 +2512,8 @@ func TestChanUpdatesInHorizon(t *testing.T) { ) resp, err := fn.CollectErr(respIter) - if err != nil { - t.Fatalf("unable to query for updates: %v", err) - } - - if len(resp) != len(queryCase.resp) { - t.Fatalf("expected %v chans, got %v chans", - len(queryCase.resp), len(resp)) - - } + require.NoError(t, err) + require.Len(t, resp, len(queryCase.resp)) for i := 0; i < len(resp); i++ { chanExp := queryCase.resp[i] @@ -3208,13 +3037,9 @@ func TestFilterKnownChanIDs(t *testing.T) { // We'll start by creating two nodes which will seed our test graph. node1 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) node2 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) // Next, we'll add 5 channel ID's to the graph, each of them having a // block height 10 blocks after the previous. @@ -3225,10 +3050,7 @@ func TestFilterKnownChanIDs(t *testing.T) { lnwire.GossipVersion1, uint32(i*10), 0, 0, 0, node1, node2, ) - - if err := graph.AddChannelEdge(ctx, channel); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, channel)) chanIDs = append(chanIDs, NewChannelUpdateInfo( chanID, time.Time{}, time.Time{}, @@ -3242,13 +3064,9 @@ func TestFilterKnownChanIDs(t *testing.T) { lnwire.GossipVersion1, uint32(i*10+1), 0, 0, 0, node1, node2, ) - if err := graph.AddChannelEdge(ctx, channel); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, channel)) err := graph.DeleteChannelEdges(false, true, channel.ChannelID) - if err != nil { - t.Fatalf("unable to mark edge zombie: %v", err) - } + require.NoError(t, err) zombieIDs = append( zombieIDs, ChannelUpdateInfo{ShortChannelID: chanID}, @@ -3952,20 +3770,13 @@ func testFetchChanInfos(t *testing.T, v lnwire.GossipVersion) { // edges back. resp, err := graph.FetchChanInfos(edgeQuery) require.NoError(t, err, "unable to fetch chan edges") - if len(resp) != len(edges) { - t.Fatalf("expected %v edges, instead got %v", len(edges), - len(resp)) - } + require.Len(t, resp, len(edges)) for i := 0; i < len(resp); i++ { err := compareEdgePolicies(resp[i].Policy1, edges[i].Policy1) - if err != nil { - t.Fatalf("edge doesn't match: %v", err) - } + require.NoError(t, err) err = compareEdgePolicies(resp[i].Policy2, edges[i].Policy2) - if err != nil { - t.Fatalf("edge doesn't match: %v", err) - } + require.NoError(t, err) assertEdgeInfoEqual(t, resp[i].Info, edges[i].Info) } } @@ -4060,46 +3871,34 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) { } sourceNode := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.SetSourceNode(ctx, sourceNode); err != nil { - t.Fatalf("unable to set source node: %v", err) - } + require.NoError(t, graph.SetSourceNode(ctx, sourceNode)) // We'll first populate our graph with two nodes. All channels created // below will be made between these two nodes. node1 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) node2 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) // With the two nodes created, we'll now create a random channel, as // well as two edges in the database with distinct update times. edgeInfo, chanID := createEdge( lnwire.GossipVersion1, 100, 0, 0, 0, node1, node2, ) - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) edge1 := randEdgePolicy(chanID.ToUint64()) edge1.ChannelFlags = 0 edge1.ToNode = node1.PubKeyBytes edge1.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) edge1 = copyEdgePolicy(edge1) // Avoid read/write race conditions. edge2 := randEdgePolicy(chanID.ToUint64()) edge2.ChannelFlags = 1 edge2.ToNode = node2.PubKeyBytes edge2.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge2); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2)) edge2 = copyEdgePolicy(edge2) // Avoid read/write race conditions. // checkIndexTimestamps is a helper function that checks the edge update @@ -4148,9 +3947,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) { return nil }) }, func() {}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } // With both edges policies added, we'll make sure to check they exist @@ -4164,14 +3961,10 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) { // removed from the update index. edge1.ChannelFlags = 2 edge1.LastUpdate = time.Now() - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) edge2.ChannelFlags = 3 edge2.LastUpdate = edge1.LastUpdate.Add(time.Hour) - if err := graph.UpdateEdgePolicy(ctx, edge2); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2)) // With the policies updated, we should now be able to find their // updated entries within the update index. @@ -4206,34 +3999,24 @@ func TestPruneGraphNodes(t *testing.T) { // We'll start off by inserting our source node, to ensure that it's // the only node left after we prune the graph. sourceNode := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.SetSourceNode(ctx, sourceNode); err != nil { - t.Fatalf("unable to set source node: %v", err) - } + require.NoError(t, graph.SetSourceNode(ctx, sourceNode)) // With the source node inserted, we'll now add three nodes to the // channel graph, at the end of the scenario, only two of these nodes // should still be in the graph. node1 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) node2 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) node3 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node3); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node3)) // We'll now add a new edge to the graph, but only actually advertise // the edge of *one* of the nodes. edgeInfo, chanID := createEdge( lnwire.GossipVersion1, 100, 0, 0, 0, node1, node2, ) - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) // We'll now insert an advertised edge, but it'll only be the edge that // points from the first to the second node. @@ -4241,14 +4024,10 @@ func TestPruneGraphNodes(t *testing.T) { edge1.ChannelFlags = 0 edge1.ToNode = node1.PubKeyBytes edge1.SigBytes = testSig.Serialize() - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) // We'll now initiate a around of graph pruning. - if err := graph.PruneGraphNodes(); err != nil { - t.Fatalf("unable to prune graph nodes: %v", err) - } + require.NoError(t, graph.PruneGraphNodes()) // At this point, there should be 3 nodes left in the graph still: the // source node (which can't be pruned), and node 1+2. Nodes 1 and two @@ -4315,9 +4094,7 @@ func TestNodePruningUpdateIndexDeletion(t *testing.T) { // We'll first populate our graph with a single node that will be // removed shortly. node1 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) // We'll confirm that we can retrieve the node using // NodeUpdatesInHorizon, using a time that's slightly beyond the last @@ -4330,10 +4107,7 @@ func TestNodePruningUpdateIndexDeletion(t *testing.T) { // match the node we just inserted. nodesInHorizon, err := fn.CollectErr(nodesInHorizonIter) require.NoError(t, err, "unable to fetch nodes in horizon") - if len(nodesInHorizon) != 1 { - t.Fatalf("should have 1 nodes instead have: %v", - len(nodesInHorizon)) - } + require.Len(t, nodesInHorizon, 1) compareNodes(t, node1, nodesInHorizon[0]) // We'll now delete the node from the graph, this should result in it @@ -4346,11 +4120,7 @@ func TestNodePruningUpdateIndexDeletion(t *testing.T) { nodesInHorizonIter = graph.NodeUpdatesInHorizon(startTime, endTime) nodesInHorizon, err = fn.CollectErr(nodesInHorizonIter) require.NoError(t, err, "unable to fetch nodes in horizon") - - if len(nodesInHorizon) != 0 { - t.Fatalf("should have zero nodes instead have: %v", - len(nodesInHorizon)) - } + require.Empty(t, nodesInHorizon) } var ( @@ -4581,15 +4351,11 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) { // Create first node and add it to the graph. node1 := createTestVertex(t, v) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) // Create second node and add it to the graph. node2 := createTestVertex(t, v) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) // Adding a new channel edge to the graph. edgeInfo, edge1, edge2 := createChannelEdge(node1, node2, v) @@ -4599,21 +4365,13 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) { case lnwire.GossipVersion2: node2.LastBlockHeight = nextBlockHeight() } - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } - - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) // Ensure no disabled channels exist in the bucket on start. disabledChanIds, err := graph.DisabledChannelIDs() require.NoError(t, err, "unable to get disabled channel ids") - if len(disabledChanIds) > 0 { - t.Fatalf("expected empty disabled channels, got %v disabled "+ - "channels", len(disabledChanIds)) - } + require.Empty(t, disabledChanIds) // Add one disabled policy and ensure the channel is still not in the // disabled list. @@ -4623,15 +4381,10 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) { case lnwire.GossipVersion2: edge1.DisableFlags |= lnwire.ChanUpdateDisableIncoming } - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) disabledChanIds, err = graph.DisabledChannelIDs() require.NoError(t, err, "unable to get disabled channel ids") - if len(disabledChanIds) > 0 { - t.Fatalf("expected empty disabled channels, got %v disabled "+ - "channels", len(disabledChanIds)) - } + require.Empty(t, disabledChanIds) // Add second disabled policy and ensure the channel is now in the // disabled list. @@ -4641,31 +4394,19 @@ func testDisabledChannelIDs(t *testing.T, v lnwire.GossipVersion) { case lnwire.GossipVersion2: edge2.DisableFlags |= lnwire.ChanUpdateDisableIncoming } - if err := graph.UpdateEdgePolicy(ctx, edge2); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge2)) disabledChanIds, err = graph.DisabledChannelIDs() require.NoError(t, err, "unable to get disabled channel ids") - if len(disabledChanIds) != 1 || - disabledChanIds[0] != edgeInfo.ChannelID { - - t.Fatalf("expected disabled channel with id %v, "+ - "got %v", edgeInfo.ChannelID, disabledChanIds) - } + require.Equal(t, []uint64{edgeInfo.ChannelID}, disabledChanIds) // Delete the channel edge and ensure it is removed from the disabled // list. - if err = graph.DeleteChannelEdges( + require.NoError(t, graph.DeleteChannelEdges( false, true, edgeInfo.ChannelID, - ); err != nil { - t.Fatalf("unable to delete channel edge: %v", err) - } + )) disabledChanIds, err = graph.DisabledChannelIDs() require.NoError(t, err, "unable to get disabled channel ids") - if len(disabledChanIds) > 0 { - t.Fatalf("expected empty disabled channels, got %v disabled "+ - "channels", len(disabledChanIds)) - } + require.Empty(t, disabledChanIds) } // TestEdgePolicyMissingMaxHTLC tests that if we find a ChannelEdgePolicy in @@ -4688,20 +4429,14 @@ func TestEdgePolicyMissingMaxHTLC(t *testing.T) { // We'd like to test the update of edges inserted into the database, so // we create two vertexes to connect. node1 := createTestVertex(t, lnwire.GossipVersion1) - if err := graph.AddNode(ctx, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node1)) node2 := createTestVertex(t, lnwire.GossipVersion1) edgeInfo, edge1, edge2 := createChannelEdge( node1, node2, lnwire.GossipVersion1, ) - if err := graph.AddNode(ctx, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } - if err := graph.AddChannelEdge(ctx, edgeInfo); err != nil { - t.Fatalf("unable to create channel edge: %v", err) - } + require.NoError(t, graph.AddNode(ctx, node2)) + require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) chanID := edgeInfo.ChannelID from := edge2.ToNode[:] @@ -4746,28 +4481,18 @@ func TestEdgePolicyMissingMaxHTLC(t *testing.T) { require.NoError(t, err, "unable to fetch channel by ID") // The first edge should have a nil-policy returned - if dbEdge1 != nil { - t.Fatalf("expected db edge to be nil") - } - if err := compareEdgePolicies(dbEdge2, edge2); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } + require.Nil(t, dbEdge1) + require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) // Now add the original, unmodified edge policy, and make sure the edge // policies then become fully populated. - if err := graph.UpdateEdgePolicy(ctx, edge1); err != nil { - t.Fatalf("unable to update edge: %v", err) - } + require.NoError(t, graph.UpdateEdgePolicy(ctx, edge1)) dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByID(chanID) require.NoError(t, err, "unable to fetch channel by ID") - if err := compareEdgePolicies(dbEdge1, edge1); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } - if err := compareEdgePolicies(dbEdge2, edge2); err != nil { - t.Fatalf("edge doesn't match: %v", err) - } + require.NoError(t, compareEdgePolicies(dbEdge1, edge1)) + require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) } @@ -4810,11 +4535,7 @@ func assertNumZombies(t *testing.T, graph *ChannelGraph, expZombies uint64) { numZombies, err := graph.NumZombies() require.NoError(t, err, "unable to query number of zombies") - - if numZombies != expZombies { - t.Fatalf("expected %d zombies, found %d", - expZombies, numZombies) - } + require.Equal(t, expZombies, numZombies) } // TestGraphZombieIndex ensures that we can mark edges correctly as zombie/live. @@ -4954,9 +4675,8 @@ func TestLightningNodeSigVerification(t *testing.T) { // Create some dummy data to sign. var data [32]byte - if _, err := prand.Read(data[:]); err != nil { - t.Fatalf("unable to read prand: %v", err) - } + _, err := prand.Read(data[:]) + require.NoError(t, err) // Create private key and sign the data with it. priv, err := btcec.NewPrivateKey() @@ -4965,9 +4685,7 @@ func TestLightningNodeSigVerification(t *testing.T) { sign := ecdsa.Sign(priv, data[:]) // Sanity check that the signature checks out. - if !sign.Verify(data[:], priv.PubKey()) { - t.Fatalf("signature doesn't check out") - } + require.True(t, sign.Verify(data[:], priv.PubKey())) // Create a Node from the same private key. node := createNode(t, lnwire.GossipVersion1, priv) @@ -4976,10 +4694,7 @@ func TestLightningNodeSigVerification(t *testing.T) { // pubkey returned from the lightning node. nodePub, err := node.PubKey() require.NoError(t, err, "unable to get pubkey") - - if !sign.Verify(data[:], nodePub) { - t.Fatalf("unable to verify sig") - } + require.True(t, sign.Verify(data[:], nodePub)) } // TestComputeFee tests fee calculation based on the outgoing amt. @@ -4995,9 +4710,7 @@ func TestComputeFee(t *testing.T) { ) fee := policy.ComputeFee(outgoingAmt) - if fee != expectedFee { - t.Fatalf("expected fee %v, got %v", expectedFee, fee) - } + require.Equal(t, expectedFee, fee) } // TestBatchedAddChannelEdge asserts that BatchedAddChannelEdge properly diff --git a/graph/db/reject_cache_test.go b/graph/db/reject_cache_test.go index c526f487b..e97a37a61 100644 --- a/graph/db/reject_cache_test.go +++ b/graph/db/reject_cache_test.go @@ -1,10 +1,10 @@ package graphdb import ( - "reflect" "testing" "github.com/lightningnetwork/lnd/lnwire" + "github.com/stretchr/testify/require" ) // TestRejectCache checks the behavior of the rejectCache with respect to insertion, @@ -18,9 +18,7 @@ func TestRejectCache(t *testing.T) { // As a sanity check, assert that querying the empty cache does not // return an entry. _, ok := c.get(lnwire.GossipVersion1, 0) - if ok { - t.Fatalf("reject cache should be empty") - } + require.False(t, ok) // Now, fill up the cache entirely. for i := uint64(0); i < cacheSize; i++ { @@ -53,9 +51,7 @@ func TestRejectCache(t *testing.T) { // Assert that exactly one element has been evicted. numEvicted := len(evicted) - if numEvicted != 1 { - t.Fatalf("expected one evicted entry, got: %d", numEvicted) - } + require.Equal(t, 1, numEvicted) // Remove the highest item which initially caused the eviction and // reinsert the element that was evicted prior. @@ -88,15 +84,10 @@ func assertHasEntries(t *testing.T, c *rejectCache, start, end uint64) { for i := start; i < end; i++ { entry, ok := c.get(lnwire.GossipVersion1, i) - if !ok { - t.Fatalf("reject cache should contain chan %d", i) - } + require.True(t, ok) expEntry := entryForInt(i) - if !reflect.DeepEqual(entry, expEntry) { - t.Fatalf("entry mismatch, want: %v, got: %v", - expEntry, entry) - } + require.Equal(t, expEntry, entry) } } From 8dfe747c02fd4c221dc31440850c8d219bf15706 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 25 Feb 2026 08:39:05 +0200 Subject: [PATCH 2/5] graph: migrate tests from Fatal to require helpers Replace remaining fatal-style assertions in graph package tests with direct testify/require helpers. This simplifies control flow and makes test intent clearer by using NoError, True/False, Len, Empty, and Equal/EqualValues assertions. Also remove FailNow-style patterns in favor of specific assertion helpers. --- graph/builder_test.go | 333 +++++++++++++----------------------- graph/notifications_test.go | 148 ++++------------ 2 files changed, 151 insertions(+), 330 deletions(-) diff --git a/graph/builder_test.go b/graph/builder_test.go index acab91ccf..7c1980edf 100644 --- a/graph/builder_test.go +++ b/graph/builder_test.go @@ -109,9 +109,10 @@ func TestIgnoreNodeAnnouncement(t *testing.T) { ) err := ctx.builder.AddNode(t.Context(), node) - if !IsError(err, ErrIgnored) { - t.Fatalf("expected to get ErrIgnore, instead got: %v", err) - } + require.Truef( + t, IsError(err, ErrIgnored), + "expected to get ErrIgnore, instead got: %v", err, + ) } // TestIgnoreChannelEdgePolicyForUnknownChannel checks that a router will @@ -179,14 +180,17 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) { // Attempt to update the edge. This should be ignored, since the edge // is not yet added to the router. err = ctx.builder.UpdateEdge(ctxb, edgePolicy) - if !IsError(err, ErrIgnored) { - t.Fatalf("expected to get ErrIgnore, instead got: %v", err) - } + require.Truef( + t, IsError(err, ErrIgnored), + "expected to get ErrIgnore, instead got: %v", err, + ) // Add the edge. - require.NoErrorf(t, ctx.builder.AddEdge(ctxb, edge), + require.NoErrorf( + t, ctx.builder.AddEdge(ctxb, edge), "expected to be able to add edge to the channel graph, even "+ - "though the vertexes were unknown: %v.", err) + "though the vertexes were unknown: %v.", err, + ) // Now updating the edge policy should succeed. require.NoError(t, ctx.builder.UpdateEdge(ctxb, edgePolicy)) @@ -224,9 +228,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) { bitcoinKey2.SerializeCompressed(), chanValue, height, ) - if err != nil { - t.Fatalf("unable create channel edge: %v", err) - } + require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID1 = chanID.ToUint64() @@ -256,9 +258,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) { bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, height) - if err != nil { - t.Fatalf("unable create channel edge: %v", err) - } + require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID2 = chanID.ToUint64() @@ -298,9 +298,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge1); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge1)) edge2, err := models.NewV1Channel( chanID2, *chaincfg.SimNetParams.GenesisHash, node1.PubKeyBytes, @@ -314,37 +312,21 @@ func TestWakeUpOnStaleBranch(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge2); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge2)) // Check that the fundingTxs are in the graph db. has, isZombie, err := ctx.graph.HasChannelEdge(chanID1) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID1) - } - if !has { - t.Fatalf("could not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.NoError(t, err) + require.True(t, has) + require.False(t, isZombie) has, isZombie, err = ctx.graph.HasChannelEdge(chanID2) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID2) - } - if !has { - t.Fatalf("could not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.NoError(t, err) + require.True(t, has) + require.False(t, isZombie) // Stop the router, so we can reorg the chain while its offline. - if err := ctx.builder.Stop(); err != nil { - t.Fatalf("unable to stop router: %v", err) - } + require.NoError(t, ctx.builder.Stop()) // Create a 15 block fork. for i := uint32(1); i <= 15; i++ { @@ -380,33 +362,20 @@ func TestWakeUpOnStaleBranch(t *testing.T) { require.NoError(t, err) // It should resync to the longer chain on startup. - if err := router.Start(); err != nil { - t.Fatalf("unable to start router: %v", err) - } + require.NoError(t, router.Start()) // The channel with chanID2 should not be in the database anymore, // since it is not confirmed on the longest chain. chanID1 should // still be. has, isZombie, err = ctx.graph.HasChannelEdge(chanID1) require.NoError(t, err) - - if !has { - t.Fatalf("did not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.True(t, has) + require.False(t, isZombie) has, isZombie, err = ctx.graph.HasChannelEdge(chanID2) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID2) - } - if has { - t.Fatalf("found edge in graph") - } - if isZombie { - t.Fatal("reorged edge should not be marked as zombie") - } + require.NoError(t, err) + require.False(t, has) + require.False(t, isZombie) } // TestDisconnectedBlocks checks that the router handles a reorg happening when @@ -435,9 +404,7 @@ func TestDisconnectedBlocks(t *testing.T) { bitcoinKey2.SerializeCompressed(), chanValue, height, ) - if err != nil { - t.Fatalf("unable create channel edge: %v", err) - } + require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID1 = chanID.ToUint64() @@ -467,9 +434,7 @@ func TestDisconnectedBlocks(t *testing.T) { bitcoinKey2.SerializeCompressed(), chanValue, height, ) - if err != nil { - t.Fatalf("unable create channel edge: %v", err) - } + require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID2 = chanID.ToUint64() @@ -508,9 +473,7 @@ func TestDisconnectedBlocks(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge1); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge1)) edge2, err := models.NewV1Channel( chanID2, *chaincfg.SimNetParams.GenesisHash, node1.PubKeyBytes, @@ -522,32 +485,18 @@ func TestDisconnectedBlocks(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge2); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge2)) // Check that the fundingTxs are in the graph db. has, isZombie, err := ctx.graph.HasChannelEdge(chanID1) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID1) - } - if !has { - t.Fatalf("could not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.NoError(t, err) + require.True(t, has) + require.False(t, isZombie) has, isZombie, err = ctx.graph.HasChannelEdge(chanID2) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID2) - } - if !has { - t.Fatalf("could not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.NoError(t, err) + require.True(t, has) + require.False(t, isZombie) // Create a 15 block fork. We first let the chainView notify the router // about stale blocks, before sending the now connected blocks. We do @@ -581,26 +530,14 @@ func TestDisconnectedBlocks(t *testing.T) { // chanID2 should not be in the database anymore, since it is not // confirmed on the longest chain. chanID1 should still be. has, isZombie, err = ctx.graph.HasChannelEdge(chanID1) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID1) - } - if !has { - t.Fatalf("did not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.NoError(t, err) + require.True(t, has) + require.False(t, isZombie) has, isZombie, err = ctx.graph.HasChannelEdge(chanID2) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID2) - } - if has { - t.Fatalf("found edge in graph") - } - if isZombie { - t.Fatal("reorged edge should not be marked as zombie") - } + require.NoError(t, err) + require.False(t, has) + require.False(t, isZombie) } // TestChansClosedOfflinePruneGraph tests that if channels we know of are @@ -660,23 +597,15 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge1); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge1)) // The router should now be aware of the channel we created above. hasChan, isZombie, err := ctx.graph.HasChannelEdge( chanID1.ToUint64(), ) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID1) - } - if !hasChan { - t.Fatalf("could not find edge in graph") - } - if isZombie { - t.Fatal("edge was marked as zombie") - } + require.NoError(t, err) + require.True(t, hasChan) + require.False(t, isZombie) // With the transaction included, and the router's database state // updated, we'll now mine 5 additional blocks on top of it. @@ -695,15 +624,10 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) { // At this point, our starting height should be 107. _, chainHeight, err := ctx.chain.GetBestBlock() require.NoError(t, err, "unable to get best block") - if chainHeight != 107 { - t.Fatalf("incorrect chain height: expected %v, got %v", - 107, chainHeight) - } + require.EqualValues(t, 107, chainHeight) // Next, we'll "shut down" the router in order to simulate downtime. - if err := ctx.builder.Stop(); err != nil { - t.Fatalf("unable to shutdown router: %v", err) - } + require.NoError(t, ctx.builder.Stop()) // While the router is "offline" we'll mine 5 additional blocks, with // the second block closing the channel we created above. @@ -735,10 +659,7 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) { // At this point, our starting height should be 112. _, chainHeight, err = ctx.chain.GetBestBlock() require.NoError(t, err, "unable to get best block") - if chainHeight != 112 { - t.Fatalf("incorrect chain height: expected %v, got %v", - 112, chainHeight) - } + require.EqualValues(t, 112, chainHeight) // Now we'll re-start the ChannelRouter. It should recognize that it's // behind the main chain and prune all the blocks that it missed while @@ -750,15 +671,9 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) { hasChan, isZombie, err = ctx.graph.HasChannelEdge( chanID1.ToUint64(), ) - if err != nil { - t.Fatalf("error looking for edge: %v", chanID1) - } - if hasChan { - t.Fatalf("channel was found in graph but shouldn't have been") - } - if isZombie { - t.Fatal("closed channel should not be marked as zombie") - } + require.NoError(t, err) + require.False(t, hasChan) + require.False(t, isZombie) } // TestPruneChannelGraphStaleEdges ensures that we properly prune stale edges @@ -857,9 +772,7 @@ func TestPruneChannelGraphStaleEdges(t *testing.T) { testGraph, err := createTestGraphFromChannels( t, true, testChannels, "a", ) - if err != nil { - t.Fatalf("unable to create test graph: %v", err) - } + require.NoError(t, err) const startingHeight = 100 ctx := createTestCtxFromGraphInstance( @@ -871,9 +784,7 @@ func TestPruneChannelGraphStaleEdges(t *testing.T) { // Proceed to prune the channels - only the last one should be // pruned. - if err := ctx.builder.pruneZombieChans(); err != nil { - t.Fatalf("unable to prune zombie channels: %v", err) - } + require.NoError(t, ctx.builder.pruneZombieChans()) // We expect channels that have either both edges stale, or one // edge stale with both known. @@ -1022,9 +933,7 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) { assertChannelsPruned(t, ctx.graph, testChannels, prunedChannel) } - if err := ctx.builder.pruneZombieChans(); err != nil { - t.Fatalf("unable to prune zombie channels: %v", err) - } + require.NoError(t, ctx.builder.pruneZombieChans()) // If we attempted to prune them without AssumeChannelValid being set, // none should be pruned. Otherwise the last channel should still be @@ -1075,16 +984,12 @@ func TestIsStaleNode(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) // Before we add the node, if we query for staleness, we should get // false, as we haven't added the full node. updateTimeStamp := time.Unix(123, 0) - if ctx.builder.IsStaleNode(ctxb, pub1, updateTimeStamp) { - t.Fatalf("incorrectly detected node as stale") - } + require.False(t, ctx.builder.IsStaleNode(ctxb, pub1, updateTimeStamp)) // With the node stub in the database, we'll add the fully node // announcement to the database. @@ -1098,22 +1003,16 @@ func TestIsStaleNode(t *testing.T) { Features: testFeatures.RawFeatureVector, }, ) - if err := ctx.builder.AddNode(t.Context(), n1); err != nil { - t.Fatalf("could not add node: %v", err) - } + require.NoError(t, ctx.builder.AddNode(t.Context(), n1)) // If we use the same timestamp and query for staleness, we should get // true. - if !ctx.builder.IsStaleNode(ctxb, pub1, updateTimeStamp) { - t.Fatalf("failure to detect stale node update") - } + require.True(t, ctx.builder.IsStaleNode(ctxb, pub1, updateTimeStamp)) // If we update the timestamp and once again query for staleness, it // should report false. newTimeStamp := time.Unix(1234, 0) - if ctx.builder.IsStaleNode(ctxb, pub1, newTimeStamp) { - t.Fatalf("incorrectly detected node as stale") - } + require.False(t, ctx.builder.IsStaleNode(ctxb, pub1, newTimeStamp)) } // TestIsKnownEdge tests that the IsKnownEdge method properly detects stale @@ -1155,15 +1054,11 @@ func TestIsKnownEdge(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) // Now that the edge has been inserted, query is the router already // knows of the edge should return true. - if !ctx.builder.IsKnownEdge(*chanID) { - t.Fatalf("router should detect edge as known") - } + require.True(t, ctx.builder.IsKnownEdge(*chanID)) } // TestIsStaleEdgePolicy tests that the IsStaleEdgePolicy properly detects @@ -1198,12 +1093,16 @@ func TestIsStaleEdgePolicy(t *testing.T) { // If we query for staleness before adding the edge, we should get // false. updateTimeStamp := time.Unix(123, 0) - if ctx.builder.IsStaleEdgePolicy(*chanID, updateTimeStamp, 0) { - t.Fatalf("router failed to detect fresh edge policy") - } - if ctx.builder.IsStaleEdgePolicy(*chanID, updateTimeStamp, 1) { - t.Fatalf("router failed to detect fresh edge policy") - } + require.False( + t, ctx.builder.IsStaleEdgePolicy( + *chanID, updateTimeStamp, 0, + ), + ) + require.False( + t, ctx.builder.IsStaleEdgePolicy( + *chanID, updateTimeStamp, 1, + ), + ) edge, err := models.NewV1Channel( chanID.ToUint64(), *chaincfg.SimNetParams.GenesisHash, pub1, @@ -1214,9 +1113,7 @@ func TestIsStaleEdgePolicy(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) // We'll also add two edge policies, one for each direction. edgePolicy := &models.ChannelEdgePolicy{ @@ -1230,9 +1127,7 @@ func TestIsStaleEdgePolicy(t *testing.T) { FeeProportionalMillionths: 10000, } edgePolicy.ChannelFlags = 0 - if err := ctx.builder.UpdateEdge(ctxb, edgePolicy); err != nil { - t.Fatalf("unable to update edge policy: %v", err) - } + require.NoError(t, ctx.builder.UpdateEdge(ctxb, edgePolicy)) edgePolicy = &models.ChannelEdgePolicy{ Version: lnwire.GossipVersion1, @@ -1245,28 +1140,34 @@ func TestIsStaleEdgePolicy(t *testing.T) { FeeProportionalMillionths: 10000, } edgePolicy.ChannelFlags = 1 - if err := ctx.builder.UpdateEdge(ctxb, edgePolicy); err != nil { - t.Fatalf("unable to update edge policy: %v", err) - } + require.NoError(t, ctx.builder.UpdateEdge(ctxb, edgePolicy)) // Now that the edges have been added, an identical (chanID, flag, // timestamp) tuple for each edge should be detected as a stale edge. - if !ctx.builder.IsStaleEdgePolicy(*chanID, updateTimeStamp, 0) { - t.Fatalf("router failed to detect stale edge policy") - } - if !ctx.builder.IsStaleEdgePolicy(*chanID, updateTimeStamp, 1) { - t.Fatalf("router failed to detect stale edge policy") - } + require.True( + t, ctx.builder.IsStaleEdgePolicy( + *chanID, updateTimeStamp, 0, + ), + ) + require.True( + t, ctx.builder.IsStaleEdgePolicy( + *chanID, updateTimeStamp, 1, + ), + ) // If we now update the timestamp for both edges, the router should // detect that this tuple represents a fresh edge. updateTimeStamp = time.Unix(9999, 0) - if ctx.builder.IsStaleEdgePolicy(*chanID, updateTimeStamp, 0) { - t.Fatalf("router failed to detect fresh edge policy") - } - if ctx.builder.IsStaleEdgePolicy(*chanID, updateTimeStamp, 1) { - t.Fatalf("router failed to detect fresh edge policy") - } + require.False( + t, ctx.builder.IsStaleEdgePolicy( + *chanID, updateTimeStamp, 0, + ), + ) + require.False( + t, ctx.builder.IsStaleEdgePolicy( + *chanID, updateTimeStamp, 1, + ), + ) } // TestBlockDifferenceFix tests if when the router is behind on blocks, the @@ -1722,27 +1623,25 @@ func assertChannelsPruned(t *testing.T, graph *graphdb.VersionedGraph, exists, isZombie, err := graph.HasChannelEdge( channel.ChannelID, ) - if err != nil { - t.Fatalf("unable to determine existence of "+ - "channel=%v in the graph: %v", - channel.ChannelID, err) - } - if !shouldPrune && !exists { - t.Fatalf("expected channel=%v to exist within "+ - "the graph", channel.ChannelID) - } - if shouldPrune && exists { - t.Fatalf("expected channel=%v to not exist "+ - "within the graph", channel.ChannelID) - } - if !shouldPrune && isZombie { - t.Fatalf("expected channel=%v to not be marked "+ - "as zombie", channel.ChannelID) - } - if shouldPrune && !isZombie { - t.Fatalf("expected channel=%v to be marked as "+ - "zombie", channel.ChannelID) + require.NoError(t, err) + if shouldPrune { + require.Falsef(t, exists, + "expected channel=%v to not exist within "+ + "the graph", + channel.ChannelID) + require.Truef(t, isZombie, + "expected channel=%v to be marked as zombie", + channel.ChannelID) + + continue } + + require.Truef(t, exists, + "expected channel=%v to exist within the graph", + channel.ChannelID) + require.Falsef(t, isZombie, + "expected channel=%v to not be marked as zombie", + channel.ChannelID) } } diff --git a/graph/notifications_test.go b/graph/notifications_test.go index 20e45026a..340cdaf68 100644 --- a/graph/notifications_test.go +++ b/graph/notifications_test.go @@ -471,9 +471,7 @@ func TestEdgeUpdateNotification(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) // With the channel edge now in place, we'll subscribe for topology // notifications. @@ -490,56 +488,28 @@ func TestEdgeUpdateNotification(t *testing.T) { require.NoError(t, err, "unable to create a random chan policy") edge2.ChannelFlags = 1 - if err := ctx.builder.UpdateEdge(ctxb, edge1); err != nil { - t.Fatalf("unable to add edge update: %v", err) - } - if err := ctx.builder.UpdateEdge(ctxb, edge2); err != nil { - t.Fatalf("unable to add edge update: %v", err) - } + require.NoError(t, ctx.builder.UpdateEdge(ctxb, edge1)) + require.NoError(t, ctx.builder.UpdateEdge(ctxb, edge2)) assertEdgeCorrect := func(t *testing.T, edgeUpdate *graphdb.ChannelEdgeUpdate, edgeAnn *models.ChannelEdgePolicy) { - if edgeUpdate.ChanID != edgeAnn.ChannelID { - t.Fatalf("channel ID of edge doesn't match: "+ - "expected %v, got %v", chanID.ToUint64(), edgeUpdate.ChanID) - } - if edgeUpdate.ChanPoint != *chanPoint { - t.Fatalf("channel don't match: expected %v, got %v", - chanPoint, edgeUpdate.ChanPoint) - } + require.Equal(t, edgeAnn.ChannelID, edgeUpdate.ChanID) + require.Equal(t, *chanPoint, edgeUpdate.ChanPoint) // TODO(roasbeef): this is a hack, needs to be removed // after commitment fees are dynamic. - if edgeUpdate.Capacity != chanValue { - t.Fatalf("capacity of edge doesn't match: "+ - "expected %v, got %v", chanValue, edgeUpdate.Capacity) - } - if edgeUpdate.MinHTLC != edgeAnn.MinHTLC { - t.Fatalf("min HTLC of edge doesn't match: "+ - "expected %v, got %v", edgeAnn.MinHTLC, - edgeUpdate.MinHTLC) - } - if edgeUpdate.MaxHTLC != edgeAnn.MaxHTLC { - t.Fatalf("max HTLC of edge doesn't match: "+ - "expected %v, got %v", edgeAnn.MaxHTLC, - edgeUpdate.MaxHTLC) - } - if edgeUpdate.BaseFee != edgeAnn.FeeBaseMSat { - t.Fatalf("base fee of edge doesn't match: "+ - "expected %v, got %v", edgeAnn.FeeBaseMSat, - edgeUpdate.BaseFee) - } - if edgeUpdate.FeeRate != edgeAnn.FeeProportionalMillionths { - t.Fatalf("fee rate of edge doesn't match: "+ - "expected %v, got %v", edgeAnn.FeeProportionalMillionths, - edgeUpdate.FeeRate) - } - if edgeUpdate.TimeLockDelta != edgeAnn.TimeLockDelta { - t.Fatalf("time lock delta of edge doesn't match: "+ - "expected %v, got %v", edgeAnn.TimeLockDelta, - edgeUpdate.TimeLockDelta) - } + require.EqualValues(t, chanValue, edgeUpdate.Capacity) + require.Equal(t, edgeAnn.MinHTLC, edgeUpdate.MinHTLC) + require.Equal(t, edgeAnn.MaxHTLC, edgeUpdate.MaxHTLC) + require.Equal(t, edgeAnn.FeeBaseMSat, edgeUpdate.BaseFee) + require.Equal( + t, edgeAnn.FeeProportionalMillionths, + edgeUpdate.FeeRate, + ) + require.Equal( + t, edgeAnn.TimeLockDelta, edgeUpdate.TimeLockDelta, + ) require.Equal( t, edgeAnn.ExtraOpaqueData, edgeUpdate.ExtraOpaqueData, ) @@ -563,10 +533,7 @@ func TestEdgeUpdateNotification(t *testing.T) { case ntfn := <-ntfnClient.TopologyChanges: // For each processed announcement we should only receive a // single announcement in a batch. - if len(ntfn.ChannelEdgeUpdates) != 1 { - t.Fatalf("expected 1 notification, instead have %v", - len(ntfn.ChannelEdgeUpdates)) - } + require.Len(t, ntfn.ChannelEdgeUpdates, 1) edgeUpdate := ntfn.ChannelEdgeUpdates[0] nodeVertex := route.NewVertex(edgeUpdate.AdvertisingNode) @@ -669,9 +636,7 @@ func TestNodeUpdateNotification(t *testing.T) { // Adding the edge will add the nodes to the graph, but with no info // except the pubkey known. - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) // Create a new client to receive notifications. ntfnClient, err := ctx.graph.SubscribeTopology() @@ -679,12 +644,8 @@ func TestNodeUpdateNotification(t *testing.T) { // Change network topology by adding the updated info for the two nodes // to the channel router. - if err := ctx.builder.AddNode(ctxb, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } - if err := ctx.builder.AddNode(ctxb, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, ctx.builder.AddNode(ctxb, node1)) + require.NoError(t, ctx.builder.AddNode(ctxb, node2)) assertNodeNtfnCorrect := func(t *testing.T, ann *models.Node, nodeUpdate *graphdb.NetworkNodeUpdate) { @@ -693,15 +654,8 @@ func TestNodeUpdateNotification(t *testing.T) { // The notification received should directly map the // announcement originally sent. - if nodeUpdate.Addresses[0] != ann.Addresses[0] { - t.Fatalf("node address doesn't match: expected %v, got %v", - nodeUpdate.Addresses[0], ann.Addresses[0]) - } - if !nodeUpdate.IdentityKey.IsEqual(nodeKey) { - t.Fatalf("node identity keys don't match: expected %x, "+ - "got %x", nodeKey.SerializeCompressed(), - nodeUpdate.IdentityKey.SerializeCompressed()) - } + require.Equal(t, ann.Addresses[0], nodeUpdate.Addresses[0]) + require.True(t, nodeUpdate.IdentityKey.IsEqual(nodeKey)) featuresBuf := new(bytes.Buffer) require.NoError(t, nodeUpdate.Features.Encode(featuresBuf)) @@ -733,10 +687,7 @@ func TestNodeUpdateNotification(t *testing.T) { case ntfn := <-ntfnClient.TopologyChanges: // For each processed announcement we should only receive a // single announcement in a batch. - if len(ntfn.NodeUpdates) != 1 { - t.Fatalf("expected 1 notification, instead have %v", - len(ntfn.NodeUpdates)) - } + require.Len(t, ntfn.NodeUpdates, 1) nodeUpdate := ntfn.NodeUpdates[0] nodeVertex := route.NewVertex(nodeUpdate.IdentityKey) @@ -774,9 +725,7 @@ func TestNodeUpdateNotification(t *testing.T) { nodeUpdateAnn.LastUpdate = node1.LastUpdate.Add(time.Second) // Add new node topology update to the channel router. - if err := ctx.builder.AddNode(ctxb, &nodeUpdateAnn); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, ctx.builder.AddNode(ctxb, &nodeUpdateAnn)) // Once again a notification should be received reflecting the up to // date node announcement. @@ -784,10 +733,7 @@ func TestNodeUpdateNotification(t *testing.T) { case ntfn := <-ntfnClient.TopologyChanges: // For each processed announcement we should only receive a // single announcement in a batch. - if len(ntfn.NodeUpdates) != 1 { - t.Fatalf("expected 1 notification, instead have %v", - len(ntfn.NodeUpdates)) - } + require.Len(t, ntfn.NodeUpdates, 1) nodeUpdate := ntfn.NodeUpdates[0] assertNodeNtfnCorrect(t, &nodeUpdateAnn, nodeUpdate) @@ -859,17 +805,11 @@ func TestNotificationCancellation(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) - if err := ctx.builder.AddNode(ctxb, node1); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, ctx.builder.AddNode(ctxb, node1)) - if err := ctx.builder.AddNode(ctxb, node2); err != nil { - t.Fatalf("unable to add node: %v", err) - } + require.NoError(t, ctx.builder.AddNode(ctxb, node2)) select { // The notifications shouldn't be sent, however, the channel should be @@ -940,9 +880,7 @@ func TestChannelCloseNotification(t *testing.T) { ) require.NoError(t, err) - if err := ctx.builder.AddEdge(ctxb, edge); err != nil { - t.Fatalf("unable to add edge: %v", err) - } + require.NoError(t, ctx.builder.AddEdge(ctxb, edge)) // With the channel edge now in place, we'll subscribe for topology // notifications. @@ -975,35 +913,19 @@ func TestChannelCloseNotification(t *testing.T) { // We should have exactly a single notification for the channel // "closed" above. closedChans := ntfn.ClosedChannels - if len(closedChans) == 0 { - t.Fatal("close channel ntfn not populated") - } else if len(closedChans) != 1 { - t.Fatalf("only one should have been detected as closed, "+ - "instead %v were", len(closedChans)) - } + require.NotEmpty(t, closedChans) + require.Len(t, closedChans, 1) // Ensure that the notification we received includes the proper // update the for the channel that was closed in the generated // block. closedChan := closedChans[0] - if closedChan.ChanID != chanID.ToUint64() { - t.Fatalf("channel ID of closed channel doesn't match: "+ - "expected %v, got %v", chanID.ToUint64(), closedChan.ChanID) - } + require.Equal(t, chanID.ToUint64(), closedChan.ChanID) // TODO(roasbeef): this is a hack, needs to be removed // after commitment fees are dynamic. - if closedChan.Capacity != chanValue { - t.Fatalf("capacity of closed channel doesn't match: "+ - "expected %v, got %v", chanValue, closedChan.Capacity) - } - if closedChan.ClosedHeight != blockHeight { - t.Fatalf("close height of closed channel doesn't match: "+ - "expected %v, got %v", blockHeight, closedChan.ClosedHeight) - } - if closedChan.ChanPoint != *chanUtxo { - t.Fatalf("chan point of closed channel doesn't match: "+ - "expected %v, got %v", chanUtxo, closedChan.ChanPoint) - } + require.EqualValues(t, chanValue, closedChan.Capacity) + require.Equal(t, blockHeight, closedChan.ClosedHeight) + require.Equal(t, *chanUtxo, closedChan.ChanPoint) case <-time.After(time.Second * 5): t.Fatal("notification not sent") From 963975135cde875c52df7ac324601ccf7ca6e825 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 25 Feb 2026 08:58:12 +0200 Subject: [PATCH 3/5] graph/tests: make randEdgePolicy assert internally Update randEdgePolicy to take a testing handle, mark itself as a helper, and assert internal packing errors directly with require. Call sites now receive only the policy value without plumbing an error through immediate require.NoError checks. --- graph/notifications_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/graph/notifications_test.go b/graph/notifications_test.go index 340cdaf68..bef6ebdce 100644 --- a/graph/notifications_test.go +++ b/graph/notifications_test.go @@ -98,8 +98,10 @@ func createTestNode(t *testing.T) *models.Node { return n } -func randEdgePolicy(chanID *lnwire.ShortChannelID, - node *models.Node) (*models.ChannelEdgePolicy, error) { +func randEdgePolicy(t testing.TB, chanID *lnwire.ShortChannelID, + node *models.Node) *models.ChannelEdgePolicy { + + t.Helper() InboundFee := models.InboundFee{ Base: prand.Int31() * -1, @@ -108,9 +110,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID, inboundFee := InboundFee.ToWire() var extraOpaqueData lnwire.ExtraOpaqueData - if err := extraOpaqueData.PackRecords(&inboundFee); err != nil { - return nil, err - } + require.NoError(t, extraOpaqueData.PackRecords(&inboundFee)) return &models.ChannelEdgePolicy{ Version: lnwire.GossipVersion1, @@ -125,7 +125,7 @@ func randEdgePolicy(chanID *lnwire.ShortChannelID, ToNode: node.PubKeyBytes, InboundFee: fn.Some(inboundFee), ExtraOpaqueData: extraOpaqueData, - }, nil + } } func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte, @@ -480,12 +480,10 @@ func TestEdgeUpdateNotification(t *testing.T) { // Create random policy edges that are stemmed to the channel id // created above. - edge1, err := randEdgePolicy(chanID, node1) - require.NoError(t, err, "unable to create a random chan policy") + edge1 := randEdgePolicy(t, chanID, node1) edge1.ChannelFlags = 0 - edge2, err := randEdgePolicy(chanID, node2) - require.NoError(t, err, "unable to create a random chan policy") + edge2 := randEdgePolicy(t, chanID, node2) edge2.ChannelFlags = 1 require.NoError(t, ctx.builder.UpdateEdge(ctxb, edge1)) From ceb939ebb1716dc0c67868a3db93496c16a9dd75 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 25 Feb 2026 09:00:03 +0200 Subject: [PATCH 4/5] graph/tests: make createChannelEdge assert internally Update createChannelEdge to take a testing handle, mark itself as a helper, and call require.NoError for funding script generation. All call sites now consume only returned values and no longer plumb an immediately-asserted error value. --- graph/builder_test.go | 50 +++++++++++++++---------------------- graph/notifications_test.go | 32 +++++++++++------------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/graph/builder_test.go b/graph/builder_test.go index 7c1980edf..e561d25b1 100644 --- a/graph/builder_test.go +++ b/graph/builder_test.go @@ -54,11 +54,10 @@ func TestAddProof(t *testing.T) { // In order to be able to add the edge we should have a valid funding // UTXO within the blockchain. - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), 100, 0, ) - require.NoError(t, err, "unable create channel edge") fundingBlock := &wire.MsgBlock{ Transactions: []*wire.MsgTx{fundingTx}, } @@ -142,11 +141,10 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) { // Add the edge between the two unknown nodes to the graph, and check // that the nodes are found after the fact. - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), 10000, 500, ) - require.NoError(t, err, "unable to create channel edge") fundingBlock := &wire.MsgBlock{ Transactions: []*wire.MsgTx{fundingTx}, } @@ -223,12 +221,11 @@ func TestWakeUpOnStaleBranch(t *testing.T) { } height := startingBlockHeight + i if i == 5 { - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, height, ) - require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID1 = chanID.ToUint64() @@ -254,11 +251,10 @@ func TestWakeUpOnStaleBranch(t *testing.T) { } height := uint32(forkHeight) + i if i == 5 { - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, height) - require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID2 = chanID.ToUint64() @@ -399,12 +395,11 @@ func TestDisconnectedBlocks(t *testing.T) { } height := startingBlockHeight + i if i == 5 { - _, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + _, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, height, ) - require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID1 = chanID.ToUint64() @@ -429,12 +424,11 @@ func TestDisconnectedBlocks(t *testing.T) { } height := uint32(forkHeight) + i if i == 5 { - _, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + _, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, height, ) - require.NoError(t, err) block.Transactions = append(block.Transactions, fundingTx) chanID2 = chanID.ToUint64() @@ -557,12 +551,11 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) { Transactions: []*wire.MsgTx{}, } nextHeight := startingBlockHeight + 1 - script, fundingTx1, chanUTXO, chanID1, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx1, chanUTXO, chanID1 := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, uint32(nextHeight), ) - require.NoError(t, err, "unable create channel edge") block102.Transactions = append(block102.Transactions, fundingTx1) ctx.chain.addBlock(block102, uint32(nextHeight), rand.Uint32()) ctx.chain.setBestBlock(int32(nextHeight)) @@ -964,12 +957,11 @@ func TestIsStaleNode(t *testing.T) { copy(pub1[:], priv1.PubKey().SerializeCompressed()) copy(pub2[:], priv2.PubKey().SerializeCompressed()) - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), 10000, 500, ) - require.NoError(t, err, "unable to create channel edge") fundingBlock := &wire.MsgBlock{ Transactions: []*wire.MsgTx{fundingTx}, } @@ -1033,12 +1025,11 @@ func TestIsKnownEdge(t *testing.T) { copy(pub1[:], priv1.PubKey().SerializeCompressed()) copy(pub2[:], priv2.PubKey().SerializeCompressed()) - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), 10000, 500, ) - require.NoError(t, err, "unable to create channel edge") fundingBlock := &wire.MsgBlock{ Transactions: []*wire.MsgTx{fundingTx}, } @@ -1079,12 +1070,11 @@ func TestIsStaleEdgePolicy(t *testing.T) { copy(pub1[:], priv1.PubKey().SerializeCompressed()) copy(pub2[:], priv2.PubKey().SerializeCompressed()) - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), 10000, 500, ) - require.NoError(t, err, "unable to create channel edge") fundingBlock := &wire.MsgBlock{ Transactions: []*wire.MsgTx{fundingTx}, } diff --git a/graph/notifications_test.go b/graph/notifications_test.go index bef6ebdce..f8bc0f21f 100644 --- a/graph/notifications_test.go +++ b/graph/notifications_test.go @@ -128,9 +128,11 @@ func randEdgePolicy(t testing.TB, chanID *lnwire.ShortChannelID, } } -func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte, +func createChannelEdge(t testing.TB, bitcoinKey1, bitcoinKey2 []byte, chanValue btcutil.Amount, fundingHeight uint32) ([]byte, *wire.MsgTx, - *wire.OutPoint, *lnwire.ShortChannelID, error) { + *wire.OutPoint, *lnwire.ShortChannelID) { + + t.Helper() fundingTx := wire.NewMsgTx(2) script, tx, err := input.GenFundingPkScript( @@ -138,9 +140,7 @@ func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte, bitcoinKey2, int64(chanValue), ) - if err != nil { - return nil, nil, nil, nil, err - } + require.NoError(t, err) fundingTx.TxOut = append(fundingTx.TxOut, tx) chanUtxo := wire.OutPoint{ @@ -155,7 +155,7 @@ func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte, TxPosition: 0, } - return script, fundingTx, &chanUtxo, chanID, nil + return script, fundingTx, &chanUtxo, chanID } type mockChain struct { @@ -429,11 +429,10 @@ func TestEdgeUpdateNotification(t *testing.T) { // First we'll create the utxo for the channel to be "closed" const chanValue = 10000 - script, fundingTx, chanPoint, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, chanPoint, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, 0, ) - require.NoError(t, err, "unable create channel edge") // We'll also add a record for the block that included our funding // transaction. @@ -589,12 +588,11 @@ func TestNodeUpdateNotification(t *testing.T) { // We only accept node announcements from nodes having a known channel, // so create one now. const chanValue = 10000 - script, fundingTx, _, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, _, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, startingBlockHeight, ) - require.NoError(t, err, "unable create channel edge") // We'll also add a record for the block that included our funding // transaction. @@ -756,12 +754,11 @@ func TestNotificationCancellation(t *testing.T) { // We'll create the utxo for a new channel. const chanValue = 10000 - script, fundingTx, chanPoint, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, chanPoint, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, startingBlockHeight, ) - require.NoError(t, err, "unable create channel edge") // We'll also add a record for the block that included our funding // transaction. @@ -835,12 +832,11 @@ func TestChannelCloseNotification(t *testing.T) { // First we'll create the utxo for the channel to be "closed" const chanValue = 10000 - script, fundingTx, chanUtxo, chanID, err := createChannelEdge( - bitcoinKey1.SerializeCompressed(), + script, fundingTx, chanUtxo, chanID := createChannelEdge( + t, bitcoinKey1.SerializeCompressed(), bitcoinKey2.SerializeCompressed(), chanValue, startingBlockHeight, ) - require.NoError(t, err, "unable create channel edge") // We'll also add a record for the block that included our funding // transaction. From 160c2a9f68e2ff6cbeaf2b8a21ef48fea234bd53 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 25 Feb 2026 09:02:51 +0200 Subject: [PATCH 5/5] graph/db tests: make compareEdgePolicies assert internally Convert compareEdgePolicies into a test helper that accepts a testing handle and performs assertions directly. Update call sites to invoke the helper instead of threading errors into immediate require.NoError checks. --- graph/db/graph_test.go | 51 ++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 9dd5a6adc..aa0e02b3e 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -11,7 +11,6 @@ import ( "math" prand "math/rand" "net" - "reflect" "sync" "testing" "time" @@ -1196,8 +1195,8 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { // been inserted properly. dbEdgeInfo, dbEdge1, dbEdge2, err := graph.FetchChannelEdgesByID(chanID) require.NoError(t, err, "unable to fetch channel by ID") - require.NoError(t, compareEdgePolicies(dbEdge1, edge1)) - require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) + compareEdgePolicies(t, dbEdge1, edge1) + compareEdgePolicies(t, dbEdge2, edge2) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) // Next, attempt to query the channel edges according to the outpoint @@ -1206,8 +1205,8 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { &outpoint, ) require.NoError(t, err, "unable to fetch channel by ID") - require.NoError(t, compareEdgePolicies(dbEdge1, edge1)) - require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) + compareEdgePolicies(t, dbEdge1, edge1) + compareEdgePolicies(t, dbEdge2, edge2) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) } @@ -1269,12 +1268,8 @@ func testEdgePolicyCRUD(t *testing.T, v lnwire.GossipVersion) { policy1 *models.ChannelEdgePolicy, policy2 *models.ChannelEdgePolicy) error { - require.NoError( - t, compareEdgePolicies(edge1, policy1), - ) - require.NoError( - t, compareEdgePolicies(edge2, policy2), - ) + compareEdgePolicies(t, edge1, policy1) + compareEdgePolicies(t, edge2, policy2) return nil }, func() {}, @@ -2521,15 +2516,12 @@ func TestChanUpdatesInHorizon(t *testing.T) { assertEdgeInfoEqual(t, chanExp.Info, chanRet.Info) - err = compareEdgePolicies( - chanExp.Policy1, chanRet.Policy1, + compareEdgePolicies( + t, chanExp.Policy1, chanRet.Policy1, ) - require.NoError(t, err) - - err = compareEdgePolicies( - chanExp.Policy2, chanRet.Policy2, + compareEdgePolicies( + t, chanExp.Policy2, chanRet.Policy2, ) - require.NoError(t, err) } } } @@ -3773,10 +3765,8 @@ func testFetchChanInfos(t *testing.T, v lnwire.GossipVersion) { require.Len(t, resp, len(edges)) for i := 0; i < len(resp); i++ { - err := compareEdgePolicies(resp[i].Policy1, edges[i].Policy1) - require.NoError(t, err) - err = compareEdgePolicies(resp[i].Policy2, edges[i].Policy2) - require.NoError(t, err) + compareEdgePolicies(t, resp[i].Policy1, edges[i].Policy1) + compareEdgePolicies(t, resp[i].Policy2, edges[i].Policy2) assertEdgeInfoEqual(t, resp[i].Info, edges[i].Info) } } @@ -4482,7 +4472,7 @@ func TestEdgePolicyMissingMaxHTLC(t *testing.T) { // The first edge should have a nil-policy returned require.Nil(t, dbEdge1) - require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) + compareEdgePolicies(t, dbEdge2, edge2) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) // Now add the original, unmodified edge policy, and make sure the edge @@ -4491,8 +4481,8 @@ func TestEdgePolicyMissingMaxHTLC(t *testing.T) { dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByID(chanID) require.NoError(t, err, "unable to fetch channel by ID") - require.NoError(t, compareEdgePolicies(dbEdge1, edge1)) - require.NoError(t, compareEdgePolicies(dbEdge2, edge2)) + compareEdgePolicies(t, dbEdge1, edge1) + compareEdgePolicies(t, dbEdge2, edge2) assertEdgeInfoEqual(t, dbEdgeInfo, edgeInfo) } @@ -4624,7 +4614,9 @@ func compareNodes(t *testing.T, a, b *models.Node) { // compareEdgePolicies compares two ChannelEdgePolicy values for semantic // equality after normalizing version-specific/backend-specific differences. -func compareEdgePolicies(a, b *models.ChannelEdgePolicy) error { +func compareEdgePolicies(t testing.TB, a, b *models.ChannelEdgePolicy) { + t.Helper() + //nolint:ll normalize := func(p *models.ChannelEdgePolicy) *models.ChannelEdgePolicy { if p == nil { @@ -4660,12 +4652,7 @@ func compareEdgePolicies(a, b *models.ChannelEdgePolicy) error { normalizedA := normalize(a) normalizedB := normalize(b) - if !reflect.DeepEqual(normalizedA, normalizedB) { - return fmt.Errorf("expected %v, got %v", normalizedA, - normalizedB) - } - - return nil + require.Equal(t, normalizedA, normalizedB) } // TestLightningNodeSigVerification checks that we can use the Node's