lntest/harness: assert unconfirmed utxos in ListUnspent during sendCoins

This commit is contained in:
Conner Fromknecht 2019-02-11 13:02:11 -08:00
parent 932fafd7cd
commit 3fa9d81a41
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -1,6 +1,7 @@
package lntest
import (
"encoding/hex"
"errors"
"fmt"
"io"
@ -1297,6 +1298,41 @@ func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount,
return err
}
// Encode the pkScript in hex as this the format that it will be
// returned via rpc.
expPkScriptStr := hex.EncodeToString(addrScript)
// Now, wait for ListUnspent to show the unconfirmed transaction
// containing the correct pkscript.
err = WaitNoError(func() error {
req := &lnrpc.ListUnspentRequest{}
resp, err := target.ListUnspent(ctx, req)
if err != nil {
return err
}
// When using this method, there should only ever be on
// unconfirmed transaction.
if len(resp.Utxos) != 1 {
return fmt.Errorf("number of unconfirmed utxos "+
"should be 1, found %d", len(resp.Utxos))
}
// Assert that the lone unconfirmed utxo contains the same
// pkscript as the output generated above.
pkScriptStr := resp.Utxos[0].ScriptPubkey
if strings.Compare(pkScriptStr, expPkScriptStr) != 0 {
return fmt.Errorf("pkscript mismatch, want: %s, "+
"found: %s", expPkScriptStr, pkScriptStr)
}
return nil
}, 15*time.Second)
if err != nil {
return fmt.Errorf("unconfirmed utxo was not found in "+
"ListUnspent: %v", err)
}
// If the transaction should remain unconfirmed, then we'll wait until
// the target node's unconfirmed balance reflects the expected balance
// and exit.