Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_signrawtransaction.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2019 The Bitcoin Core developers | # Copyright (c) 2015-2019 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 signrawtransaction* RPCs.""" | """Test transaction signing using the signrawtransaction* RPCs.""" | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, assert_raises_rpc_error | from test_framework.util import assert_equal, assert_raises_rpc_error | ||||
RPC_WALLET_NOT_SPECIFIED = "Wallet file not specified (must request wallet " + \ | RPC_WALLET_NOT_SPECIFIED = "Wallet file not specified (must request wallet " + \ | ||||
"RPC through /wallet/<filename> uri-path)." | "RPC through /wallet/<filename> uri-path)." | ||||
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 | ||||
self.num_nodes = 2 | self.num_nodes = 1 | ||||
self.extra_args = [[], ["-wallet=w1", "-wallet=w2"]] | |||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def successful_signing_test(self): | def successful_signing_test(self): | ||||
"""Creates and signs a valid raw transaction with one input. | """Creates and signs a valid raw transaction with one input. | ||||
Expected results: | Expected results: | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | def multiwallet_signing_test(self): | ||||
# Valid pay-to-pubkey scripts | # Valid pay-to-pubkey scripts | ||||
{'txid': '9b907ef1e3c26fc71fe4a4b3580bc75264112f95050014157059c736f0202e71', | {'txid': '9b907ef1e3c26fc71fe4a4b3580bc75264112f95050014157059c736f0202e71', | ||||
'vout': 0, 'amount': 3.14159, | 'vout': 0, 'amount': 3.14159, | ||||
'scriptPubKey': '76a91460baa0f494b38ce3c940dea67f3804dc52d1fb9488ac'}, | 'scriptPubKey': '76a91460baa0f494b38ce3c940dea67f3804dc52d1fb9488ac'}, | ||||
] | ] | ||||
outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} | outputs = {'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB': 0.1} | ||||
multiwallet_node = self.nodes[1] | multiwallet_node = self.nodes[0] | ||||
rawTx = multiwallet_node.createrawtransaction(inputs, outputs) | rawTx = multiwallet_node.createrawtransaction(inputs, outputs) | ||||
# The multiwallet node cannot sign the transaction if no wallet is | # The multiwallet node cannot sign the transaction if no wallet is | ||||
# specified | # specified | ||||
assert_raises_rpc_error(-19, RPC_WALLET_NOT_SPECIFIED, | assert_raises_rpc_error(-19, RPC_WALLET_NOT_SPECIFIED, | ||||
multiwallet_node.signrawtransactionwithwallet, | multiwallet_node.signrawtransactionwithwallet, | ||||
rawTx) | rawTx) | ||||
Show All 15 Lines | def multiwallet_signing_test(self): | ||||
rawTxSigned_w1 = w1.signrawtransactionwithwallet(rawTx_w1) | rawTxSigned_w1 = w1.signrawtransactionwithwallet(rawTx_w1) | ||||
assert rawTxSigned_w1['complete'] | assert rawTxSigned_w1['complete'] | ||||
assert 'errors' not in rawTxSigned_w1 | assert 'errors' not in rawTxSigned_w1 | ||||
def run_test(self): | def run_test(self): | ||||
self.successful_signing_test() | self.successful_signing_test() | ||||
self.script_verification_error_test() | self.script_verification_error_test() | ||||
self.test_sighashes() | self.test_sighashes() | ||||
self.multiwallet_signing_test() | |||||
self.test_with_lock_outputs() | self.test_with_lock_outputs() | ||||
# The multiwalet require the node to use different flags, so we run it | |||||
# last. | |||||
self.restart_node(0, ["-wallet=w1", "-wallet=w2"]) | |||||
self.multiwallet_signing_test() | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
SignRawTransactionsTest().main() | SignRawTransactionsTest().main() |