mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
test: add coverage for passing an invalid sighashtype
in RPCs descriptorprocesspbst, walletprocesspbst, signrawtransactionwithkey, and signrawtransactionwithwallet.
This commit is contained in:
parent
f57e724a80
commit
647d95aae9
3 changed files with 35 additions and 16 deletions
|
@ -883,6 +883,9 @@ class PSBTTest(BitcoinTestFramework):
|
|||
comb_psbt = self.nodes[0].combinepsbt([psbt, parsed_psbt.to_base64()])
|
||||
assert_equal(comb_psbt, psbt)
|
||||
|
||||
self.log.info("Test walletprocesspsbt raises if an invalid sighashtype is passed")
|
||||
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[0].walletprocesspsbt, psbt, sighashtype="all")
|
||||
|
||||
self.log.info("Test decoding PSBT with per-input preimage types")
|
||||
# note that the decodepsbt RPC doesn't check whether preimages and hashes match
|
||||
hash_ripemd160, preimage_ripemd160 = random_bytes(20), random_bytes(50)
|
||||
|
@ -982,5 +985,9 @@ class PSBTTest(BitcoinTestFramework):
|
|||
rawtx = self.nodes[2].finalizepsbt(psbt)["hex"]
|
||||
self.nodes[2].sendrawtransaction(rawtx)
|
||||
|
||||
self.log.info("Test descriptorprocesspsbt raises if an invalid sighashtype is passed")
|
||||
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[2].descriptorprocesspsbt, psbt, [descriptor], sighashtype="all")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PSBTTest().main()
|
||||
|
|
|
@ -14,6 +14,7 @@ from test_framework.address import (
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
find_vout_for_address,
|
||||
)
|
||||
from test_framework.script_util import (
|
||||
|
@ -33,6 +34,14 @@ from decimal import (
|
|||
Decimal,
|
||||
)
|
||||
|
||||
INPUTS = [
|
||||
# Valid pay-to-pubkey scripts
|
||||
{'txid': '9b907ef1e3c26fc71fe4a4b3580bc75264112f95050014157059c736f0202e71', 'vout': 0,
|
||||
'scriptPubKey': '76a91460baa0f494b38ce3c940dea67f3804dc52d1fb9488ac'},
|
||||
{'txid': '83a4f6a6b73660e13ee6cb3c6063fa3759c50c9b7521d0536022961898f4fb02', 'vout': 0,
|
||||
'scriptPubKey': '76a914669b857c03a5ed269d5d85a1ffac9ed5d663072788ac'},
|
||||
]
|
||||
OUTPUTS = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1}
|
||||
|
||||
class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
|
@ -56,19 +65,8 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
|||
2) No script verification error occurred"""
|
||||
self.log.info("Test valid raw transaction with one input")
|
||||
privKeys = ['cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N', 'cVKpPfVKSJxKqVpE9awvXNWuLHCa5j5tiE7K6zbUSptFpTEtiFrA']
|
||||
|
||||
inputs = [
|
||||
# Valid pay-to-pubkey scripts
|
||||
{'txid': '9b907ef1e3c26fc71fe4a4b3580bc75264112f95050014157059c736f0202e71', 'vout': 0,
|
||||
'scriptPubKey': '76a91460baa0f494b38ce3c940dea67f3804dc52d1fb9488ac'},
|
||||
{'txid': '83a4f6a6b73660e13ee6cb3c6063fa3759c50c9b7521d0536022961898f4fb02', 'vout': 0,
|
||||
'scriptPubKey': '76a914669b857c03a5ed269d5d85a1ffac9ed5d663072788ac'},
|
||||
]
|
||||
|
||||
outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1}
|
||||
|
||||
rawTx = self.nodes[0].createrawtransaction(inputs, outputs)
|
||||
rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, inputs)
|
||||
rawTx = self.nodes[0].createrawtransaction(INPUTS, OUTPUTS)
|
||||
rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, INPUTS)
|
||||
|
||||
# 1) The transaction has a complete set of signatures
|
||||
assert rawTxSigned['complete']
|
||||
|
@ -125,9 +123,16 @@ class SignRawTransactionWithKeyTest(BitcoinTestFramework):
|
|||
assert_equal(spending_tx_signed['complete'], True)
|
||||
self.nodes[0].sendrawtransaction(spending_tx_signed['hex'])
|
||||
|
||||
def invalid_sighashtype_test(self):
|
||||
self.log.info("Test signing transaction with invalid sighashtype")
|
||||
tx = self.nodes[0].createrawtransaction(INPUTS, OUTPUTS)
|
||||
privkeys = [self.nodes[0].get_deterministic_priv_key().key]
|
||||
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[0].signrawtransactionwithkey, tx, privkeys, sighashtype="all")
|
||||
|
||||
def run_test(self):
|
||||
self.successful_signing_test()
|
||||
self.witness_script_test()
|
||||
self.invalid_sighashtype_test()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -33,6 +33,10 @@ from decimal import (
|
|||
getcontext,
|
||||
)
|
||||
|
||||
|
||||
RAW_TX = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
|
||||
|
||||
|
||||
class SignRawTransactionWithWalletTest(BitcoinTestFramework):
|
||||
def add_options(self, parser):
|
||||
self.add_wallet_options(parser)
|
||||
|
@ -47,10 +51,12 @@ class SignRawTransactionWithWalletTest(BitcoinTestFramework):
|
|||
def test_with_lock_outputs(self):
|
||||
self.log.info("Test correct error reporting when trying to sign a locked output")
|
||||
self.nodes[0].encryptwallet("password")
|
||||
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].signrawtransactionwithwallet, RAW_TX)
|
||||
self.nodes[0].walletpassphrase("password", 9999)
|
||||
|
||||
rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000'
|
||||
|
||||
assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].signrawtransactionwithwallet, rawTx)
|
||||
def test_with_invalid_sighashtype(self):
|
||||
self.log.info("Test signrawtransactionwithwallet raises if an invalid sighashtype is passed")
|
||||
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[0].signrawtransactionwithwallet, hexstring=RAW_TX, sighashtype="all")
|
||||
|
||||
def script_verification_error_test(self):
|
||||
"""Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script.
|
||||
|
@ -299,6 +305,7 @@ class SignRawTransactionWithWalletTest(BitcoinTestFramework):
|
|||
self.script_verification_error_test()
|
||||
self.OP_1NEGATE_test()
|
||||
self.test_with_lock_outputs()
|
||||
self.test_with_invalid_sighashtype()
|
||||
self.test_fully_signed_tx()
|
||||
self.test_signing_with_csv()
|
||||
self.test_signing_with_cltv()
|
||||
|
|
Loading…
Add table
Reference in a new issue