lnd_test: adds polling num channels assertion in breach itests

This commit is contained in:
Conner Fromknecht committed 2018-01-05 13:47:18 -08:00
1 parent d6998ed306
commit 978c0dc512
1 file changed
+27 -33
+27 -33
View File
@@ -2768,18 +2768,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("justice tx wasn't mined") t.Fatalf("justice tx wasn't mined")
} }
// Finally, obtain Alice's channel state, she shouldn't report any assertNumChannels(t, ctxb, net.Alice, 0)
// channel as she just successfully brought Bob to justice by sweeping
// all the channel funds.
req := &lnrpc.ListChannelsRequest{}
aliceChanInfo, err := net.Alice.ListChannels(ctxb, req)
if err != nil {
t.Fatalf("unable to query for alice's channels: %v", err)
}
if len(aliceChanInfo.Channels) != 0 {
t.Fatalf("alice shouldn't have a channel: %v",
spew.Sdump(aliceChanInfo.Channels))
}
} }
// testRevokedCloseRetributionZeroValueRemoteOutput tests that Alice is able // testRevokedCloseRetributionZeroValueRemoteOutput tests that Alice is able
@@ -2997,18 +2986,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
t.Fatalf("justice tx wasn't mined") t.Fatalf("justice tx wasn't mined")
} }
// Finally, obtain Alice's channel state, she shouldn't report any assertNumChannels(t, ctxb, net.Alice, 0)
// channel as she just successfully brought Carol to justice by sweeping
// all the channel funds.
req := &lnrpc.ListChannelsRequest{}
aliceChanInfo, err := net.Alice.ListChannels(ctxb, req)
if err != nil {
t.Fatalf("unable to query for alice's channels: %v", err)
}
if len(aliceChanInfo.Channels) != 0 {
t.Fatalf("alice shouldn't have a channel: %v",
spew.Sdump(aliceChanInfo.Channels))
}
} }
// testRevokedCloseRetributionRemoteHodl tests that Alice properly responds to a // testRevokedCloseRetributionRemoteHodl tests that Alice properly responds to a
@@ -3295,17 +3273,33 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
t.Fatalf("justice tx wasn't mined") t.Fatalf("justice tx wasn't mined")
} }
// Finally, obtain Alice's channel state, she shouldn't report any assertNumChannels(t, ctxb, net.Alice, 0)
// channel as she just successfully brought Carol to justice by sweeping }
// all the channel funds.
// assertNumChannels polls the provided node's list channels rpc until it
// reaches the desired number of total channels.
func assertNumChannels(t *harnessTest, ctxb context.Context,
node *lntest.HarnessNode, numChannels int) {
// Poll alice for her list of channels.
req := &lnrpc.ListChannelsRequest{} req := &lnrpc.ListChannelsRequest{}
aliceChanInfo, err := net.Alice.ListChannels(ctxb, req)
if err != nil { var predErr error
t.Fatalf("unable to query for alice's channels: %v", err) pred := func() bool {
chanInfo, err := node.ListChannels(ctxb, req)
if err != nil {
predErr = fmt.Errorf("unable to query for alice's "+
"channels: %v", err)
return false
}
// Return true if the query returned the expected number of
// channels.
return len(chanInfo.Channels) == numChannels
} }
if len(aliceChanInfo.Channels) != 0 {
t.Fatalf("alice shouldn't have a channel: %v", if err := lntest.WaitPredicate(pred, time.Second*15); err != nil {
spew.Sdump(aliceChanInfo.Channels)) t.Fatalf("node has incorrect number of channels: %v", predErr)
} }
} }