lntest/harness: assert unconfirmed utxos in ListUnspent during sendCoins
This commit is contained in:
parent
932fafd7cd
commit
3fa9d81a41
@ -1,6 +1,7 @@
|
|||||||
package lntest
|
package lntest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -1297,6 +1298,41 @@ func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount,
|
|||||||
return err
|
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
|
// If the transaction should remain unconfirmed, then we'll wait until
|
||||||
// the target node's unconfirmed balance reflects the expected balance
|
// the target node's unconfirmed balance reflects the expected balance
|
||||||
// and exit.
|
// and exit.
|
||||||
|
Loading…
Reference in New Issue
Block a user