lntest: extract WaitForBalance into a method
This commit is contained in:
parent
aa7c2e6d47
commit
0a335bbea2
@ -1171,24 +1171,6 @@ func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause until the nodes current wallet balances reflects the amount
|
expectedBalance := initialBalance.ConfirmedBalance + int64(amt)
|
||||||
// sent to it above.
|
return target.WaitForBalance(expectedBalance, true)
|
||||||
// TODO(roasbeef): factor out into helper func
|
|
||||||
balanceTicker := time.Tick(time.Millisecond * 50)
|
|
||||||
balanceTimeout := time.After(time.Second * 30)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-balanceTicker:
|
|
||||||
currentBal, err := target.WalletBalance(ctx, balReq)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentBal.ConfirmedBalance == initialBalance.ConfirmedBalance+int64(amt) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
case <-balanceTimeout:
|
|
||||||
return fmt.Errorf("balances not synced after deadline")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// fileExists reports whether the named file or directory exists.
|
||||||
// This function is taken from https://github.com/btcsuite/btcd
|
// This function is taken from https://github.com/btcsuite/btcd
|
||||||
func fileExists(name string) bool {
|
func fileExists(name string) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user