def test_sendcmpct(self, test_node, old_node=None):
    preferred_version = test_node.cmpct_version
    node = self.nodes[0]

    def received_sendcmpct():
        return (len(test_node.last_sendcmpct) > 0)
    wait_until(received_sendcmpct, timeout=30, lock=mininode_lock)
    with mininode_lock:
        assert_equal(test_node.last_sendcmpct[0].version, preferred_version)
        assert_equal(test_node.last_sendcmpct[(- 1)].version, 1)
        test_node.last_sendcmpct = []
    tip = int(node.getbestblockhash(), 16)

    def check_announcement_of_new_block(node, peer, predicate):
        peer.clear_block_announcement()
        block_hash = int(node.generate(1)[0], 16)
        peer.wait_for_block_announcement(block_hash, timeout=30)
        assert peer.block_announced
        with mininode_lock:
            assert predicate(peer), 'block_hash={!r}, cmpctblock={!r}, inv={!r}'.format(block_hash, peer.last_message.get('cmpctblock', None), peer.last_message.get('inv', None))
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' not in p.last_message)))
    test_node.request_headers_and_sync(locator=[tip])
    check_announcement_of_new_block(node, test_node, (lambda p: (('cmpctblock' not in p.last_message) and ('inv' in p.last_message))))
    test_node.request_headers_and_sync(locator=[tip])
    sendcmpct = msg_sendcmpct()
    sendcmpct.version = (preferred_version + 1)
    sendcmpct.announce = True
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' not in p.last_message)))
    test_node.request_headers_and_sync(locator=[tip])
    sendcmpct.version = preferred_version
    sendcmpct.announce = False
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' not in p.last_message)))
    test_node.request_headers_and_sync(locator=[tip])
    sendcmpct.version = preferred_version
    sendcmpct.announce = True
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    test_node.send_and_ping(msg_sendheaders())
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    sendcmpct.version = (preferred_version - 1)
    sendcmpct.announce = False
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    sendcmpct.version = preferred_version
    sendcmpct.announce = False
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: (('cmpctblock' not in p.last_message) and ('headers' in p.last_message))))
    if (old_node is not None):
        sendcmpct.version = (preferred_version - 1)
        sendcmpct.announce = True
        old_node.send_and_ping(sendcmpct)
        old_node.request_headers_and_sync(locator=[tip])
        check_announcement_of_new_block(node, old_node, (lambda p: ('cmpctblock' in p.last_message)))
def test_sendcmpct(self, test_node, old_node=None):
    preferred_version = test_node.cmpct_version
    node = self.nodes[0]

    def received_sendcmpct():
        return (len(test_node.last_sendcmpct) > 0)
    wait_until(received_sendcmpct, timeout=30, lock=mininode_lock)
    with mininode_lock:
        assert_equal(test_node.last_sendcmpct[0].version, preferred_version)
        assert_equal(test_node.last_sendcmpct[(- 1)].version, 1)
        test_node.last_sendcmpct = []
    tip = int(node.getbestblockhash(), 16)

    def check_announcement_of_new_block(node, peer, predicate):
        peer.clear_block_announcement()
        block_hash = int(node.generate(1)[0], 16)
        peer.wait_for_block_announcement(block_hash, timeout=30)
        assert peer.block_announced
        with mininode_lock:
            assert predicate(peer), 'block_hash={!r}, cmpctblock={!r}, inv={!r}'.format(block_hash, peer.last_message.get('cmpctblock', None), peer.last_message.get('inv', None))
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' not in p.last_message)))
    test_node.request_headers_and_sync(locator=[tip])
    check_announcement_of_new_block(node, test_node, (lambda p: (('cmpctblock' not in p.last_message) and ('inv' in p.last_message))))
    test_node.request_headers_and_sync(locator=[tip])
    sendcmpct = msg_sendcmpct()
    sendcmpct.version = (preferred_version + 1)
    sendcmpct.announce = True
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' not in p.last_message)))
    test_node.request_headers_and_sync(locator=[tip])
    sendcmpct.version = preferred_version
    sendcmpct.announce = False
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' not in p.last_message)))
    test_node.request_headers_and_sync(locator=[tip])
    sendcmpct.version = preferred_version
    sendcmpct.announce = True
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    test_node.send_and_ping(msg_sendheaders())
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    sendcmpct.version = (preferred_version - 1)
    sendcmpct.announce = False
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: ('cmpctblock' in p.last_message)))
    sendcmpct.version = preferred_version
    sendcmpct.announce = False
    test_node.send_and_ping(sendcmpct)
    check_announcement_of_new_block(node, test_node, (lambda p: (('cmpctblock' not in p.last_message) and ('headers' in p.last_message))))
    if (old_node is not None):
        sendcmpct.version = (preferred_version - 1)
        sendcmpct.announce = True
        old_node.send_and_ping(sendcmpct)
        old_node.request_headers_and_sync(locator=[tip])
        check_announcement_of_new_block(node, old_node, (lambda p: ('cmpctblock' in p.last_message)))