def test_headers_message_one_block_not_in_flight(self):
        header1 = CBlockHeader(nNonce=1)
        header2 = CBlockHeader(nNonce=2)
        message = messages.msg_headers()
        message.headers = [header1, header2]
        self.networking.blocks_in_flight = {header1.GetHash(): 'in_flight'}

        self.networking.headers_message(self.private_connection, message)

        self.assertEqual(self.private_connection.send.call_args[0][0],
                         'getdata')
        self.assertEqual(len(self.private_connection.send.call_args[0][1].inv),
                         1)
    def test_headers_message_two_unknown_blocks(self):
        header1 = CBlockHeader(nNonce=1)
        header2 = CBlockHeader(nNonce=2)

        message = messages.msg_headers()
        message.headers = [header1, header2]
        self.networking.blocks_in_flight = {}
        self.networking.request_blocks = MagicMock()

        self.networking.headers_message(self.private_connection, message)

        self.assertEqual(self.chain.process_header.call_count, 2)
        self.assertEqual(self.chain.process_header.call_args[0][1],
                         BlockOrigin.private)

        self.assertTrue(self.networking.request_blocks.called)
        self.assertEqual(len(self.networking.request_blocks.call_args[0][1]),
                         2)
        self.assertIn(header1.GetHash(),
                      self.networking.request_blocks.call_args[0][1])
        self.assertIn(header2.GetHash(),
                      self.networking.request_blocks.call_args[0][1])