예제 #1
0
    def send_to(self, receiver_id, message_type, payload):
        request = consensus_pb2.ConsensusSendToRequest(
            message_type=message_type,
            content=payload,
            receiver_id=receiver_id)

        response = self._send(
            request=request,
            message_type=Message.CONSENSUS_SEND_TO_REQUEST,
            response_type=consensus_pb2.ConsensusSendToResponse)

        if response.status != consensus_pb2.ConsensusSendToResponse.OK:
            raise exceptions.ReceiveError('Failed with status {}'.format(
                response.status))
예제 #2
0
    def test_send_to(self):
        self.mock_stream.send.return_value = self._make_future(
            message_type=Message.CONSENSUS_SEND_TO_RESPONSE,
            content=consensus_pb2.ConsensusSendToResponse(
                status=consensus_pb2.ConsensusSendToResponse.OK).
            SerializeToString())

        self.service.send_to(peer_id=b'peer_id',
                             message_type='message_type',
                             payload=b'payload')

        self.mock_stream.send.assert_called_with(
            message_type=Message.CONSENSUS_SEND_TO_REQUEST,
            content=consensus_pb2.ConsensusSendToRequest(
                message=consensus_pb2.ConsensusPeerMessage(
                    message_type='message_type', content=b'payload'),
                peer_id=b'peer_id').SerializeToString())