lnd_test: adds polling num channels assertion in breach itests

This commit is contained in:
Conner Fromknecht 2017-12-14 13:56:10 -08:00
parent d6998ed306
commit 978c0dc512
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF
1 changed files with 27 additions and 33 deletions

View File

@ -2768,18 +2768,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("justice tx wasn't mined")
}
// Finally, obtain Alice's channel state, she shouldn't report any
// 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))
}
assertNumChannels(t, ctxb, net.Alice, 0)
}
// testRevokedCloseRetributionZeroValueRemoteOutput tests that Alice is able
@ -2997,18 +2986,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
t.Fatalf("justice tx wasn't mined")
}
// Finally, obtain Alice's channel state, she shouldn't report any
// 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))
}
assertNumChannels(t, ctxb, net.Alice, 0)
}
// testRevokedCloseRetributionRemoteHodl tests that Alice properly responds to a
@ -3295,17 +3273,33 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
t.Fatalf("justice tx wasn't mined")
}
// Finally, obtain Alice's channel state, she shouldn't report any
// channel as she just successfully brought Carol to justice by sweeping
// all the channel funds.
assertNumChannels(t, ctxb, net.Alice, 0)
}
// 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{}
aliceChanInfo, err := net.Alice.ListChannels(ctxb, req)
if err != nil {
t.Fatalf("unable to query for alice's channels: %v", err)
var predErr error
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",
spew.Sdump(aliceChanInfo.Channels))
if err := lntest.WaitPredicate(pred, time.Second*15); err != nil {
t.Fatalf("node has incorrect number of channels: %v", predErr)
}
}