diff --git a/itest/lnd_psbt_test.go b/itest/lnd_psbt_test.go index 57a0a67b7..ffa680d75 100644 --- a/itest/lnd_psbt_test.go +++ b/itest/lnd_psbt_test.go @@ -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. diff --git a/lntest/rpc/wallet_kit.go b/lntest/rpc/wallet_kit.go index 1d0a12858..9a88fe6e7 100644 --- a/lntest/rpc/wallet_kit.go +++ b/lntest/rpc/wallet_kit.go @@ -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