diff --git a/lntest/harness.go b/lntest/harness.go index 9d878f54..afe71248 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -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.