lntest: extract WaitForBalance into a method

This commit is contained in:
Wilmer Paulino committed 2018-08-16 20:22:41 -07:00
1 parent aa7c2e6d47
commit 0a335bbea2
2 files changed
+29 -20

No files matched your search

+27
View File
@@ -895,6 +895,33 @@ func (hn *HarnessNode) WaitForBlockchainSync(ctx context.Context) error {
}
}
// WaitForBalance waits until the node sees the expected confirmed/unconfirmed
// balance within their wallet.
func (hn *HarnessNode) WaitForBalance(expectedBalance int64, confirmed bool) error {
ctx := context.Background()
req := &lnrpc.WalletBalanceRequest{}
doesBalanceMatch := func() bool {
balance, err := hn.WalletBalance(ctx, req)
if err != nil {
return false
}
if confirmed {
return balance.ConfirmedBalance == expectedBalance
}
return balance.UnconfirmedBalance == expectedBalance
}
err := WaitPredicate(doesBalanceMatch, 30*time.Second)
if err != nil {
return errors.New("balances not synced after deadline")
}
return nil
}
// fileExists reports whether the named file or directory exists.
// This function is taken from https://github.com/btcsuite/btcd
func fileExists(name string) bool {