Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 581 Lines • ▼ Show 20 Lines | def on_getheaders(self, message): | ||||
# Truncate the list if there are too many headers | # Truncate the list if there are too many headers | ||||
headers_list = headers_list[:-maxheaders - 1:-1] | headers_list = headers_list[:-maxheaders - 1:-1] | ||||
response = msg_headers(headers_list) | response = msg_headers(headers_list) | ||||
if response is not None: | if response is not None: | ||||
self.send_message(response) | self.send_message(response) | ||||
def send_blocks_and_test(self, blocks, node, *, success=True, request_block=True, | def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, reject_reason=None, expect_disconnect=False, timeout=60): | ||||
reject_reason=None, expect_disconnect=False, timeout=60): | |||||
"""Send blocks to test node and test whether the tip advances. | """Send blocks to test node and test whether the tip advances. | ||||
- add all blocks to our block_store | - add all blocks to our block_store | ||||
- send a headers message for the final block | - send a headers message for the final block | ||||
- the on_getheaders handler will ensure that any getheaders are responded to | - the on_getheaders handler will ensure that any getheaders are responded to | ||||
- if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will | - if force_send is False: wait for getdata for each of the blocks. The on_getdata handler will | ||||
ensure that any getdata messages are responded to | ensure that any getdata messages are responded to. Otherwise send the full block unsolicited. | ||||
- if success is True: assert that the node's tip advances to the most recent block | - if success is True: assert that the node's tip advances to the most recent block | ||||
- if success is False: assert that the node's tip doesn't advance | - if success is False: assert that the node's tip doesn't advance | ||||
- if reject_reason is set: assert that the correct reject message is logged""" | - if reject_reason is set: assert that the correct reject message is logged""" | ||||
with mininode_lock: | with mininode_lock: | ||||
for block in blocks: | for block in blocks: | ||||
self.block_store[block.sha256] = block | self.block_store[block.sha256] = block | ||||
self.last_block_hash = block.sha256 | self.last_block_hash = block.sha256 | ||||
def test(): | def test(): | ||||
self.send_message(msg_headers([CBlockHeader(blocks[-1])])) | if force_send: | ||||
for b in blocks: | |||||
self.send_message(msg_block(block=b)) | |||||
if request_block: | else: | ||||
self.send_message(msg_headers([CBlockHeader(blocks[-1])])) | |||||
wait_until( | wait_until( | ||||
lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock) | lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock) | ||||
if expect_disconnect: | if expect_disconnect: | ||||
self.wait_for_disconnect(timeout=timeout) | self.wait_for_disconnect(timeout=timeout) | ||||
else: | else: | ||||
self.sync_with_ping(timeout=timeout) | self.sync_with_ping(timeout=timeout) | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |