lntest/graph_top: remove dependence on net.Alice/Bob

This commit is contained in:
Conner Fromknecht 2021-01-29 00:14:29 -08:00
parent fcd5cb625a
commit ba67f3ecaa
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -10335,16 +10335,39 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
const chanAmt = funding.MaxBtcFundingAmount const chanAmt = funding.MaxBtcFundingAmount
alice, err := net.NewNode("alice", nil)
require.NoError(t.t, err)
defer shutdownAndAssert(net, t, alice)
bob, err := net.NewNode("bob", nil)
require.NoError(t.t, err)
defer shutdownAndAssert(net, t, bob)
// Connect Alice and Bob.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.EnsureConnected(ctxt, alice, bob)
require.NoError(t.t, err)
// Alice stimmy.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, alice)
require.NoError(t.t, err)
// Bob stimmy.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, bob)
require.NoError(t.t, err)
// Let Alice subscribe to graph notifications. // Let Alice subscribe to graph notifications.
graphSub := subscribeGraphNotifications( graphSub := subscribeGraphNotifications(
t, ctxb, net.Alice, t, ctxb, alice,
) )
defer close(graphSub.quit) defer close(graphSub.quit)
// Open a new channel between Alice and Bob. // Open a new channel between Alice and Bob.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, ctxt, t, net, alice, bob,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@ -10364,15 +10387,15 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
// message. // message.
for _, chanUpdate := range graphUpdate.ChannelUpdates { for _, chanUpdate := range graphUpdate.ChannelUpdates {
switch chanUpdate.AdvertisingNode { switch chanUpdate.AdvertisingNode {
case net.Alice.PubKeyStr: case alice.PubKeyStr:
case net.Bob.PubKeyStr: case bob.PubKeyStr:
default: default:
t.Fatalf("unknown advertising node: %v", t.Fatalf("unknown advertising node: %v",
chanUpdate.AdvertisingNode) chanUpdate.AdvertisingNode)
} }
switch chanUpdate.ConnectingNode { switch chanUpdate.ConnectingNode {
case net.Alice.PubKeyStr: case alice.PubKeyStr:
case net.Bob.PubKeyStr: case bob.PubKeyStr:
default: default:
t.Fatalf("unknown connecting node: %v", t.Fatalf("unknown connecting node: %v",
chanUpdate.ConnectingNode) chanUpdate.ConnectingNode)
@ -10388,8 +10411,8 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
for _, nodeUpdate := range graphUpdate.NodeUpdates { for _, nodeUpdate := range graphUpdate.NodeUpdates {
switch nodeUpdate.IdentityKey { switch nodeUpdate.IdentityKey {
case net.Alice.PubKeyStr: case alice.PubKeyStr:
case net.Bob.PubKeyStr: case bob.PubKeyStr:
default: default:
t.Fatalf("unknown node: %v", t.Fatalf("unknown node: %v",
nodeUpdate.IdentityKey) nodeUpdate.IdentityKey)
@ -10413,7 +10436,7 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest)
// Now we'll test that updates are properly sent after channels are closed // Now we'll test that updates are properly sent after channels are closed
// within the network. // within the network.
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false) closeChannelAndAssert(ctxt, t, net, alice, chanPoint, false)
// Now that the channel has been closed, we should receive a // Now that the channel has been closed, we should receive a
// notification indicating so. // notification indicating so.
@ -10468,7 +10491,7 @@ out:
// we disconnect Alice and Bob, open a channel between Bob and Carol, // we disconnect Alice and Bob, open a channel between Bob and Carol,
// and finally connect Alice to Bob again. // and finally connect Alice to Bob again.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.DisconnectNodes(ctxt, net.Alice, net.Bob); err != nil { if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to disconnect alice and bob: %v", err) t.Fatalf("unable to disconnect alice and bob: %v", err)
} }
carol, err := net.NewNode("Carol", nil) carol, err := net.NewNode("Carol", nil)
@ -10478,12 +10501,12 @@ out:
defer shutdownAndAssert(net, t, carol) defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, net.Bob, carol); err != nil { if err := net.ConnectNodes(ctxt, bob, carol); err != nil {
t.Fatalf("unable to connect bob to carol: %v", err) t.Fatalf("unable to connect bob to carol: %v", err)
} }
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout) ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPoint = openChannelAndAssert( chanPoint = openChannelAndAssert(
ctxt, t, net, net.Bob, carol, ctxt, t, net, bob, carol,
lntest.OpenChannelParams{ lntest.OpenChannelParams{
Amt: chanAmt, Amt: chanAmt,
}, },
@ -10496,7 +10519,7 @@ out:
// Bob, since a node will update its node announcement after a new // Bob, since a node will update its node announcement after a new
// channel is opened. // channel is opened.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.EnsureConnected(ctxt, net.Alice, net.Bob); err != nil { if err := net.EnsureConnected(ctxt, alice, bob); err != nil {
t.Fatalf("unable to connect alice to bob: %v", err) t.Fatalf("unable to connect alice to bob: %v", err)
} }
@ -10510,7 +10533,7 @@ out:
for _, nodeUpdate := range graphUpdate.NodeUpdates { for _, nodeUpdate := range graphUpdate.NodeUpdates {
switch nodeUpdate.IdentityKey { switch nodeUpdate.IdentityKey {
case carol.PubKeyStr: case carol.PubKeyStr:
case net.Bob.PubKeyStr: case bob.PubKeyStr:
default: default:
t.Fatalf("unknown node update pubey: %v", t.Fatalf("unknown node update pubey: %v",
nodeUpdate.IdentityKey) nodeUpdate.IdentityKey)
@ -10521,14 +10544,14 @@ out:
for _, chanUpdate := range graphUpdate.ChannelUpdates { for _, chanUpdate := range graphUpdate.ChannelUpdates {
switch chanUpdate.AdvertisingNode { switch chanUpdate.AdvertisingNode {
case carol.PubKeyStr: case carol.PubKeyStr:
case net.Bob.PubKeyStr: case bob.PubKeyStr:
default: default:
t.Fatalf("unknown advertising node: %v", t.Fatalf("unknown advertising node: %v",
chanUpdate.AdvertisingNode) chanUpdate.AdvertisingNode)
} }
switch chanUpdate.ConnectingNode { switch chanUpdate.ConnectingNode {
case carol.PubKeyStr: case carol.PubKeyStr:
case net.Bob.PubKeyStr: case bob.PubKeyStr:
default: default:
t.Fatalf("unknown connecting node: %v", t.Fatalf("unknown connecting node: %v",
chanUpdate.ConnectingNode) chanUpdate.ConnectingNode)
@ -10552,7 +10575,7 @@ out:
// Close the channel between Bob and Carol. // Close the channel between Bob and Carol.
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
closeChannelAndAssert(ctxt, t, net, net.Bob, chanPoint, false) closeChannelAndAssert(ctxt, t, net, bob, chanPoint, false)
} }
// testNodeAnnouncement ensures that when a node is started with one or more // testNodeAnnouncement ensures that when a node is started with one or more