mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 10:19:26 +02:00
test: add coverage for passing an invalid sighashtype
in RPCs descriptorprocesspbst, walletprocesspbst, signrawtransactionwithkey, and signrawtransactionwithwallet.
This commit is contained in:
@ -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__':
|
||||
|
Reference in New Issue
Block a user