itest: refactor testUnannouncedChannels
This commit is contained in:
3 files changed
+15
-82
No files matched your search
@@ -163,4 +163,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "addpeer config",
|
Name: "addpeer config",
|
||||||
TestFunc: testAddPeerConfig,
|
TestFunc: testAddPeerConfig,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "unannounced channels",
|
||||||
|
TestFunc: testUnannouncedChannels,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -222,106 +222,39 @@ func testUpdateChanStatus(ht *lntemp.HarnessTest) {
|
|||||||
|
|
||||||
// testUnannouncedChannels checks unannounced channels are not returned by
|
// testUnannouncedChannels checks unannounced channels are not returned by
|
||||||
// describeGraph RPC request unless explicitly asked for.
|
// describeGraph RPC request unless explicitly asked for.
|
||||||
func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
func testUnannouncedChannels(ht *lntemp.HarnessTest) {
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
amount := funding.MaxBtcFundingAmount
|
amount := funding.MaxBtcFundingAmount
|
||||||
|
alice, bob := ht.Alice, ht.Bob
|
||||||
|
|
||||||
// Open a channel between Alice and Bob, ensuring the
|
// Open a channel between Alice and Bob, ensuring the
|
||||||
// channel has been opened properly.
|
// channel has been opened properly.
|
||||||
chanOpenUpdate := openChannelStream(
|
chanOpenUpdate := ht.OpenChannelAssertStream(
|
||||||
t, net, net.Alice, net.Bob,
|
alice, bob, lntemp.OpenChannelParams{Amt: amount},
|
||||||
lntest.OpenChannelParams{
|
|
||||||
Amt: amount,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mine 2 blocks, and check that the channel is opened but not yet
|
// Mine 2 blocks, and check that the channel is opened but not yet
|
||||||
// announced to the network.
|
// announced to the network.
|
||||||
mineBlocks(t, net, 2, 1)
|
ht.MineBlocksAndAssertNumTxes(2, 1)
|
||||||
|
|
||||||
// One block is enough to make the channel ready for use, since the
|
// One block is enough to make the channel ready for use, since the
|
||||||
// nodes have defaultNumConfs=1 set.
|
// nodes have defaultNumConfs=1 set.
|
||||||
fundingChanPoint, err := net.WaitForChannelOpen(chanOpenUpdate)
|
fundingChanPoint := ht.WaitForChannelOpenEvent(chanOpenUpdate)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("error while waiting for channel open: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alice should have 1 edge in her graph.
|
// Alice should have 1 edge in her graph.
|
||||||
req := &lnrpc.ChannelGraphRequest{
|
ht.AssertNumEdges(alice, 1, true)
|
||||||
IncludeUnannounced: true,
|
|
||||||
}
|
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
chanGraph, err := net.Alice.DescribeGraph(ctxt, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to query alice's graph: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
numEdges := len(chanGraph.Edges)
|
|
||||||
if numEdges != 1 {
|
|
||||||
t.Fatalf("expected to find 1 edge in the graph, found %d", numEdges)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Channels should not be announced yet, hence Alice should have no
|
// Channels should not be announced yet, hence Alice should have no
|
||||||
// announced edges in her graph.
|
// announced edges in her graph.
|
||||||
req.IncludeUnannounced = false
|
ht.AssertNumEdges(alice, 0, false)
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
chanGraph, err = net.Alice.DescribeGraph(ctxt, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to query alice's graph: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
numEdges = len(chanGraph.Edges)
|
|
||||||
if numEdges != 0 {
|
|
||||||
t.Fatalf("expected to find 0 announced edges in the graph, found %d",
|
|
||||||
numEdges)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mine 4 more blocks, and check that the channel is now announced.
|
// Mine 4 more blocks, and check that the channel is now announced.
|
||||||
mineBlocks(t, net, 4, 0)
|
ht.MineBlocks(4)
|
||||||
|
|
||||||
// Give the network a chance to learn that auth proof is confirmed.
|
// Give the network a chance to learn that auth proof is confirmed.
|
||||||
var predErr error
|
ht.AssertNumEdges(alice, 1, false)
|
||||||
err = wait.Predicate(func() bool {
|
|
||||||
// The channel should now be announced. Check that Alice has 1
|
|
||||||
// announced edge.
|
|
||||||
req.IncludeUnannounced = false
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
chanGraph, err = net.Alice.DescribeGraph(ctxt, req)
|
|
||||||
if err != nil {
|
|
||||||
predErr = fmt.Errorf("unable to query alice's graph: %v", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
numEdges = len(chanGraph.Edges)
|
|
||||||
if numEdges != 1 {
|
|
||||||
predErr = fmt.Errorf("expected to find 1 announced edge in "+
|
|
||||||
"the graph, found %d", numEdges)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}, defaultTimeout)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%v", predErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The channel should now be announced. Check that Alice has 1 announced
|
|
||||||
// edge.
|
|
||||||
req.IncludeUnannounced = false
|
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
chanGraph, err = net.Alice.DescribeGraph(ctxt, req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to query alice's graph: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
numEdges = len(chanGraph.Edges)
|
|
||||||
if numEdges != 1 {
|
|
||||||
t.Fatalf("expected to find 1 announced edge in the graph, found %d",
|
|
||||||
numEdges)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the channel used during the test.
|
// Close the channel used during the test.
|
||||||
closeChannelAndAssert(t, net, net.Alice, fundingChanPoint, false)
|
ht.CloseChannel(alice, fundingChanPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) {
|
func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "send to route error propagation",
|
name: "send to route error propagation",
|
||||||
test: testSendToRouteErrorPropagation,
|
test: testSendToRouteErrorPropagation,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "unannounced channels",
|
|
||||||
test: testUnannouncedChannels,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "private channels",
|
name: "private channels",
|
||||||
test: testPrivateChannels,
|
test: testPrivateChannels,
|
||||||
|
|||||||
Reference in new issue
Block a user