Skip to content

Commit fa1dea1

Browse files
author
MarcoFalke
committed
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
1 parent fa762a3 commit fa1dea1

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

test/functional/test_framework/blocktools.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Utilities for manipulating blocks and transactions."""
66

77
from binascii import a2b_hex
8-
import io
98
import struct
109
import time
1110
import unittest
@@ -45,7 +44,6 @@
4544
hash160,
4645
)
4746
from .util import assert_equal
48-
from io import BytesIO
4947

5048
WITNESS_SCALE_FACTOR = 4
5149
MAX_BLOCK_SIGOPS = 20000
@@ -78,9 +76,7 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl
7876
if txlist:
7977
for tx in txlist:
8078
if not hasattr(tx, 'calc_sha256'):
81-
txo = CTransaction()
82-
txo.deserialize(io.BytesIO(tx))
83-
tx = txo
79+
tx = FromHex(CTransaction(), tx)
8480
block.vtx.append(tx)
8581
block.hashMerkleRoot = block.calc_merkle_root()
8682
block.calc_sha256()
@@ -166,8 +162,7 @@ def create_transaction(node, txid, to_address, *, amount):
166162
sign for the output that is being spent.
167163
"""
168164
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
169-
tx = CTransaction()
170-
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx)))
165+
tx = FromHex(CTransaction(), raw_tx)
171166
return tx
172167

173168
def create_raw_transaction(node, txid, to_address, *, amount):

0 commit comments

Comments
 (0)