itest: refactor testNodeAnnouncement

This commit is contained in:
yyforyongyu 2022-08-04 06:49:43 +08:00
parent 7029698c16
commit c990e053c6
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
3 changed files with 19 additions and 59 deletions

View file

@ -171,4 +171,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "graph topology notifications", Name: "graph topology notifications",
TestFunc: testGraphTopologyNotifications, TestFunc: testGraphTopologyNotifications,
}, },
{
Name: "node announcement",
TestFunc: testNodeAnnouncement,
},
} }

View file

@ -370,17 +370,15 @@ func testGraphTopologyNtfns(ht *lntemp.HarnessTest, pinned bool) {
// testNodeAnnouncement ensures that when a node is started with one or more // testNodeAnnouncement ensures that when a node is started with one or more
// external IP addresses specified on the command line, that those addresses // external IP addresses specified on the command line, that those addresses
// announced to the network and reported in the network graph. // announced to the network and reported in the network graph.
func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) { func testNodeAnnouncement(ht *lntemp.HarnessTest) {
ctxb := context.Background() alice, bob := ht.Alice, ht.Bob
aliceSub := subscribeGraphNotifications(ctxb, t, net.Alice)
defer close(aliceSub.quit)
advertisedAddrs := []string{ advertisedAddrs := []string{
"192.168.1.1:8333", "192.168.1.1:8333",
"[2001:db8:85a3:8d3:1319:8a2e:370:7348]:8337", "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:8337",
"bkb6azqggsaiskzi.onion:9735", "bkb6azqggsaiskzi.onion:9735",
"fomvuglh6h6vcag73xo5t5gv56ombih3zr2xvplkpbfd7wrog4swjwid.onion:1234", "fomvuglh6h6vcag73xo5t5gv56ombih3zr2xvplkpbfd7wrog4swj" +
"wid.onion:1234",
} }
var lndArgs []string var lndArgs []string
@ -388,29 +386,17 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
lndArgs = append(lndArgs, "--externalip="+addr) lndArgs = append(lndArgs, "--externalip="+addr)
} }
dave := net.NewNode(t.t, "Dave", lndArgs) dave := ht.NewNode("Dave", lndArgs)
defer shutdownAndAssert(net, t, dave)
// We must let Dave have an open channel before he can send a node // We must let Dave have an open channel before he can send a node
// announcement, so we open a channel with Bob, // announcement, so we open a channel with Bob,
net.ConnectNodes(t.t, net.Bob, dave) ht.ConnectNodes(bob, dave)
// Alice shouldn't receive any new updates yet since the channel has yet
// to be opened.
select {
case <-aliceSub.updateChan:
t.Fatalf("received unexpected update from dave")
case <-time.After(time.Second):
}
// We'll then go ahead and open a channel between Bob and Dave. This // We'll then go ahead and open a channel between Bob and Dave. This
// ensures that Alice receives the node announcement from Bob as part of // ensures that Alice receives the node announcement from Bob as part of
// the announcement broadcast. // the announcement broadcast.
chanPoint := openChannelAndAssert( chanPoint := ht.OpenChannel(
t, net, net.Bob, dave, bob, dave, lntemp.OpenChannelParams{Amt: 1000000},
lntest.OpenChannelParams{
Amt: 1000000,
},
) )
assertAddrs := func(addrsFound []string, targetAddrs ...string) { assertAddrs := func(addrsFound []string, targetAddrs ...string) {
@ -420,45 +406,20 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
} }
for _, addr := range targetAddrs { for _, addr := range targetAddrs {
if _, ok := addrs[addr]; !ok { _, ok := addrs[addr]
t.Fatalf("address %v not found in node "+ require.True(ht, ok, "address %v not found in node "+
"announcement", addr) "announcement", addr)
}
} }
} }
waitForAddrsInUpdate := func(graphSub graphSubscription,
nodePubKey string, targetAddrs ...string) {
for {
select {
case graphUpdate := <-graphSub.updateChan:
for _, update := range graphUpdate.NodeUpdates {
if update.IdentityKey == nodePubKey {
assertAddrs(
update.Addresses, // nolint:staticcheck
targetAddrs...,
)
return
}
}
case err := <-graphSub.errChan:
t.Fatalf("unable to recv graph update: %v", err)
case <-time.After(defaultTimeout):
t.Fatalf("did not receive node ann update")
}
}
}
// We'll then wait for Alice to receive Dave's node announcement // We'll then wait for Alice to receive Dave's node announcement
// including the expected advertised addresses from Bob since they // including the expected advertised addresses from Bob since they
// should already be connected. // should already be connected.
waitForAddrsInUpdate( allUpdates := ht.AssertNumNodeAnns(alice, dave.PubKeyStr, 1)
aliceSub, dave.PubKeyStr, advertisedAddrs..., nodeUpdate := allUpdates[len(allUpdates)-1]
) assertAddrs(nodeUpdate.Addresses, advertisedAddrs...)
// Close the channel between Bob and Dave. // Close the channel between Bob and Dave.
closeChannelAndAssert(t, net, net.Bob, chanPoint, false) ht.CloseChannel(bob, chanPoint)
} }
// graphSubscription houses the proxied update and error chans for a node's // graphSubscription houses the proxied update and error chans for a node's

View file

@ -72,11 +72,6 @@ var allTestCases = []*testCase{
name: "multi-hop htlc error propagation", name: "multi-hop htlc error propagation",
test: testHtlcErrorPropagation, test: testHtlcErrorPropagation,
}, },
// TODO(roasbeef): multi-path integration test
{
name: "node announcement",
test: testNodeAnnouncement,
},
{ {
name: "derive shared key", name: "derive shared key",
test: testDeriveSharedKey, test: testDeriveSharedKey,