Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rawtransactions.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-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. | ||||
"""rawtranscation RPCs QA test. | """rawtranscation RPCs QA test. | ||||
# Tests the following RPCs: | # Tests the following RPCs: | ||||
# - createrawtransaction | # - createrawtransaction | ||||
# - signrawtransaction | # - signrawtransactionwithwallet | ||||
# - sendrawtransaction | # - sendrawtransaction | ||||
# - decoderawtransaction | # - decoderawtransaction | ||||
# - getrawtransaction | # - getrawtransaction | ||||
""" | """ | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.txtools import pad_raw_tx | from test_framework.txtools import pad_raw_tx | ||||
# Create one-input, one-output, no-fee transaction: | # Create one-input, one-output, no-fee transaction: | ||||
class RawTransactionsTest(BitcoinTestFramework): | class RawTransactionsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 3 | self.num_nodes = 3 | ||||
self.extra_args = [ | |||||
[], ["-deprecatedrpc=signrawtransaction"], ["-deprecatedrpc=signrawtransaction"]] | |||||
def setup_network(self, split=False): | def setup_network(self, split=False): | ||||
super().setup_network() | super().setup_network() | ||||
connect_nodes_bi(self.nodes, 0, 2) | connect_nodes_bi(self.nodes, 0, 2) | ||||
def run_test(self): | def run_test(self): | ||||
# prepare some coins for multiple *rawtransaction commands | # prepare some coins for multiple *rawtransaction commands | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
Show All 11 Lines | def run_test(self): | ||||
# sendrawtransaction with missing input # | # sendrawtransaction with missing input # | ||||
# | # | ||||
inputs = [ | inputs = [ | ||||
{'txid': "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout': 1}] | {'txid': "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout': 1}] | ||||
# won't exists | # won't exists | ||||
outputs = {self.nodes[0].getnewaddress(): 4.998} | outputs = {self.nodes[0].getnewaddress(): 4.998} | ||||
rawtx = self.nodes[2].createrawtransaction(inputs, outputs) | rawtx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
rawtx = pad_raw_tx(rawtx) | rawtx = pad_raw_tx(rawtx) | ||||
rawtx = self.nodes[2].signrawtransaction(rawtx) | rawtx = self.nodes[2].signrawtransactionwithwallet(rawtx) | ||||
# This will raise an exception since there are missing inputs | # This will raise an exception since there are missing inputs | ||||
assert_raises_rpc_error( | assert_raises_rpc_error( | ||||
-25, "Missing inputs", self.nodes[2].sendrawtransaction, rawtx['hex']) | -25, "Missing inputs", self.nodes[2].sendrawtransaction, rawtx['hex']) | ||||
# | # | ||||
# RAW TX MULTISIG TESTS # | # RAW TX MULTISIG TESTS # | ||||
# | # | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
inputs = [{ | inputs = [{ | ||||
"txid": txId, | "txid": txId, | ||||
"vout": vout['n'], | "vout": vout['n'], | ||||
"scriptPubKey": vout['scriptPubKey']['hex'], | "scriptPubKey": vout['scriptPubKey']['hex'], | ||||
"amount": vout['value'], | "amount": vout['value'], | ||||
}] | }] | ||||
outputs = {self.nodes[0].getnewaddress(): 2.19} | outputs = {self.nodes[0].getnewaddress(): 2.19} | ||||
rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | rawTx = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
rawTxPartialSigned = self.nodes[1].signrawtransaction(rawTx, inputs) | rawTxPartialSigned = self.nodes[1].signrawtransactionwithwallet( | ||||
rawTx, inputs) | |||||
# node1 only has one key, can't comp. sign the tx | # node1 only has one key, can't comp. sign the tx | ||||
assert_equal(rawTxPartialSigned['complete'], False) | assert_equal(rawTxPartialSigned['complete'], False) | ||||
rawTxSigned = self.nodes[2].signrawtransaction(rawTx, inputs) | rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx, inputs) | ||||
# node2 can sign the tx compl., own two of three keys | # node2 can sign the tx compl., own two of three keys | ||||
assert_equal(rawTxSigned['complete'], True) | assert_equal(rawTxSigned['complete'], True) | ||||
self.nodes[2].sendrawtransaction(rawTxSigned['hex']) | self.nodes[2].sendrawtransaction(rawTxSigned['hex']) | ||||
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex']) | rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex']) | ||||
self.sync_all() | self.sync_all() | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all() | self.sync_all() | ||||
assert_equal(self.nodes[0].getbalance(), bal + Decimal( | assert_equal(self.nodes[0].getbalance(), bal + Decimal( | ||||
Show All 31 Lines | def run_test(self): | ||||
vout = outpoint | vout = outpoint | ||||
break | break | ||||
bal = self.nodes[0].getbalance() | bal = self.nodes[0].getbalance() | ||||
inputs = [{"txid": txId, "vout": vout['n'], "scriptPubKey": vout['scriptPubKey'] | inputs = [{"txid": txId, "vout": vout['n'], "scriptPubKey": vout['scriptPubKey'] | ||||
['hex'], "redeemScript": mSigObjValid['hex'], "amount": vout['value']}] | ['hex'], "redeemScript": mSigObjValid['hex'], "amount": vout['value']}] | ||||
outputs = {self.nodes[0].getnewaddress(): 2.19} | outputs = {self.nodes[0].getnewaddress(): 2.19} | ||||
rawTx2 = self.nodes[2].createrawtransaction(inputs, outputs) | rawTx2 = self.nodes[2].createrawtransaction(inputs, outputs) | ||||
rawTxPartialSigned1 = self.nodes[1].signrawtransaction(rawTx2, inputs) | rawTxPartialSigned1 = self.nodes[1].signrawtransactionwithwallet( | ||||
rawTx2, inputs) | |||||
self.log.info(rawTxPartialSigned1) | self.log.info(rawTxPartialSigned1) | ||||
# node1 only has one key, can't comp. sign the tx | # node1 only has one key, can't comp. sign the tx | ||||
assert_equal(rawTxPartialSigned['complete'], False) | assert_equal(rawTxPartialSigned['complete'], False) | ||||
rawTxPartialSigned2 = self.nodes[2].signrawtransaction(rawTx2, inputs) | rawTxPartialSigned2 = self.nodes[2].signrawtransactionwithwallet( | ||||
rawTx2, inputs) | |||||
self.log.info(rawTxPartialSigned2) | self.log.info(rawTxPartialSigned2) | ||||
# node2 only has one key, can't comp. sign the tx | # node2 only has one key, can't comp. sign the tx | ||||
assert_equal(rawTxPartialSigned2['complete'], False) | assert_equal(rawTxPartialSigned2['complete'], False) | ||||
rawTxComb = self.nodes[2].combinerawtransaction( | rawTxComb = self.nodes[2].combinerawtransaction( | ||||
[rawTxPartialSigned1['hex'], rawTxPartialSigned2['hex']]) | [rawTxPartialSigned1['hex'], rawTxPartialSigned2['hex']]) | ||||
self.log.info(rawTxComb) | self.log.info(rawTxComb) | ||||
self.nodes[2].sendrawtransaction(rawTxComb) | self.nodes[2].sendrawtransaction(rawTxComb) | ||||
rawTx2 = self.nodes[0].decoderawtransaction(rawTxComb) | rawTx2 = self.nodes[0].decoderawtransaction(rawTxComb) | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |