Changeset View
Changeset View
Standalone View
Standalone View
test/functional/signrawtransactions.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test transaction signing using the signrawtransactionwithwallet RPC.""" | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
class SignRawTransactionsTest(BitcoinTestFramework): | class SignRawTransactionsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
Show All 17 Lines | def successful_signing_test(self): | ||||
{'txid': '83a4f6a6b73660e13ee6cb3c6063fa3759c50c9b7521d0536022961898f4fb02', | {'txid': '83a4f6a6b73660e13ee6cb3c6063fa3759c50c9b7521d0536022961898f4fb02', | ||||
'vout': 0, 'amount': '123.456', | 'vout': 0, 'amount': '123.456', | ||||
'scriptPubKey': '76a914669b857c03a5ed269d5d85a1ffac9ed5d663072788ac'}, | 'scriptPubKey': '76a914669b857c03a5ed269d5d85a1ffac9ed5d663072788ac'}, | ||||
] | ] | ||||
outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} | outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} | ||||
rawTx = self.nodes[0].createrawtransaction(inputs, outputs) | rawTx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
rawTxSigned = self.nodes[0].signrawtransaction(rawTx, inputs, privKeys) | rawTxSigned = self.nodes[0].signrawtransactionwithkey( | ||||
rawTx, privKeys, inputs) | |||||
# 1) The transaction has a complete set of signatures | # 1) The transaction has a complete set of signatures | ||||
assert 'complete' in rawTxSigned | assert 'complete' in rawTxSigned | ||||
assert_equal(rawTxSigned['complete'], True) | assert_equal(rawTxSigned['complete'], True) | ||||
# 2) No script verification error occurred | # 2) No script verification error occurred | ||||
assert 'errors' not in rawTxSigned | assert 'errors' not in rawTxSigned | ||||
Show All 40 Lines | def script_verification_error_test(self): | ||||
for i, inp in enumerate(inputs): | for i, inp in enumerate(inputs): | ||||
assert_equal(decodedRawTx["vin"][i]["txid"], inp["txid"]) | assert_equal(decodedRawTx["vin"][i]["txid"], inp["txid"]) | ||||
assert_equal(decodedRawTx["vin"][i]["vout"], inp["vout"]) | assert_equal(decodedRawTx["vin"][i]["vout"], inp["vout"]) | ||||
# Make sure decoderawtransaction throws if there is extra data | # Make sure decoderawtransaction throws if there is extra data | ||||
assert_raises_rpc_error(-22, "TX decode failed", | assert_raises_rpc_error(-22, "TX decode failed", | ||||
self.nodes[0].decoderawtransaction, rawTx + "00") | self.nodes[0].decoderawtransaction, rawTx + "00") | ||||
rawTxSigned = self.nodes[0].signrawtransaction( | rawTxSigned = self.nodes[0].signrawtransactionwithkey( | ||||
rawTx, scripts, privKeys) | rawTx, privKeys, scripts) | ||||
# 3) The transaction has no complete set of signatures | # 3) The transaction has no complete set of signatures | ||||
assert 'complete' in rawTxSigned | assert 'complete' in rawTxSigned | ||||
assert_equal(rawTxSigned['complete'], False) | assert_equal(rawTxSigned['complete'], False) | ||||
# 4) Two script verification errors occurred | # 4) Two script verification errors occurred | ||||
assert 'errors' in rawTxSigned | assert 'errors' in rawTxSigned | ||||
assert_equal(len(rawTxSigned['errors']), 2) | assert_equal(len(rawTxSigned['errors']), 2) | ||||
Show All 22 Lines |