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:
Sebastian Falbesoner
2021-06-15 23:02:28 +02:00
parent 965e937434
commit 2ce7b47958
22 changed files with 257 additions and 152 deletions

View File

@ -15,9 +15,52 @@ from test_framework.blocktools import (
add_witness_commitment,
create_block,
)
from test_framework.messages import BlockTransactions, BlockTransactionsRequest, calculate_shortid, CBlock, CBlockHeader, CInv, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, FromHex, HeaderAndShortIDs, msg_no_witness_block, msg_no_witness_blocktxn, msg_cmpctblock, msg_getblocktxn, msg_getdata, msg_getheaders, msg_headers, msg_inv, msg_sendcmpct, msg_sendheaders, msg_tx, msg_block, msg_blocktxn, MSG_BLOCK, MSG_CMPCT_BLOCK, MSG_WITNESS_FLAG, NODE_NETWORK, P2PHeaderAndShortIDs, PrefilledTransaction, ser_uint256, ToHex
from test_framework.p2p import p2p_lock, P2PInterface
from test_framework.script import CScript, OP_TRUE, OP_DROP
from test_framework.messages import (
BlockTransactions,
BlockTransactionsRequest,
CBlock,
CBlockHeader,
CInv,
COutPoint,
CTransaction,
CTxIn,
CTxInWitness,
CTxOut,
FromHex,
HeaderAndShortIDs,
MSG_BLOCK,
MSG_CMPCT_BLOCK,
MSG_WITNESS_FLAG,
NODE_NETWORK,
P2PHeaderAndShortIDs,
PrefilledTransaction,
ToHex,
calculate_shortid,
msg_block,
msg_blocktxn,
msg_cmpctblock,
msg_getblocktxn,
msg_getdata,
msg_getheaders,
msg_headers,
msg_inv,
msg_no_witness_block,
msg_no_witness_blocktxn,
msg_sendcmpct,
msg_sendheaders,
msg_tx,
ser_uint256,
tx_from_hex,
)
from test_framework.p2p import (
P2PInterface,
p2p_lock,
)
from test_framework.script import (
CScript,
OP_DROP,
OP_TRUE,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, softfork_active
@ -257,7 +300,7 @@ class CompactBlocksTest(BitcoinTestFramework):
for _ in range(num_transactions):
txid = node.sendtoaddress(address, 0.1)
hex_tx = node.gettransaction(txid)["hex"]
tx = FromHex(CTransaction(), hex_tx)
tx = tx_from_hex(hex_tx)
if not tx.wit.is_null():
segwit_tx_generated = True