Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_rawtransaction.py
Show All 19 Lines | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.txtools import pad_raw_tx | from test_framework.txtools import pad_raw_tx | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes_bi, | connect_nodes_bi, | ||||
hex_str_to_bytes, | hex_str_to_bytes, | ||||
bytes_to_hex_str, | |||||
) | ) | ||||
class multidict(dict): | class multidict(dict): | ||||
"""Dictionary that allows duplicate keys. | """Dictionary that allows duplicate keys. | ||||
Constructed with a list of (key, value) tuples. When dumped by the json module, | Constructed with a list of (key, value) tuples. When dumped by the json module, | ||||
will output invalid json with repeated keys, eg: | will output invalid json with repeated keys, eg: | ||||
>>> json.dumps(multidict([(1,2),(1,2)]) | >>> json.dumps(multidict([(1,2),(1,2)]) | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info( | self.log.info( | ||||
'Check that createrawtransaction accepts an array and object as outputs') | 'Check that createrawtransaction accepts an array and object as outputs') | ||||
tx = CTransaction() | tx = CTransaction() | ||||
# One output | # One output | ||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction( | tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction( | ||||
inputs=[{'txid': txid, 'vout': 9}], outputs={address: 99})))) | inputs=[{'txid': txid, 'vout': 9}], outputs={address: 99})))) | ||||
assert_equal(len(tx.vout), 1) | assert_equal(len(tx.vout), 1) | ||||
assert_equal( | assert_equal( | ||||
bytes_to_hex_str(tx.serialize()), | tx.serialize().hex(), | ||||
self.nodes[2].createrawtransaction( | self.nodes[2].createrawtransaction( | ||||
inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}]), | inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}]), | ||||
) | ) | ||||
# Two outputs | # Two outputs | ||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[ | tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[ | ||||
{'txid': txid, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)]))))) | {'txid': txid, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)]))))) | ||||
assert_equal(len(tx.vout), 2) | assert_equal(len(tx.vout), 2) | ||||
assert_equal( | assert_equal( | ||||
bytes_to_hex_str(tx.serialize()), | tx.serialize().hex(), | ||||
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[ | self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[ | ||||
{address: 99}, {address2: 99}]), | {address: 99}, {address2: 99}]), | ||||
) | ) | ||||
# Two data outputs | # Two data outputs | ||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[ | tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[ | ||||
{'txid': txid, 'vout': 9}], outputs=multidict([('data', '99'), ('data', '99')]))))) | {'txid': txid, 'vout': 9}], outputs=multidict([('data', '99'), ('data', '99')]))))) | ||||
assert_equal(len(tx.vout), 2) | assert_equal(len(tx.vout), 2) | ||||
assert_equal( | assert_equal( | ||||
bytes_to_hex_str(tx.serialize()), | tx.serialize().hex(), | ||||
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[ | self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[ | ||||
{'data': '99'}, {'data': '99'}]), | {'data': '99'}, {'data': '99'}]), | ||||
) | ) | ||||
# Multiple mixed outputs | # Multiple mixed outputs | ||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[ | tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[ | ||||
{'txid': txid, 'vout': 9}], outputs=multidict([(address, 99), ('data', '99'), ('data', '99')]))))) | {'txid': txid, 'vout': 9}], outputs=multidict([(address, 99), ('data', '99'), ('data', '99')]))))) | ||||
assert_equal(len(tx.vout), 3) | assert_equal(len(tx.vout), 3) | ||||
assert_equal( | assert_equal( | ||||
bytes_to_hex_str(tx.serialize()), | tx.serialize().hex(), | ||||
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[ | self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[ | ||||
{address: 99}, {'data': '99'}, {'data': '99'}]), | {address: 99}, {'data': '99'}, {'data': '99'}]), | ||||
) | ) | ||||
self.log.info('sendrawtransaction with missing input') | self.log.info('sendrawtransaction with missing input') | ||||
# won't exists | # won't exists | ||||
inputs = [ | inputs = [ | ||||
{'txid': "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout': 1}] | {'txid': "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout': 1}] | ||||
▲ Show 20 Lines • Show All 312 Lines • Show Last 20 Lines |