From 7090ff22d74d4a7f99df1ff5844d4899372185c1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 22 Nov 2022 11:36:37 +0100 Subject: [PATCH] lnwallet: assert that P2TR addrs are used for change outputs --- lnwallet/test/test_interface.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lnwallet/test/test_interface.go b/lnwallet/test/test_interface.go index 6c43240da..bfdbeff25 100644 --- a/lnwallet/test/test_interface.go +++ b/lnwallet/test/test_interface.go @@ -2562,7 +2562,9 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet, // _very_ similar to the one we just created being sent. The // only difference is that the dry run tx is not signed, and // that the change output position might be different. - tx, sendErr := w.SendOutputs(outputs, feeRate, minConfs, labels.External) + tx, sendErr := w.SendOutputs( + outputs, feeRate, minConfs, labels.External, + ) switch { case test.valid && sendErr != nil: t.Fatalf("got unexpected error when sending tx: %v", @@ -2647,6 +2649,16 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet, if err := assertSimilarTx(createTx.Tx, tx); err != nil { t.Fatalf("transactions not similar: %v", err) } + + // Now that we know both transactions were essentially + // identical, we'll make sure that a P2TR addr was used as the + // change output, which is the current default. + changeTxOut := createTx.Tx.TxOut[createTx.ChangeIndex] + changeScriptType, _, _, err := txscript.ExtractPkScriptAddrs( + changeTxOut.PkScript, &w.Cfg.NetParams, + ) + require.NoError(t, err) + require.Equal(t, changeScriptType, txscript.WitnessV1TaprootTy) } }