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")