Skip to content

Commit

Permalink
Merge bitcoin#30576: test: check that keyless P2A 'signing' via `sign…
Browse files Browse the repository at this point in the history
…rawtransactionwithkey` 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
  • Loading branch information
glozow committed Aug 5, 2024
2 parents bba01ba + 5e87f30 commit 5d682d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/functional/rpc_signrawtransactionwithkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from test_framework.address import (
address_to_scriptpubkey,
p2a,
script_to_p2sh,
)
from test_framework.test_framework import BitcoinTestFramework
Expand Down Expand Up @@ -100,6 +101,18 @@ def witness_script_test(self):
for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent
self.verify_txn_with_witness_script(tx_type)

def keyless_signing_test(self):
self.log.info("Test that keyless 'signing' of pay-to-anchor input succeeds")
funding_txid = self.send_to_address(p2a(), 49.999)
spending_tx = self.nodes[0].createrawtransaction(
[{"txid": funding_txid, "vout": 0}],
[{getnewdestination()[2]: Decimal("49.998")}])
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [], [])
self.assert_signing_completed_successfully(spending_tx_signed)
assert self.nodes[0].testmempoolaccept([spending_tx_signed["hex"]])[0]["allowed"]
# 'signing' a P2A prevout is a no-op, so signed and unsigned txs shouldn't differ
assert_equal(spending_tx, spending_tx_signed["hex"])

def verify_txn_with_witness_script(self, tx_type):
self.log.info("Test with a {} script as the witnessScript".format(tx_type))
embedded_privkey, embedded_pubkey = generate_keypair(wif=True)
Expand Down Expand Up @@ -138,6 +151,7 @@ def invalid_private_key_and_tx(self):
def run_test(self):
self.successful_signing_test()
self.witness_script_test()
self.keyless_signing_test()
self.invalid_sighashtype_test()
self.invalid_private_key_and_tx()

Expand Down
3 changes: 3 additions & 0 deletions test/functional/test_framework/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def output_key_to_p2tr(key, main=False):
assert len(key) == 32
return program_to_witness(1, key, main)

def p2a(main=False):
return program_to_witness(1, "4e73", main)

def check_key(key):
if (type(key) is str):
key = bytes.fromhex(key) # Assuming this is hex string
Expand Down

0 comments on commit 5d682d4

Please sign in to comment.