-
Notifications
You must be signed in to change notification settings - Fork 991
tests: add regression tests for withdraw returning unsigned tx #8942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vincenzopalazzo
wants to merge
2
commits into
ElementsProject:master
Choose a base branch
from
vincenzopalazzo:claude/epic-black
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+90
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2072,6 +2072,79 @@ def test_fundchannel_listtransaction(node_factory, bitcoind): | |
| assert tx['blockheight'] == 0 | ||
|
|
||
|
|
||
| @unittest.skipIf(TEST_NETWORK != 'regtest', "Uss p2tr") | ||
| def test_withdraw_returns_signed_tx(node_factory, bitcoind): | ||
| """ | ||
| Test that withdraw returns a fully signed transaction in the 'tx' field. | ||
|
|
||
| Regression test for https://github.com/ElementsProject/lightning/issues/8701 | ||
| where withdraw returned an unsigned transaction (empty witnesses) because | ||
| psbt_txid() used WALLY_PSBT_EXTRACT_NON_FINAL to extract the tx. | ||
| """ | ||
| l1 = node_factory.get_node(random_hsm=True) | ||
|
|
||
| # Fund the wallet with a few UTXOs | ||
| addr = l1.rpc.newaddr('p2tr')['p2tr'] | ||
| for i in range(3): | ||
| l1.bitcoin.rpc.sendtoaddress(addr, 0.01) | ||
| bitcoind.generate_block(1) | ||
| wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 3) | ||
|
|
||
| waddr = l1.bitcoin.rpc.getnewaddress() | ||
| out = l1.rpc.withdraw(waddr, 'all') | ||
|
|
||
| # The tx field must be a fully signed transaction | ||
| decoded = bitcoind.rpc.decoderawtransaction(out['tx']) | ||
|
|
||
| # Every segwit input must have witness data (txinwitness) | ||
| for i, vin in enumerate(decoded['vin']): | ||
| assert 'txinwitness' in vin, \ | ||
| f"Input {i} has no witness data - tx is unsigned! (issue #8701)" | ||
| assert len(vin['txinwitness']) > 0, \ | ||
| f"Input {i} has empty witness stack" | ||
|
|
||
| # The returned tx must be directly broadcastable (already sent by withdraw, | ||
| # but verify it could be re-sent by checking it was accepted) | ||
| assert decoded['txid'] == out['txid'] | ||
|
|
||
|
|
||
| @unittest.skipIf(TEST_NETWORK != 'regtest', "Uss p2tr") | ||
| def test_withdraw_close_output_signed(node_factory, bitcoind): | ||
| """ | ||
| Test that withdraw correctly signs close outputs (anchor/P2WSH). | ||
|
|
||
| Regression test for https://github.com/ElementsProject/lightning/issues/8701 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you could remove the github link from this comment as well, that would be great. |
||
| The original issue involved spending channel close outputs (with | ||
| option_anchors CSV=1) alongside regular wallet UTXOs. | ||
| """ | ||
| l1, l2 = node_factory.line_graph(2, fundchannel=True, wait_for_announce=True) | ||
|
|
||
| # Close the channel so l1 gets a close output | ||
| l1.rpc.close(l2.info['id']) | ||
| bitcoind.generate_block(1, wait_for_mempool=1) | ||
|
|
||
| # Wait for CSV lock (1 block for anchors) and the close output to mature | ||
| bitcoind.generate_block(100) | ||
| sync_blockheight(bitcoind, [l1]) | ||
|
|
||
| wait_for(lambda: all(o['status'] == 'confirmed' for o in l1.rpc.listfunds()['outputs'])) | ||
|
|
||
| # Withdraw all funds - this spends both regular and close outputs | ||
| waddr = l1.bitcoin.rpc.getnewaddress() | ||
| out = l1.rpc.withdraw(waddr, 'all') | ||
|
|
||
| decoded = bitcoind.rpc.decoderawtransaction(out['tx']) | ||
|
|
||
| # Every input must have witness data | ||
| for i, vin in enumerate(decoded['vin']): | ||
| assert 'txinwitness' in vin, \ | ||
| f"Input {i} has no witness data - tx is unsigned! (issue #8701)" | ||
| assert len(vin['txinwitness']) > 0, \ | ||
| f"Input {i} has empty witness stack" | ||
|
|
||
| assert decoded['txid'] == out['txid'] | ||
|
|
||
|
|
||
| def test_withdraw_nlocktime(node_factory): | ||
| """ | ||
| Test that we don't set the nLockTime to 0 for withdrawal and | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we perhaps reword some of this comment? This comment is a bit verbose, also we don't really want github links through source/test code.