Skip to content

Commit 9a0b2f4

Browse files
committed
[qa] Make compact blocks test construction using fetch methods
1 parent 8017547 commit 9a0b2f4

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

qa/rpc-tests/p2p-compactblocks.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
310310
tip = int(node.getbestblockhash(), 16)
311311
assert(test_node.wait_for_block_announcement(tip))
312312

313+
# Make sure we will receive a fast-announce compact block
314+
self.request_cb_announcements(test_node, node, version)
315+
313316
# Now mine a block, and look at the resulting compact block.
314317
test_node.clear_block_announcement()
315318
block_hash = int(node.generate(1)[0], 16)
@@ -319,27 +322,36 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
319322
[tx.calc_sha256() for tx in block.vtx]
320323
block.rehash()
321324

322-
# Don't care which type of announcement came back for this test; just
323-
# request the compact block if we didn't get one yet.
325+
# Wait until the block was announced (via compact blocks)
324326
wait_until(test_node.received_block_announcement, timeout=30)
325327
assert(test_node.received_block_announcement())
326328

329+
# Now fetch and check the compact block
330+
header_and_shortids = None
331+
with mininode_lock:
332+
assert(test_node.last_cmpctblock is not None)
333+
# Convert the on-the-wire representation to absolute indexes
334+
header_and_shortids = HeaderAndShortIDs(test_node.last_cmpctblock.header_and_shortids)
335+
self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block)
336+
337+
# Now fetch the compact block using a normal non-announce getdata
327338
with mininode_lock:
328-
if test_node.last_cmpctblock is None:
329-
test_node.clear_block_announcement()
330-
inv = CInv(4, block_hash) # 4 == "CompactBlock"
331-
test_node.send_message(msg_getdata([inv]))
339+
test_node.clear_block_announcement()
340+
inv = CInv(4, block_hash) # 4 == "CompactBlock"
341+
test_node.send_message(msg_getdata([inv]))
332342

333343
wait_until(test_node.received_block_announcement, timeout=30)
334344
assert(test_node.received_block_announcement())
335345

336-
# Now we should have the compactblock
346+
# Now fetch and check the compact block
337347
header_and_shortids = None
338348
with mininode_lock:
339349
assert(test_node.last_cmpctblock is not None)
340350
# Convert the on-the-wire representation to absolute indexes
341351
header_and_shortids = HeaderAndShortIDs(test_node.last_cmpctblock.header_and_shortids)
352+
self.check_compactblock_construction_from_block(version, header_and_shortids, block_hash, block)
342353

354+
def check_compactblock_construction_from_block(self, version, header_and_shortids, block_hash, block):
343355
# Check that we got the right block!
344356
header_and_shortids.header.calc_sha256()
345357
assert_equal(header_and_shortids.header.sha256, block_hash)

0 commit comments

Comments
 (0)