lntest/itest: fix scope bug

Fixes a subtle bug where the outer scope predErr was hidden when the
return value of findForceClosedChannel was stored in a newly
defined variable with the same name.
This commit is contained in:
Joost Jager 2020-03-12 10:11:08 +01:00
parent 31de32686e
commit 863966bac9
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -3223,52 +3223,47 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// Now that the commitment has been confirmed, the channel should be // Now that the commitment has been confirmed, the channel should be
// marked as force closed. // marked as force closed.
err = wait.Predicate(func() bool { err = wait.NoError(func() error {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
pendingChanResp, err := alice.PendingChannels( pendingChanResp, err := alice.PendingChannels(
ctxt, pendingChansRequest, ctxt, pendingChansRequest,
) )
if err != nil { if err != nil {
predErr = fmt.Errorf("unable to query for pending "+ return fmt.Errorf("unable to query for pending "+
"channels: %v", err) "channels: %v", err)
return false
} }
predErr = checkNumForceClosedChannels(pendingChanResp, 1) err = checkNumForceClosedChannels(pendingChanResp, 1)
if predErr != nil { if err != nil {
return false return err
} }
forceClose, predErr := findForceClosedChannel( forceClose, err := findForceClosedChannel(pendingChanResp, &op)
pendingChanResp, &op, if err != nil {
) return err
if predErr != nil {
return false
} }
// Now that the channel has been force closed, it should now // Now that the channel has been force closed, it should now
// have the height and number of blocks to confirm populated. // have the height and number of blocks to confirm populated.
predErr = checkCommitmentMaturity( err = checkCommitmentMaturity(
forceClose, commCsvMaturityHeight, int32(defaultCSV), forceClose, commCsvMaturityHeight, int32(defaultCSV),
) )
if predErr != nil { if err != nil {
return false return err
} }
// None of our outputs have been swept, so they should all be in // None of our outputs have been swept, so they should all be in
// limbo. // limbo.
if forceClose.LimboBalance == 0 { if forceClose.LimboBalance == 0 {
predErr = errors.New("all funds should still be in " + return errors.New("all funds should still be in " +
"limbo") "limbo")
return false
} }
if forceClose.RecoveredBalance != 0 { if forceClose.RecoveredBalance != 0 {
predErr = errors.New("no funds should yet be shown " + return errors.New("no funds should yet be shown " +
"as recovered") "as recovered")
return false
} }
return true return nil
}, 15*time.Second) }, 15*time.Second)
if err != nil { if err != nil {
t.Fatalf(predErr.Error()) t.Fatalf(predErr.Error())