From a266c3a4a99eabc27d41993b48feb69a99d1e24f Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 20 Mar 2023 19:22:34 +0100 Subject: [PATCH] itest: add assertion for PSBT change outputs With this commit we add more specific assertions to our PSBT signing test in order to make sure change outputs have the proper PSBT metadata associated with them, depending on their address type. --- itest/lnd_psbt_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/itest/lnd_psbt_test.go b/itest/lnd_psbt_test.go index 3d3b38c5f..57a0a67b7 100644 --- a/itest/lnd_psbt_test.go +++ b/itest/lnd_psbt_test.go @@ -1087,6 +1087,34 @@ func assertPsbtFundSignSpend(ht *lntest.HarnessTest, alice *node.HarnessNode, ) require.GreaterOrEqual(ht, fundResp.ChangeOutputIndex, int32(-1)) + // Make sure our change output has all the meta information required for + // signing. + fundedPacket, err := psbt.NewFromRawBytes( + bytes.NewReader(fundResp.FundedPsbt), false, + ) + require.NoError(ht, err) + + pOut := fundedPacket.Outputs[fundResp.ChangeOutputIndex] + require.NotEmpty(ht, pOut.Bip32Derivation) + derivation := pOut.Bip32Derivation[0] + _, err = btcec.ParsePubKey(derivation.PubKey) + require.NoError(ht, err) + require.Len(ht, derivation.Bip32Path, 5) + + // Ensure we get the change output properly decorated with all the new + // Taproot related fields, if it is a Taproot output. + if changeType == walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR { + require.NotEmpty(ht, pOut.TaprootBip32Derivation) + require.NotEmpty(ht, pOut.TaprootInternalKey) + + trDerivation := pOut.TaprootBip32Derivation[0] + require.Equal( + ht, trDerivation.XOnlyPubKey, pOut.TaprootInternalKey, + ) + _, err := schnorr.ParsePubKey(pOut.TaprootInternalKey) + require.NoError(ht, err) + } + var signedPsbt []byte if useFinalize { finalizeResp := alice.RPC.FinalizePsbt(