0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-04 13:55:23 -05:00

test: Fix deser issue in create_block

Without the fix a hex-string can not be parsed:

File "./test/functional/test_framework/blocktools.py", line 82, in create_block
    txo.deserialize(io.BytesIO(tx))
TypeError: a bytes-like object is required, not 'str'

Also, remove io import and repace it with our FromHex() helper
This commit is contained in:
MarcoFalke 2020-11-03 12:04:03 +01:00
parent fa762a3fd4
commit fa1dea19fc
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -5,7 +5,6 @@
"""Utilities for manipulating blocks and transactions.""" """Utilities for manipulating blocks and transactions."""
from binascii import a2b_hex from binascii import a2b_hex
import io
import struct import struct
import time import time
import unittest import unittest
@ -45,7 +44,6 @@ from .script import (
hash160, hash160,
) )
from .util import assert_equal from .util import assert_equal
from io import BytesIO
WITNESS_SCALE_FACTOR = 4 WITNESS_SCALE_FACTOR = 4
MAX_BLOCK_SIGOPS = 20000 MAX_BLOCK_SIGOPS = 20000
@ -78,9 +76,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl
if txlist: if txlist:
for tx in txlist: for tx in txlist:
if not hasattr(tx, 'calc_sha256'): if not hasattr(tx, 'calc_sha256'):
txo = CTransaction() tx = FromHex(CTransaction(), tx)
txo.deserialize(io.BytesIO(tx))
tx = txo
block.vtx.append(tx) block.vtx.append(tx)
block.hashMerkleRoot = block.calc_merkle_root() block.hashMerkleRoot = block.calc_merkle_root()
block.calc_sha256() block.calc_sha256()
@ -166,8 +162,7 @@ def create_transaction(node, txid, to_address, *, amount):
sign for the output that is being spent. sign for the output that is being spent.
""" """
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount) raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
tx = CTransaction() tx = FromHex(CTransaction(), raw_tx)
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx)))
return tx return tx
def create_raw_transaction(node, txid, to_address, *, amount): def create_raw_transaction(node, txid, to_address, *, amount):