tests: add regression tests for withdraw returning unsigned tx#8942
tests: add regression tests for withdraw returning unsigned tx#8942vincenzopalazzo wants to merge 2 commits intoElementsProject:masterfrom
Conversation
Adds two tests to reproduce issue ElementsProject#8701 where the withdraw command returns an unsigned raw transaction in the 'tx' response field: 1. test_withdraw_returns_signed_tx: verifies that withdraw's 'tx' field contains witness data for all inputs (basic wallet UTXOs). 2. test_withdraw_close_output_signed: verifies signing works when withdrawing funds that include channel close outputs (anchor/P2WSH with CSV locks), which was the exact scenario in the reported issue. The root cause is that psbt_txid() uses WALLY_PSBT_EXTRACT_NON_FINAL which strips signatures/witnesses, and the withdraw response returns this unsigned tx instead of the finalized one. Changelog-None Signed-off-by: Vincenzo Palazzo <vincenzopalazzo@member.fsf.org> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Root Cause AnalysisThis is a regression introduced in commit 908f834 ("Update libwally to 0.8.8, support PSBTv2") from 2023-02-01. Before PSBTv2 (pre-
|
The withdraw command was returning an unsigned raw transaction in its 'tx' response field. This happened because signpsbt_done() used psbt_txid() to extract utx->tx, which internally calls wally_psbt_extract() with WALLY_PSBT_EXTRACT_NON_FINAL — stripping all signature and witness data. The broadcast itself succeeded because sendpsbt internally finalizes the PSBT via psbt_final_tx(), but the 'tx' field returned to the user had empty scriptSigs and no witness data. This is a regression from 908f834 ("Update libwally to 0.8.8, support PSBTv2") which rewrote psbt_txid() from manually copying final_scriptsig/redeem_script into the cloned tx, to using wally_psbt_extract(WALLY_PSBT_EXTRACT_NON_FINAL) which strips all signing data by design. Fix by finalizing the signed PSBT in signpsbt_done() and extracting the fully signed transaction via psbt_final_tx(). The txid verification still uses psbt_txid() (which is correct for txid computation since txids exclude witness data). Fixes: ElementsProject#8701 Changelog-Fixed: withdraw now returns a fully signed transaction in the `tx` response field. Signed-off-by: Vincenzo Palazzo <vincenzopalazzo@member.fsf.org> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ca8ba06 to
5f9abea
Compare
Summary
withdrawreturns an unsigned raw transaction in thetxresponse fieldtest_withdraw_returns_signed_tx: verifies witness data exists for all inputs in the returnedtxtest_withdraw_close_output_signed: reproduces the exact scenario from the issue — withdrawing funds that include channel close outputs (anchor/P2WSH with CSV=1)Root Cause Analysis
The
withdrawcommand flow:finish_txprepare→signpsbt→signpsbt_done→sendpsbt→sendpsbt_donesignpsbt_done,psbt_txid()extractsutx->txusingWALLY_PSBT_EXTRACT_NON_FINAL, which strips all signatures/witnessessendpsbtinternally finalizes the PSBT viapsbt_final_tx()sendpsbt_donereturnsutx->tx(the unsigned version) in the responseThe
txfield in thewithdrawresponse is always unsigned. Thepsbtfield is correct.Test plan
test_withdraw_returns_signed_txshould fail on current master (confirming the bug)test_withdraw_close_output_signedshould fail on current master with anchor close outputssignpsbt_doneinplugins/txprepare.cFixes: #8701
🤖 Generated with Claude Code