lntest: log the expected and last balance in WaitForBalance error case

This commit is contained in:
Olaoluwa Osuntokun committed 2018-09-06 16:49:27 -07:00
1 parent 09d4660524
commit 27ecfbbd36
1 file changed
+6 -1
+6 -1
View File
@@ -24,6 +24,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient" "github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/macaroons"
@@ -901,6 +902,7 @@ func (hn *HarnessNode) WaitForBalance(expectedBalance int64, confirmed bool) err
ctx := context.Background() ctx := context.Background()
req := &lnrpc.WalletBalanceRequest{} req := &lnrpc.WalletBalanceRequest{}
var lastBalance btcutil.Amount
doesBalanceMatch := func() bool { doesBalanceMatch := func() bool {
balance, err := hn.WalletBalance(ctx, req) balance, err := hn.WalletBalance(ctx, req)
if err != nil { if err != nil {
@@ -908,15 +910,18 @@ func (hn *HarnessNode) WaitForBalance(expectedBalance int64, confirmed bool) err
} }
if confirmed { if confirmed {
lastBalance = btcutil.Amount(balance.ConfirmedBalance)
return balance.ConfirmedBalance == expectedBalance return balance.ConfirmedBalance == expectedBalance
} }
lastBalance = btcutil.Amount(balance.UnconfirmedBalance)
return balance.UnconfirmedBalance == expectedBalance return balance.UnconfirmedBalance == expectedBalance
} }
err := WaitPredicate(doesBalanceMatch, 30*time.Second) err := WaitPredicate(doesBalanceMatch, 30*time.Second)
if err != nil { if err != nil {
return errors.New("balances not synced after deadline") return fmt.Errorf("balances not synced after deadline: "+
"expected %v, only have %v", expectedBalance, lastBalance)
} }
return nil return nil