From d27ff34b045b598c4a42fbac1e11e5daa22052c8 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 24 Oct 2024 23:10:41 +0800 Subject: [PATCH] lntest+itest: rename `AssertNumEdges` to `AssertNumActiveEdges` To properly reflect what the assertion is. --- itest/lnd_channel_graph_test.go | 6 ++--- itest/lnd_mpp_test.go | 2 +- itest/lnd_open_channel_test.go | 4 +-- itest/lnd_route_blinding_test.go | 6 ++--- itest/lnd_routing_test.go | 12 ++++----- lntest/harness_assertion.go | 45 +++++++++++++++++++++++++++++--- 6 files changed, 57 insertions(+), 18 deletions(-) diff --git a/itest/lnd_channel_graph_test.go b/itest/lnd_channel_graph_test.go index cf97bcf39..566d02c9c 100644 --- a/itest/lnd_channel_graph_test.go +++ b/itest/lnd_channel_graph_test.go @@ -237,17 +237,17 @@ func testUnannouncedChannels(ht *lntest.HarnessTest) { fundingChanPoint := ht.WaitForChannelOpenEvent(chanOpenUpdate) // Alice should have 1 edge in her graph. - ht.AssertNumEdges(alice, 1, true) + ht.AssertNumActiveEdges(alice, 1, true) // Channels should not be announced yet, hence Alice should have no // announced edges in her graph. - ht.AssertNumEdges(alice, 0, false) + ht.AssertNumActiveEdges(alice, 0, false) // Mine 4 more blocks, and check that the channel is now announced. ht.MineBlocks(4) // Give the network a chance to learn that auth proof is confirmed. - ht.AssertNumEdges(alice, 1, false) + ht.AssertNumActiveEdges(alice, 1, false) // Close the channel used during the test. ht.CloseChannel(alice, fundingChanPoint) diff --git a/itest/lnd_mpp_test.go b/itest/lnd_mpp_test.go index b5cd147dd..37da783c1 100644 --- a/itest/lnd_mpp_test.go +++ b/itest/lnd_mpp_test.go @@ -299,7 +299,7 @@ func (m *mppTestScenario) openChannels(r *mppOpenChannelRequest) { } // Each node should have exactly 6 edges. - m.ht.AssertNumEdges(hn, len(m.channelPoints), false) + m.ht.AssertNumActiveEdges(hn, len(m.channelPoints), false) } } diff --git a/itest/lnd_open_channel_test.go b/itest/lnd_open_channel_test.go index a196d71c5..48e68fba0 100644 --- a/itest/lnd_open_channel_test.go +++ b/itest/lnd_open_channel_test.go @@ -84,7 +84,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) { ht.AssertTopologyChannelOpen(bob, chanPoint) // Alice should now have 1 edge in her graph. - ht.AssertNumEdges(alice, 1, true) + ht.AssertNumActiveEdges(alice, 1, true) // Now we disconnect Alice's chain backend from the original miner, and // connect the two miners together. Since the temporary miner knows @@ -112,7 +112,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) { // Since the fundingtx was reorged out, Alice should now have no edges // in her graph. - ht.AssertNumEdges(alice, 0, true) + ht.AssertNumActiveEdges(alice, 0, true) // Cleanup by mining the funding tx again, then closing the channel. block = ht.MineBlocksAndAssertNumTxes(1, 1)[0] diff --git a/itest/lnd_route_blinding_test.go b/itest/lnd_route_blinding_test.go index ba5d40ec8..b921103ac 100644 --- a/itest/lnd_route_blinding_test.go +++ b/itest/lnd_route_blinding_test.go @@ -985,7 +985,7 @@ func testMPPToSingleBlindedPath(ht *lntest.HarnessTest) { } // Each node should have exactly numPublic edges. - ht.AssertNumEdges(hn, numPublic, false) + ht.AssertNumActiveEdges(hn, numPublic, false) } // Make Dave create an invoice with a blinded path for Alice to pay. @@ -1156,7 +1156,7 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) { } // Each node should have exactly 5 edges. - ht.AssertNumEdges(hn, len(channelPoints), false) + ht.AssertNumActiveEdges(hn, len(channelPoints), false) } // Make Dave create an invoice with a blinded path for Alice to pay. @@ -1325,7 +1325,7 @@ func testMPPToMultipleBlindedPaths(ht *lntest.HarnessTest) { } // Each node should have exactly 5 edges. - ht.AssertNumEdges(hn, len(channelPoints), false) + ht.AssertNumActiveEdges(hn, len(channelPoints), false) } // Ok now make a payment that must be split to succeed. diff --git a/itest/lnd_routing_test.go b/itest/lnd_routing_test.go index c2fc6886b..343cb2b99 100644 --- a/itest/lnd_routing_test.go +++ b/itest/lnd_routing_test.go @@ -591,12 +591,12 @@ func testPrivateChannels(ht *lntest.HarnessTest) { // Carol and Alice should know about 4, while Bob and Dave should only // know about 3, since one channel is private. - ht.AssertNumEdges(alice, 4, true) - ht.AssertNumEdges(alice, 3, false) - ht.AssertNumEdges(bob, 3, true) - ht.AssertNumEdges(carol, 4, true) - ht.AssertNumEdges(carol, 3, false) - ht.AssertNumEdges(dave, 3, true) + ht.AssertNumActiveEdges(alice, 4, true) + ht.AssertNumActiveEdges(alice, 3, false) + ht.AssertNumActiveEdges(bob, 3, true) + ht.AssertNumActiveEdges(carol, 4, true) + ht.AssertNumActiveEdges(carol, 3, false) + ht.AssertNumActiveEdges(dave, 3, true) // Close all channels. ht.CloseChannel(alice, chanPointAlice) diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index d6c739177..3d1039846 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -240,9 +240,9 @@ func (h *HarnessTest) EnsureConnected(a, b *node.HarnessNode) { h.AssertPeerConnected(b, a) } -// AssertNumEdges checks that an expected number of edges can be found in the -// node specified. -func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode, +// AssertNumActiveEdges checks that an expected number of active edges can be +// found in the node specified. +func (h *HarnessTest) AssertNumActiveEdges(hn *node.HarnessNode, expected int, includeUnannounced bool) []*lnrpc.ChannelEdge { var edges []*lnrpc.ChannelEdge @@ -293,6 +293,45 @@ func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode, return edges } +// AssertNumEdges checks that an expected number of edges can be found in the +// node specified. +func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode, + expected int, includeUnannounced bool) []*lnrpc.ChannelEdge { + + var edges []*lnrpc.ChannelEdge + + old := hn.State.Edge.Public + if includeUnannounced { + old = hn.State.Edge.Total + } + + err := wait.NoError(func() error { + req := &lnrpc.ChannelGraphRequest{ + IncludeUnannounced: includeUnannounced, + } + resp := hn.RPC.DescribeGraph(req) + total := len(resp.Edges) + + if total-old == expected { + if expected != 0 { + // NOTE: assume edges come in ascending order + // that the old edges are at the front of the + // slice. + edges = resp.Edges[old:] + } + + return nil + } + + return errNumNotMatched(hn.Name(), "num of channel edges", + expected, total-old, total, old) + }, DefaultTimeout) + + require.NoError(h, err, "timeout while checking for edges") + + return edges +} + // ReceiveOpenChannelUpdate waits until a message is received on the stream or // the timeout is reached. func (h *HarnessTest) ReceiveOpenChannelUpdate(