def test_summarize_block(self):
        self.mock_stream.send.return_value = self._make_future(
            message_type=Message.CONSENSUS_SUMMARIZE_BLOCK_RESPONSE,
            content=consensus_pb2.ConsensusSummarizeBlockResponse(
                status=consensus_pb2.ConsensusSummarizeBlockResponse.OK,
                summary=b'summary').SerializeToString())

        result = self.service.summarize_block()

        self.mock_stream.send.assert_called_with(
            message_type=Message.CONSENSUS_SUMMARIZE_BLOCK_REQUEST,
            content=consensus_pb2.ConsensusSummarizeBlockRequest(
            ).SerializeToString())

        self.assertEqual(result, b'summary')
Ejemplo n.º 2
0
    def summarize_block(self):
        request = consensus_pb2.ConsensusSummarizeBlockRequest()

        response_type = consensus_pb2.ConsensusSummarizeBlockResponse

        response = self._send(
            request=request,
            message_type=Message.CONSENSUS_SUMMARIZE_BLOCK_REQUEST,
            response_type=response_type)

        status = response.status

        if status == response_type.INVALID_STATE:
            raise exceptions.InvalidState(
                'Cannot summarize block in current state')

        if status == response_type.BLOCK_NOT_READY:
            raise exceptions.BlockNotReady('Block not ready to be summarize')

        if status != response_type.OK:
            raise exceptions.ReceiveError(
                'Failed with status {}'.format(status))

        return response.summary