Skip to content

Commit d602348

Browse files
committed
Add test for signrawtransaction
Add a brief test for signrawtransaction to ensure that compatibility is maintained.
1 parent eefff65 commit d602348

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

test/functional/rpc_signrawtransaction.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) 2015-2017 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test transaction signing using the signrawtransactionwithwallet RPC."""
5+
"""Test transaction signing using the signrawtransaction* RPCs."""
66

77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import *
@@ -12,6 +12,7 @@ class SignRawTransactionsTest(BitcoinTestFramework):
1212
def set_test_params(self):
1313
self.setup_clean_chain = True
1414
self.num_nodes = 1
15+
self.extra_args = [["-deprecatedrpc=signrawtransaction"]]
1516

1617
def successful_signing_test(self):
1718
"""Create and sign a valid raw transaction with one input.
@@ -36,12 +37,15 @@ def successful_signing_test(self):
3637
rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, inputs)
3738

3839
# 1) The transaction has a complete set of signatures
39-
assert 'complete' in rawTxSigned
40-
assert_equal(rawTxSigned['complete'], True)
40+
assert rawTxSigned['complete']
4141

4242
# 2) No script verification error occurred
4343
assert 'errors' not in rawTxSigned
4444

45+
# Perform the same test on signrawtransaction
46+
rawTxSigned2 = self.nodes[0].signrawtransaction(rawTx, inputs, privKeys)
47+
assert_equal(rawTxSigned, rawTxSigned2)
48+
4549
def script_verification_error_test(self):
4650
"""Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script.
4751
@@ -87,8 +91,7 @@ def script_verification_error_test(self):
8791
rawTxSigned = self.nodes[0].signrawtransactionwithkey(rawTx, privKeys, scripts)
8892

8993
# 3) The transaction has no complete set of signatures
90-
assert 'complete' in rawTxSigned
91-
assert_equal(rawTxSigned['complete'], False)
94+
assert not rawTxSigned['complete']
9295

9396
# 4) Two script verification errors occurred
9497
assert 'errors' in rawTxSigned
@@ -109,14 +112,17 @@ def script_verification_error_test(self):
109112
assert_equal(rawTxSigned['errors'][1]['vout'], inputs[2]['vout'])
110113
assert not rawTxSigned['errors'][0]['witness']
111114

115+
# Perform same test with signrawtransaction
116+
rawTxSigned2 = self.nodes[0].signrawtransaction(rawTx, scripts, privKeys)
117+
assert_equal(rawTxSigned, rawTxSigned2)
118+
112119
# Now test signing failure for transaction with input witnesses
113120
p2wpkh_raw_tx = "01000000000102fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000494830450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac000247304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee0121025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee635711000000"
114121

115122
rawTxSigned = self.nodes[0].signrawtransactionwithwallet(p2wpkh_raw_tx)
116123

117124
# 7) The transaction has no complete set of signatures
118-
assert 'complete' in rawTxSigned
119-
assert_equal(rawTxSigned['complete'], False)
125+
assert not rawTxSigned['complete']
120126

121127
# 8) Two script verification errors occurred
122128
assert 'errors' in rawTxSigned
@@ -134,6 +140,10 @@ def script_verification_error_test(self):
134140
assert_equal(rawTxSigned['errors'][1]['witness'], ["304402203609e17b84f6a7d30c80bfa610b5b4542f32a8a0d5447a12fb1366d7f01cc44a0220573a954c4518331561406f90300e8f3358f51928d43c212a8caed02de67eebee01", "025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357"])
135141
assert not rawTxSigned['errors'][0]['witness']
136142

143+
# Perform same test with signrawtransaction
144+
rawTxSigned2 = self.nodes[0].signrawtransaction(p2wpkh_raw_tx)
145+
assert_equal(rawTxSigned, rawTxSigned2)
146+
137147
def run_test(self):
138148
self.successful_signing_test()
139149
self.script_verification_error_test()

0 commit comments

Comments
 (0)