mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
Merge bitcoin/bitcoin#30576: test: check that keyless P2A 'signing' via signrawtransactionwithkey
succeeds
5e87f30f7c
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 #30352) is never called, as signing is only tried if the locking script verification isn't successful already. See the review discussion https://github.com/bitcoin/bitcoin/pull/30352#discussion_r1690530356 ff. ACKs for top commit: instagibbs: ACK5e87f30f7c
tdb3: ACK5e87f30f7c
glozow: code review ACK5e87f30f7c
Tree-SHA512: dfea75b4bf8fa0b9c265ddd63dab36374c2430c31220f0c8eb1b53dd847c183f9e1c493a0173e2da317553a1d4cb1b35aa9ffde1268c430cc610368d23b9c942
This commit is contained in:
commit
5d682d4ba3
2 changed files with 17 additions and 0 deletions
|
@ -9,6 +9,7 @@ from test_framework.blocktools import (
|
||||||
)
|
)
|
||||||
from test_framework.address import (
|
from test_framework.address import (
|
||||||
address_to_scriptpubkey,
|
address_to_scriptpubkey,
|
||||||
|
p2a,
|
||||||
script_to_p2sh,
|
script_to_p2sh,
|
||||||
)
|
)
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
@ -100,6 +101,18 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent
|
for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent
|
||||||
self.verify_txn_with_witness_script(tx_type)
|
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):
|
def verify_txn_with_witness_script(self, tx_type):
|
||||||
self.log.info("Test with a {} script as the witnessScript".format(tx_type))
|
self.log.info("Test with a {} script as the witnessScript".format(tx_type))
|
||||||
embedded_privkey, embedded_pubkey = generate_keypair(wif=True)
|
embedded_privkey, embedded_pubkey = generate_keypair(wif=True)
|
||||||
|
@ -138,6 +151,7 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.successful_signing_test()
|
self.successful_signing_test()
|
||||||
self.witness_script_test()
|
self.witness_script_test()
|
||||||
|
self.keyless_signing_test()
|
||||||
self.invalid_sighashtype_test()
|
self.invalid_sighashtype_test()
|
||||||
self.invalid_private_key_and_tx()
|
self.invalid_private_key_and_tx()
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,9 @@ def output_key_to_p2tr(key, main=False):
|
||||||
assert len(key) == 32
|
assert len(key) == 32
|
||||||
return program_to_witness(1, key, main)
|
return program_to_witness(1, key, main)
|
||||||
|
|
||||||
|
def p2a(main=False):
|
||||||
|
return program_to_witness(1, "4e73", main)
|
||||||
|
|
||||||
def check_key(key):
|
def check_key(key):
|
||||||
if (type(key) is str):
|
if (type(key) is str):
|
||||||
key = bytes.fromhex(key) # Assuming this is hex string
|
key = bytes.fromhex(key) # Assuming this is hex string
|
||||||
|
|
Loading…
Add table
Reference in a new issue