aboutsummaryrefslogtreecommitdiff
path: root/test/functional/rpc_signrawtransactionwithkey.py
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2023-07-26 16:56:48 -0600
committerJon Atack <jon@atack.com>2023-07-27 06:37:54 -0600
commit647d95aae9720543c2c9c46c70191e6f9f775d66 (patch)
treea421c35f532dc9cdf595fe7302cf7d5b9a488ae0 /test/functional/rpc_signrawtransactionwithkey.py
parentf57e724a809feb139c5ae71c4db65635427e4802 (diff)
downloadbitcoin-647d95aae9720543c2c9c46c70191e6f9f775d66.tar.xz
test: add coverage for passing an invalid sighashtype
in RPCs descriptorprocesspbst, walletprocesspbst, signrawtransactionwithkey, and signrawtransactionwithwallet.
Diffstat (limited to 'test/functional/rpc_signrawtransactionwithkey.py')
-rwxr-xr-xtest/functional/rpc_signrawtransactionwithkey.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/test/functional/rpc_signrawtransactionwithkey.py b/test/functional/rpc_signrawtransactionwithkey.py
index ac7a86704f..6baa653918 100755
--- a/test/functional/rpc_signrawtransactionwithkey.py
+++ b/test/functional/rpc_signrawtransactionwithkey.py
@@ -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__':