def test_incorrect_blocktxn_response(self, test_node):
    version = test_node.cmpct_version
    node = self.nodes[0]
    utxo = self.utxos.pop(0)
    block = self.build_block_with_transactions(node, utxo, 10)
    self.utxos.append([block.vtx[(- 1)].sha256, 0, block.vtx[(- 1)].vout[0].nValue])
    for tx in block.vtx[1:6]:
        test_node.send_message(msg_tx(tx))
    test_node.sync_with_ping()
    mempool = node.getrawmempool()
    for tx in block.vtx[1:6]:
        assert (tx.hash in mempool)
    comp_block = HeaderAndShortIDs()
    comp_block.initialize_from_block(block, prefill_list=[0], use_witness=(version == 2))
    test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p()))
    absolute_indexes = []
    with mininode_lock:
        assert ('getblocktxn' in test_node.last_message)
        absolute_indexes = test_node.last_message['getblocktxn'].block_txn_request.to_absolute()
    assert_equal(absolute_indexes, [6, 7, 8, 9, 10])
    msg = msg_no_witness_blocktxn()
    if (version == 2):
        msg = msg_blocktxn()
    msg.block_transactions = BlockTransactions(block.sha256, ([block.vtx[5]] + block.vtx[7:]))
    test_node.send_and_ping(msg)
    assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock)
    wait_until((lambda : ('getdata' in test_node.last_message)), timeout=10, lock=mininode_lock)
    assert_equal(len(test_node.last_message['getdata'].inv), 1)
    assert ((test_node.last_message['getdata'].inv[0].type == 2) or (test_node.last_message['getdata'].inv[0].type == (2 | MSG_WITNESS_FLAG)))
    assert_equal(test_node.last_message['getdata'].inv[0].hash, block.sha256)
    if (version == 2):
        test_node.send_and_ping(msg_block(block))
    else:
        test_node.send_and_ping(msg_no_witness_block(block))
    assert_equal(int(node.getbestblockhash(), 16), block.sha256)
def test_incorrect_blocktxn_response(self, test_node):
    version = test_node.cmpct_version
    node = self.nodes[0]
    utxo = self.utxos.pop(0)
    block = self.build_block_with_transactions(node, utxo, 10)
    self.utxos.append([block.vtx[(- 1)].sha256, 0, block.vtx[(- 1)].vout[0].nValue])
    for tx in block.vtx[1:6]:
        test_node.send_message(msg_tx(tx))
    test_node.sync_with_ping()
    mempool = node.getrawmempool()
    for tx in block.vtx[1:6]:
        assert (tx.hash in mempool)
    comp_block = HeaderAndShortIDs()
    comp_block.initialize_from_block(block, prefill_list=[0], use_witness=(version == 2))
    test_node.send_and_ping(msg_cmpctblock(comp_block.to_p2p()))
    absolute_indexes = []
    with mininode_lock:
        assert ('getblocktxn' in test_node.last_message)
        absolute_indexes = test_node.last_message['getblocktxn'].block_txn_request.to_absolute()
    assert_equal(absolute_indexes, [6, 7, 8, 9, 10])
    msg = msg_no_witness_blocktxn()
    if (version == 2):
        msg = msg_blocktxn()
    msg.block_transactions = BlockTransactions(block.sha256, ([block.vtx[5]] + block.vtx[7:]))
    test_node.send_and_ping(msg)
    assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock)
    wait_until((lambda : ('getdata' in test_node.last_message)), timeout=10, lock=mininode_lock)
    assert_equal(len(test_node.last_message['getdata'].inv), 1)
    assert ((test_node.last_message['getdata'].inv[0].type == 2) or (test_node.last_message['getdata'].inv[0].type == (2 | MSG_WITNESS_FLAG)))
    assert_equal(test_node.last_message['getdata'].inv[0].hash, block.sha256)
    if (version == 2):
        test_node.send_and_ping(msg_block(block))
    else:
        test_node.send_and_ping(msg_no_witness_block(block))
    assert_equal(int(node.getbestblockhash(), 16), block.sha256)