itest: add test when signing without UTXO data

Adds a testcase in the itest suite which tests that psbt
input data needs its corresponding UTXO data when signing.
This commit is contained in:
ziggie 2023-03-29 23:33:32 +02:00
parent 4da26fb65a
commit b649b552e6
No known key found for this signature in database
GPG Key ID: 1AFF9C4DCED6D666
2 changed files with 26 additions and 2 deletions

View File

@ -1009,17 +1009,28 @@ func assertPsbtSpend(ht *lntest.HarnessTest, alice *node.HarnessNode,
packet, err := psbt.NewFromUnsignedTx(pendingTx)
require.NoError(ht, err)
// We first try to sign the psbt without the necessary input data
// which should fail with the expected error.
var buf bytes.Buffer
err = packet.Serialize(&buf)
require.NoError(ht, err)
signReq := &walletrpc.SignPsbtRequest{FundedPsbt: buf.Bytes()}
err = alice.RPC.SignPsbtErr(signReq)
require.ErrorContains(ht, err, "input (index=0) doesn't specify "+
"any UTXO info", "error does not match")
// Now let's add the meta information that we need for signing.
packet.Inputs[0].WitnessUtxo = utxo
packet.Inputs[0].NonWitnessUtxo = prevTx
decorateUnsigned(packet)
// That's it, we should be able to sign the PSBT now.
var buf bytes.Buffer
buf.Reset()
err = packet.Serialize(&buf)
require.NoError(ht, err)
signReq := &walletrpc.SignPsbtRequest{FundedPsbt: buf.Bytes()}
signReq = &walletrpc.SignPsbtRequest{FundedPsbt: buf.Bytes()}
signResp := alice.RPC.SignPsbt(signReq)
// Let's make sure we have a partial signature.

View File

@ -263,6 +263,19 @@ func (h *HarnessRPC) SignPsbt(
return resp
}
// SignPsbtErr makes a RPC call to the node's WalletKitClient and asserts
// an error returned.
func (h *HarnessRPC) SignPsbtErr(req *walletrpc.SignPsbtRequest) error {
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel()
_, err := h.WalletKit.SignPsbt(ctxt, req)
require.Errorf(h, err, "%s: expect sign psbt to return an error",
h.Name)
return err
}
// ImportTapscript makes a RPC call to the node's WalletKitClient and asserts.
//
//nolint:lll