Skip to content

Commit 5d682d4

Browse files
committed
Merge bitcoin#30576: test: check that keyless P2A 'signing' via signrawtransactionwithkey succeeds
5e87f30 test: check that keyless P2A 'signing' via `signrawtransactionwithkey` succeeds (Sebastian Falbesoner) Pull request description: This small PR adds a sanity check to verify that transactions with P2A inputs can be 'signed' successfully, using the non-wallet RPC `signrawtransactionwithkey`. Note that in the this flow, `SignStep` (which was also extended for the new `ANCHOR` output type in bitcoin#30352) is never called, as signing is only tried if the locking script verification isn't successful already. See the review discussion bitcoin#30352 (comment) ff. ACKs for top commit: instagibbs: ACK 5e87f30 tdb3: ACK 5e87f30 glozow: code review ACK 5e87f30 Tree-SHA512: dfea75b4bf8fa0b9c265ddd63dab36374c2430c31220f0c8eb1b53dd847c183f9e1c493a0173e2da317553a1d4cb1b35aa9ffde1268c430cc610368d23b9c942
2 parents bba01ba + 5e87f30 commit 5d682d4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/functional/rpc_signrawtransactionwithkey.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from test_framework.address import (
1111
address_to_scriptpubkey,
12+
p2a,
1213
script_to_p2sh,
1314
)
1415
from test_framework.test_framework import BitcoinTestFramework
@@ -100,6 +101,18 @@ def witness_script_test(self):
100101
for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent
101102
self.verify_txn_with_witness_script(tx_type)
102103

104+
def keyless_signing_test(self):
105+
self.log.info("Test that keyless 'signing' of pay-to-anchor input succeeds")
106+
funding_txid = self.send_to_address(p2a(), 49.999)
107+
spending_tx = self.nodes[0].createrawtransaction(
108+
[{"txid": funding_txid, "vout": 0}],
109+
[{getnewdestination()[2]: Decimal("49.998")}])
110+
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [], [])
111+
self.assert_signing_completed_successfully(spending_tx_signed)
112+
assert self.nodes[0].testmempoolaccept([spending_tx_signed["hex"]])[0]["allowed"]
113+
# 'signing' a P2A prevout is a no-op, so signed and unsigned txs shouldn't differ
114+
assert_equal(spending_tx, spending_tx_signed["hex"])
115+
103116
def verify_txn_with_witness_script(self, tx_type):
104117
self.log.info("Test with a {} script as the witnessScript".format(tx_type))
105118
embedded_privkey, embedded_pubkey = generate_keypair(wif=True)
@@ -138,6 +151,7 @@ def invalid_private_key_and_tx(self):
138151
def run_test(self):
139152
self.successful_signing_test()
140153
self.witness_script_test()
154+
self.keyless_signing_test()
141155
self.invalid_sighashtype_test()
142156
self.invalid_private_key_and_tx()
143157

test/functional/test_framework/address.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def output_key_to_p2tr(key, main=False):
155155
assert len(key) == 32
156156
return program_to_witness(1, key, main)
157157

158+
def p2a(main=False):
159+
return program_to_witness(1, "4e73", main)
160+
158161
def check_key(key):
159162
if (type(key) is str):
160163
key = bytes.fromhex(key) # Assuming this is hex string

0 commit comments

Comments
 (0)