Пример #1
0
    def test_commit_block(self):
        self.mock_stream.send.return_value = self._make_future(
            message_type=Message.CONSENSUS_COMMIT_BLOCK_RESPONSE,
            content=consensus_pb2.ConsensusCommitBlockResponse(
                status=consensus_pb2.ConsensusCommitBlockResponse.OK))

        self.service.commit_block(block_id=b'test')

        self.mock_stream.send.assert_called_with(
            message_type=Message.CONSENSUS_COMMIT_BLOCK_REQUEST,
            content=consensus_pb2.ConsensusCommitBlockRequest(
                block_id=b'test').SerializeToString())
Пример #2
0
    def commit_block(self, block_id):
        request = consensus_pb2.ConsensusCommitBlockRequest(block_id=block_id)

        response_type = consensus_pb2.ConsensusCommitBlockResponse

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

        status = response.status

        if status == response_type.UNKNOWN_BLOCK:
            raise exceptions.UnknownBlock()

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