Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_locator.py
Show All 24 Lines | def run_test(self): | ||||
# Get node out of IBD | # Get node out of IBD | ||||
node.generatetoaddress(1, node.get_deterministic_priv_key().address) | node.generatetoaddress(1, node.get_deterministic_priv_key().address) | ||||
self.log.info('Test max locator size') | self.log.info('Test max locator size') | ||||
block_count = node.getblockcount() | block_count = node.getblockcount() | ||||
for msg in [msg_getheaders(), msg_getblocks()]: | for msg in [msg_getheaders(), msg_getblocks()]: | ||||
self.log.info('Wait for disconnect when sending {} hashes in locator'.format( | self.log.info('Wait for disconnect when sending {} hashes in locator'.format( | ||||
MAX_LOCATOR_SZ + 1)) | MAX_LOCATOR_SZ + 1)) | ||||
node.add_p2p_connection(P2PInterface()) | exceed_max_peer = node.add_p2p_connection(P2PInterface()) | ||||
msg.locator.vHave = [int(node.getblockhash( | msg.locator.vHave = [int(node.getblockhash( | ||||
i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ + 1), -1)] | i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ + 1), -1)] | ||||
node.p2p.send_message(msg) | exceed_max_peer.send_message(msg) | ||||
node.p2p.wait_for_disconnect() | exceed_max_peer.wait_for_disconnect() | ||||
node.disconnect_p2ps() | |||||
self.log.info( | self.log.info( | ||||
'Wait for response when sending {} hashes in locator'.format(MAX_LOCATOR_SZ)) | 'Wait for response when sending {} hashes in locator'.format(MAX_LOCATOR_SZ)) | ||||
node.add_p2p_connection(P2PInterface()) | within_max_peer = node.add_p2p_connection(P2PInterface()) | ||||
msg.locator.vHave = [int(node.getblockhash( | msg.locator.vHave = [int(node.getblockhash( | ||||
i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)] | i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)] | ||||
node.p2p.send_message(msg) | within_max_peer.send_message(msg) | ||||
if isinstance(msg, msg_getheaders): | if isinstance(msg, msg_getheaders): | ||||
node.p2p.wait_for_header(node.getbestblockhash()) | within_max_peer.wait_for_header(node.getbestblockhash()) | ||||
else: | else: | ||||
node.p2p.wait_for_block(int(node.getbestblockhash(), 16)) | within_max_peer.wait_for_block( | ||||
int(node.getbestblockhash(), 16)) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
InvalidLocatorTest().main() | InvalidLocatorTest().main() |