Beispiel #1
0
 def send_fetch_block(self, block_idx):
     """
     Fetch Block n
     Sends request for the block number n.
     :return:
     """
     logger.info('<<<Fetching block: %s from %s', block_idx, self.peer)
     msg = qrllegacy_pb2.LegacyMessage(func_name=qrllegacy_pb2.LegacyMessage.FB,
                                       fbData=qrllegacy_pb2.FBData(index=block_idx))
     self.send(msg)
Beispiel #2
0
    def test_handle_fetch_block_bad_height(self, m_logger):
        """
        If the peer has sent a request for a block which we don't have, nothing should happen.
        :return:
        """
        self.channel.factory.chain_height = 10
        msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.FB,
                           fbData=qrllegacy_pb2.FBData(index=100))
        self.manager.handle_fetch_block(self.channel, msg)

        self.channel.send.assert_not_called()
Beispiel #3
0
    def test_handle_fetch_block(self, m_logger):
        """
        1. A peer has sent a request for a block.
        2. This function serves the block in response to that request.
        :return:
        """
        self.channel.factory.chain_height = 10
        self.channel.factory.get_block_by_number.return_value = Mock(
            autospec=Block, pbdata=qrl_pb2.Block())
        msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.FB,
                           fbData=qrllegacy_pb2.FBData(index=1))
        self.manager.handle_fetch_block(self.channel, msg)

        self.channel.send.assert_called()