Example #1
0
    def setUp(self):
        super().setUp()

        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        compute_task_def = message.ComputeTaskDef()
        compute_task_def['task_id'] = '8'
        compute_task_def['subtask_id'] = '8'
        compute_task_def['deadline'] = message_timestamp
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=compute_task_def,
            requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
            provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY),
            price=0,
        )
        task_to_compute = load(
            dump(
                task_to_compute,
                REQUESTOR_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            REQUESTOR_PUBLIC_KEY,
            check_time=False,
        )
        report_computed_task = tasks.ReportComputedTaskFactory(
            task_to_compute=task_to_compute)
        self.force_report_computed_task = message.ForceReportComputedTask(
            report_computed_task=report_computed_task)
    def setUp(self):

        (self.PROVIDER_PRIVATE_KEY,
         self.PROVIDER_PUBLIC_KEY) = generate_ecc_key_pair()
        (self.REQUESTOR_PRIVATE_KEY,
         self.REQUESTOR_PUBLIC_KEY) = generate_ecc_key_pair()

        self.report_computed_task = tasks.ReportComputedTaskFactory(
            sign__privkey=self.PROVIDER_PRIVATE_KEY,
            task_to_compute=tasks.TaskToComputeFactory(
                sign__privkey=self.REQUESTOR_PRIVATE_KEY, ))
        store_report_computed_task_as_subtask(self.report_computed_task)
Example #3
0
    def setUp(self):
        super().setUp()

        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = message_timestamp
        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), )
        want_to_compute_task = sign_message(want_to_compute_task,
                                            PROVIDER_PRIVATE_KEY)
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
            requestor_ethereum_public_key=encode_hex(
                REQUESTOR_ETHERUM_PUBLIC_KEY),
            want_to_compute_task=want_to_compute_task,
            price=1,
        )
        task_to_compute.generate_ethsig(REQUESTOR_ETHEREUM_PRIVATE_KEY)
        task_to_compute.sign_all_promissory_notes(
            deposit_contract_address=settings.GNT_DEPOSIT_CONTRACT_ADDRESS,
            private_key=REQUESTOR_ETHEREUM_PRIVATE_KEY,
        )
        self.task_to_compute = load(
            dump(
                task_to_compute,
                REQUESTOR_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            REQUESTOR_PUBLIC_KEY,
            check_time=False,
        )
        report_computed_task = tasks.ReportComputedTaskFactory(
            task_to_compute=self.task_to_compute)
        self.report_computed_task = load(
            dump(
                report_computed_task,
                PROVIDER_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            PROVIDER_PUBLIC_KEY,
            check_time=False,
        )
        self.force_report_computed_task = message.concents.ForceReportComputedTask(
            report_computed_task=self.report_computed_task)

        self.force_get_task_result = message.concents.ForceGetTaskResult(
            report_computed_task=self.report_computed_task)
Example #4
0
    def setUp(self):
        super().setUp()

        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        compute_task_def = message.ComputeTaskDef()
        compute_task_def['task_id'] = '8'
        compute_task_def['subtask_id'] = '8'
        compute_task_def['deadline'] = message_timestamp
        compute_task_def['extra_data'] = {
            'frames': [1],
            'output_format': 'PNG',
            'scene_file': 'kitten.blend',
        }
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=compute_task_def,
            requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
            provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY),
            price=0,
        )
        task_to_compute = load(
            dump(
                task_to_compute,
                REQUESTOR_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            REQUESTOR_PUBLIC_KEY,
            check_time=False,
        )
        report_computed_task = tasks.ReportComputedTaskFactory(
            task_to_compute=task_to_compute)
        report_computed_task = load(
            dump(
                report_computed_task,
                PROVIDER_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            PROVIDER_PUBLIC_KEY,
            check_time=False,
        )
        self.force_report_computed_task = message.ForceReportComputedTask(
            report_computed_task=report_computed_task)
Example #5
0
    def setUp(self):
        super().setUp()

        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = message_timestamp
        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), )
        want_to_compute_task = sign_message(want_to_compute_task,
                                            PROVIDER_PRIVATE_KEY)
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
            want_to_compute_task=want_to_compute_task,
            price=1,
        )
        self.task_to_compute = load(
            dump(
                task_to_compute,
                REQUESTOR_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            REQUESTOR_PUBLIC_KEY,
            check_time=False,
        )
        report_computed_task = tasks.ReportComputedTaskFactory(
            task_to_compute=self.task_to_compute)
        self.report_computed_task = load(
            dump(
                report_computed_task,
                PROVIDER_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            PROVIDER_PUBLIC_KEY,
            check_time=False,
        )
        self.force_report_computed_task = message.concents.ForceReportComputedTask(
            report_computed_task=self.report_computed_task)

        self.force_get_task_result = message.concents.ForceGetTaskResult(
            report_computed_task=self.report_computed_task)
Example #6
0
 def setUp(self):
     with freeze_time("2017-11-17 10:00:00"):
         super().setUp()
         self.compute_task_def = tasks.ComputeTaskDefFactory()
         self.compute_task_def['deadline'] = get_current_utc_timestamp() + (
             60 * 37)
         self.want_to_compute_task = tasks.WantToComputeTaskFactory(
             sign__privkey=self.PROVIDER_PRIVATE_KEY, )
         self.task_to_compute = tasks.TaskToComputeFactory(
             compute_task_def=self.compute_task_def,
             want_to_compute_task=self.want_to_compute_task,
             provider_public_key=self._get_provider_hex_public_key(),
             requestor_public_key=self._get_requestor_hex_public_key(),
             sign__privkey=self.REQUESTOR_PRIVATE_KEY,
         )
         self.size = 58
         self.report_computed_task = tasks.ReportComputedTaskFactory(
             task_to_compute=self.task_to_compute,
             size=self.size,
             sign__privkey=self.PROVIDER_PRIVATE_KEY,
         )
         self.force_golem_data = message.concents.ForceReportComputedTask(
             report_computed_task=self.report_computed_task, )
Example #7
0
    def test_that_incorrect_version_of_golem_messages_in_stored_message_should_raise_validation_error(self):

        with override_settings(GOLEM_MESSAGES_VERSION=self.second_communication_protocol_version):
            task_to_compute = tasks.TaskToComputeFactory()

            report_computed_task=tasks.ReportComputedTaskFactory(task_to_compute=task_to_compute)
            with self.assertRaises(ValidationError) as error:
                with mock.patch('core.message_handlers.store_message', side_effect=self.store_message_with_custom_protocol_version):
                    store_subtask(
                        task_id=task_to_compute.task_id,
                        subtask_id=task_to_compute.subtask_id,
                        task_to_compute=task_to_compute,
                        provider_public_key=hex_to_bytes_convert(task_to_compute.provider_public_key),
                        requestor_public_key=hex_to_bytes_convert(task_to_compute.requestor_public_key),
                        report_computed_task=report_computed_task,
                        state=Subtask.SubtaskState.REPORTED,
                        next_deadline=None,
                    )

        self.assertIn(
            f"Unsupported Golem Message version. Version in: `task_to_compute` is {self.first_communication_protocol_version}, "
            f"Version in Concent is {self.second_communication_protocol_version}",
            str(error.exception)
        )
Example #8
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = tasks.ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.want_to_compute_task = tasks.WantToComputeTaskFactory(
            sign__privkey=self.PROVIDER_PRIVATE_KEY, )
        self.task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            want_to_compute_task=self.want_to_compute_task,
            provider_public_key=self._get_provider_hex_public_key(),
            requestor_public_key=self._get_requestor_hex_public_key(),
            sign__privkey=self.REQUESTOR_PRIVATE_KEY,
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.report_computed_task = tasks.ReportComputedTaskFactory(
                task_to_compute=self.task_to_compute,
                size=self.size,
                sign__privkey=self.PROVIDER_PRIVATE_KEY,
            )
            self.force_golem_data = concents.ForceReportComputedTaskFactory(
                report_computed_task=self.report_computed_task,
                sign__privkey=self.REQUESTOR_PRIVATE_KEY,
            )
        message_timestamp = parse_timestamp_to_utc_datetime(
            get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.MAJOR_MINOR_GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.MAJOR_MINOR_GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.type_,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.MAJOR_MINOR_GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = tasks.AckReportComputedTaskFactory(
            report_computed_task=self.report_computed_task,
            sign__privkey=self.REQUESTOR_PRIVATE_KEY,
        )

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.MAJOR_MINOR_GOLEM_MESSAGES_VERSION,
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(public_key_bytes=self.PROVIDER_PUBLIC_KEY)
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            report_computed_task=new_message,
            task_to_compute=task_to_compute_message,
            want_to_compute_task=want_to_compute_message,
            ack_report_computed_task=stored_ack_report_computed_task,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider=client_provider,
            requestor=client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']),
            protocol_version=settings.MAJOR_MINOR_GOLEM_MESSAGES_VERSION,
        )
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.
            name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()