mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-10 11:33:46 +02:00
test: introduce tx_from_hex
helper for tx deserialization
`FromHex` is mostly used for transactions, so we introduce a shortcut `tx_from_hex` for `FromHex(CTransaction, hex_str)`.
This commit is contained in:
@@ -14,16 +14,18 @@ Test the following RPCs:
|
||||
|
||||
from collections import OrderedDict
|
||||
from decimal import Decimal
|
||||
from io import BytesIO
|
||||
|
||||
from test_framework.blocktools import COINBASE_MATURITY
|
||||
from test_framework.messages import CTransaction, ToHex
|
||||
from test_framework.messages import (
|
||||
CTransaction,
|
||||
ToHex,
|
||||
tx_from_hex,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
find_vout_for_address,
|
||||
hex_str_to_bytes,
|
||||
)
|
||||
|
||||
|
||||
@@ -127,23 +129,22 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
assert_raises_rpc_error(-3, "Expected type bool", self.nodes[0].createrawtransaction, [], {}, 0, 'foo')
|
||||
|
||||
self.log.info('Check that createrawtransaction accepts an array and object as outputs')
|
||||
tx = CTransaction()
|
||||
# One output
|
||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs={address: 99}))))
|
||||
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs={address: 99}))
|
||||
assert_equal(len(tx.vout), 1)
|
||||
assert_equal(
|
||||
tx.serialize().hex(),
|
||||
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}]),
|
||||
)
|
||||
# Two outputs
|
||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)])))))
|
||||
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=OrderedDict([(address, 99), (address2, 99)])))
|
||||
assert_equal(len(tx.vout), 2)
|
||||
assert_equal(
|
||||
tx.serialize().hex(),
|
||||
self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=[{address: 99}, {address2: 99}]),
|
||||
)
|
||||
# Multiple mixed outputs
|
||||
tx.deserialize(BytesIO(hex_str_to_bytes(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=multidict([(address, 99), (address2, 99), ('data', '99')])))))
|
||||
tx = tx_from_hex(self.nodes[2].createrawtransaction(inputs=[{'txid': txid, 'vout': 9}], outputs=multidict([(address, 99), (address2, 99), ('data', '99')])))
|
||||
assert_equal(len(tx.vout), 3)
|
||||
assert_equal(
|
||||
tx.serialize().hex(),
|
||||
|
Reference in New Issue
Block a user