예제 #1
0
    def test_handle_push_block(self, m_logger):
        """
        1. This node has requested a peer to send us its MessageReceipts
        2. The node has received a list of Block headers
        3. The node has requested a specific block.
        4. The peer sends the new block, which is handled by this function?
        :return:
        """
        msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.PB,
                           pbData=qrllegacy_pb2.PBData(block=qrl_pb2.Block()))
        self.manager.handle_push_block(self.channel, msg)

        self.channel.factory.block_received.assert_called()
예제 #2
0
    def handle_fetch_block(self, source, message: qrllegacy_pb2.LegacyMessage):  # Fetch Request for block
        """
        Fetch Block
        Sends the request for the block.
        :return:
        """
        P2PBaseObserver._validate_message(message, qrllegacy_pb2.LegacyMessage.FB)

        block_number = message.fbData.index

        logger.info(' Request for %s by %s', block_number, source.connection_id)
        if 0 < block_number <= source.factory.chain_height:
            block = source.factory.get_block(block_number)
            msg = qrllegacy_pb2.LegacyMessage(func_name=qrllegacy_pb2.LegacyMessage.PB,
                                              pbData=qrllegacy_pb2.PBData(block=block.pbdata))
            source.send(msg)
예제 #3
0
    def test_handle_push_block_bad_block(self, m_Block, m_logger):
        """
        If the Block couldn't be constructed from the Protobuf data, nothing should happen.
        (including disconnecting the peer? dunno)
        :return:
        """
        # Case 1: Block() raises an Exception
        m_Block.side_effect = Exception
        msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.PB,
                           pbData=qrllegacy_pb2.PBData(block=qrl_pb2.Block()))
        self.manager.handle_push_block(self.channel, msg)

        self.channel.factory.block_received.assert_not_called()

        # Case 2: no protobuf data was in the message.
        msg = make_message(func_name=qrllegacy_pb2.LegacyMessage.PB)
        self.manager.handle_push_block(self.channel, msg)

        self.channel.factory.block_received.assert_not_called()