aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_compactblocks.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/p2p_compactblocks.py')
-rwxr-xr-xtest/functional/p2p_compactblocks.py65
1 files changed, 55 insertions, 10 deletions
diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py
index 3e4f2f974d..b4e662de2e 100755
--- a/test/functional/p2p_compactblocks.py
+++ b/test/functional/p2p_compactblocks.py
@@ -15,11 +15,56 @@ 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,
+ from_hex,
+ HeaderAndShortIDs,
+ MSG_BLOCK,
+ MSG_CMPCT_BLOCK,
+ MSG_WITNESS_FLAG,
+ NODE_NETWORK,
+ P2PHeaderAndShortIDs,
+ PrefilledTransaction,
+ 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
+from test_framework.util import (
+ assert_equal,
+ softfork_active,
+)
# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
class TestP2PConn(P2PInterface):
@@ -257,7 +302,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
@@ -276,7 +321,7 @@ class CompactBlocksTest(BitcoinTestFramework):
block_hash = int(node.generate(1)[0], 16)
# Store the raw block in our internal format.
- block = FromHex(CBlock(), node.getblock("%064x" % block_hash, False))
+ block = from_hex(CBlock(), node.getblock("%064x" % block_hash, False))
for tx in block.vtx:
tx.calc_sha256()
block.rehash()
@@ -569,7 +614,7 @@ class CompactBlocksTest(BitcoinTestFramework):
current_height = chain_height
while (current_height >= chain_height - MAX_GETBLOCKTXN_DEPTH):
block_hash = node.getblockhash(current_height)
- block = FromHex(CBlock(), node.getblock(block_hash, False))
+ block = from_hex(CBlock(), node.getblock(block_hash, False))
msg = msg_getblocktxn()
msg.block_txn_request = BlockTransactionsRequest(int(block_hash, 16), [])
@@ -672,9 +717,9 @@ class CompactBlocksTest(BitcoinTestFramework):
[l.clear_block_announcement() for l in listeners]
- # ToHex() won't serialize with witness, but this block has no witnesses
- # anyway. TODO: repeat this test with witness tx's to a segwit node.
- node.submitblock(ToHex(block))
+ # serialize without witness (this block has no witnesses anyway).
+ # TODO: repeat this test with witness tx's to a segwit node.
+ node.submitblock(block.serialize().hex())
for l in listeners:
l.wait_until(lambda: "cmpctblock" in l.last_message, timeout=30)