-
-
Save pinheadmz/ca8ed75913902bd1ddf88bdd921712ee to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/test/functional/rpc_signrawtransactionwithkey.py b/test/functional/rpc_signrawtransactionwithkey.py | |
index 268584331e..cb8e6d042b 100755 | |
--- a/test/functional/rpc_signrawtransactionwithkey.py | |
+++ b/test/functional/rpc_signrawtransactionwithkey.py | |
@@ -81,7 +81,7 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework): | |
embedded_privkey, embedded_pubkey = generate_keypair(wif=True) | |
p2sh_p2wsh_address = self.nodes[1].createmultisig(1, [embedded_pubkey.hex()], "p2sh-segwit") | |
# send transaction to P2SH-P2WSH 1-of-1 multisig address | |
- self.block_hash = self.generate(self.nodes[0], COINBASE_MATURITY + 1) | |
+ self.block_hash = self.generate(self.nodes[0], COINBASE_MATURITY + 2) | |
self.blk_idx = 0 | |
self.send_to_address(p2sh_p2wsh_address["address"], 49.999) | |
self.generate(self.nodes[0], 1) | |
@@ -100,6 +100,37 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework): | |
for tx_type in ['P2PKH', 'P2PK']: # these tests are order-independent | |
self.verify_txn_with_witness_script(tx_type) | |
+ def p2sh_multisig_test(self, pubkeys, allowed): | |
+ self.log.info(f"Test signing transaction to P2SH 1-of-{pubkeys} multisig addresses without wallet") | |
+ privs = [] | |
+ pubs = [] | |
+ # Create a new P2SH 1-of-15 multisig address: | |
+ # Generate keys | |
+ for _ in range(pubkeys): | |
+ priv, pub = generate_keypair(wif=True) | |
+ privs.append(priv) | |
+ pubs.append(pub) | |
+ # Use segwit option here to get the (potentially too-large-for-legacy) redeem script | |
+ redeem_script = self.nodes[1].createmultisig(1, [pubkey.hex() for pubkey in pubs], "p2sh-segwit")["redeemScript"] | |
+ # Now get the legacy P2SH address, even if the redeem script is invalid | |
+ decoded_ms = self.nodes[1].decodescript(redeem_script) | |
+ p2sh_ms_addr = decoded_ms["p2sh"] | |
+ # Fund the P2SH multisig address | |
+ txid = self.send_to_address(p2sh_ms_addr, 49.999) | |
+ # Get the output script while tx is still in the mempool | |
+ tx = self.nodes[0].getrawtransaction(txid, 2) | |
+ script_pub_key = tx["vout"][0]["scriptPubKey"]["hex"] | |
+ # Confirm | |
+ self.generate(self.nodes[0], 1) | |
+ # Create transaction template | |
+ unsigned_tx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': 0}], {getnewdestination()[2]: Decimal("49.998")}) | |
+ # Sign: always expected to succeed even if the resulting tx is unacceptable | |
+ signed_tx = self.nodes[0].signrawtransactionwithkey( | |
+ unsigned_tx, | |
+ [privs[0]], | |
+ [{'txid': txid, 'vout': 0, 'scriptPubKey': script_pub_key, 'redeemScript': redeem_script, 'amount': 49.999}]) | |
+ assert self.nodes[0].testmempoolaccept([signed_tx["hex"]])[0]["allowed"] == allowed | |
+ | |
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) | |
@@ -130,7 +161,8 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework): | |
self.successful_signing_test() | |
self.witness_script_test() | |
self.invalid_sighashtype_test() | |
- | |
+ self.p2sh_multisig_test(15, allowed=True) | |
+ self.p2sh_multisig_test(16, allowed=False) | |
if __name__ == '__main__': | |
SignRawTransactionWithKeyTest().main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment