Example #1
0
 def setUp(self):
     self.task_to_compute_1 = TaskToComputeFactory(
         requestor_ethereum_public_key=encode_hex(REQUESTOR_PUB_ETH_KEY),
         requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
         want_to_compute_task=WantToComputeTaskFactory(
             provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), ),
     )
     self.task_to_compute_1.generate_ethsig(REQUESTOR_PRIV_ETH_KEY)
     self.task_to_compute_2 = TaskToComputeFactory(
         requestor_ethereum_public_key=encode_hex(REQUESTOR_PUB_ETH_KEY),
         requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
         want_to_compute_task=WantToComputeTaskFactory(
             provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), ),
     )
     self.task_to_compute_2.generate_ethsig(REQUESTOR_PRIV_ETH_KEY)
Example #2
0
 def setUp(self):
     with freeze_time("2017-11-17 10:00:00"):
         super().setUp()
         self.compute_task_def = ComputeTaskDefFactory()
         self.compute_task_def['deadline'] = get_current_utc_timestamp() + (60 * 37)
         self.want_to_compute_task = WantToComputeTaskFactory(
             node_name=1,
             task_id=self._get_uuid(),
             perf_index=3,
             price=4,
             max_resource_size=5,
             max_memory_size=6,
             num_cores=7,
         )
         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(),
         )
         self.size = 58
         self.report_computed_task = message.tasks.ReportComputedTask(
             task_to_compute=self.task_to_compute,
             size=self.size
         )
         self.force_golem_data = message.concents.ForceReportComputedTask(
             report_computed_task=self.report_computed_task,
         )
Example #3
0
    def setUp(self):
        super().setUp()
        self.stored_message_counter = 0
        self.message_timestamp = get_current_utc_timestamp()  # 1510912800
        self.compute_task_def = self._get_deserialized_compute_task_def(
            deadline=self.message_timestamp + settings.CONCENT_MESSAGING_TIME
        )
        self.task_to_compute = self._get_deserialized_task_to_compute(
            compute_task_def=self.compute_task_def,
        )
        self.report_computed_task = self._get_deserialized_report_computed_task(
            task_to_compute=self.task_to_compute
        )
        self.correct_golem_data = self._get_deserialized_force_report_computed_task(
            report_computed_task=self.report_computed_task
        )

        self.want_to_compute = WantToComputeTaskFactory(
            node_name=1,
            task_id=self._get_uuid(),
            perf_index=3,
            price=4,
            max_resource_size=5,
            max_memory_size=6,
            num_cores=7,
        )

        self.cannot_compute_task = message.CannotComputeTask(
            task_to_compute=self.task_to_compute
        )
        self.reject_report_computed_task = self._get_deserialized_reject_report_computed_task(
            task_to_compute=self.task_to_compute,
            reason=message.tasks.RejectReportComputedTask.REASON.SubtaskTimeLimitExceeded,
        )
Example #4
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 #5
0
    def setUp(self):
        self.provider_private_key, self.provider_public_key = generate_ecc_key_pair(
        )
        self.deposit_contract_address = '0xcfB81A6EE3ae6aD4Ac59ddD21fB4589055c13DaD'

        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(self.provider_public_key))
        arguments = {
            'subtask_results_rejected__'
            'report_computed_task__'
            'task_to_compute__'
            'want_to_compute_task':
            want_to_compute_task
        }
        self.subtask_results_verify: SubtaskResultsVerify = SubtaskResultsVerifyFactory(
            **arguments)
    def test_that_sci_backend_cover_additional_verification_cost_should_return_transaction_hash(self):
        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=self._get_provider_ethereum_hex_public_key()
        )
        subtask_results_verify: SubtaskResultsVerify = SubtaskResultsVerifyFactory(**{
            'subtask_results_rejected__'
            'report_computed_task__'
            'task_to_compute__'
            'want_to_compute_task': want_to_compute_task
        })
        subtask_results_verify.sign_concent_promissory_note(
            self.gnt_deposit,
            self.PROVIDER_PRIVATE_KEY,
        )
        v, r, s = subtask_results_verify.concent_promissory_note_sig
        with mock.patch(
            'core.payments.payment_interface.PaymentInterface.__new__',
            return_value=mock.Mock(
                cover_additional_verification_cost=mock.Mock(
                    return_value=MOCK_TRANSACTION_HASH
                ),
            ),
        ) as new_sci_rpc:
            transaction_hash = sci_backend.cover_additional_verification_cost(
                provider_eth_address=self.task_to_compute.provider_ethereum_address,
                value=self.task_to_compute.price,
                subtask_id=self.task_to_compute.subtask_id,
                v=v,
                r=r,
                s=s,
                reimburse_amount=self.transaction_value
            )

        self.assertEqual(transaction_hash, MOCK_TRANSACTION_HASH)

        new_sci_rpc.return_value.cover_additional_verification_cost.assert_called_with(
            address=Web3.toChecksumAddress(self.task_to_compute.provider_ethereum_address),
            value=self.task_to_compute.price,
            subtask_id=sci_backend._hexencode_uuid(self.task_to_compute.subtask_id),
            v=v,
            r=r,
            s=s,
            reimburse_amount=self.transaction_value,
        )
Example #7
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 #8
0
    def test_send_should_return_http_400_if_data_is_incorrect(self):
        compute_task_def = message.ComputeTaskDef()
        task_to_compute = message.TaskToCompute(
            compute_task_def=compute_task_def,
            requestor_public_key=self._get_encoded_requestor_public_key(),
            want_to_compute_task=WantToComputeTaskFactory(),
        )
        report_computed_task = message.tasks.ReportComputedTask(
            task_to_compute=task_to_compute
        )
        with freeze_time("2017-11-17 9:56:00"):
            force_report_computed_task = message.concents.ForceReportComputedTask(
                report_computed_task=report_computed_task
            )

        response = self.send_request(
            url='core:send',
            data=dump(
                force_report_computed_task,
                self.PROVIDER_PRIVATE_KEY,
                CONCENT_PUBLIC_KEY),
        )
        self._test_400_response(response)

        data = message.concents.ForceReportComputedTask()
        data.report_computed_task = message.tasks.ReportComputedTask()
        compute_task_def['deadline'] = self.message_timestamp - 3600
        data.report_computed_task.task_to_compute = message.TaskToCompute(compute_task_def=compute_task_def)

        response = self.send_request(
            url='core:send',
            data=dump(
                data,
                self.PROVIDER_PRIVATE_KEY,
                CONCENT_PUBLIC_KEY),
        )
        self._test_400_response(response)
        self.assertIn('Error in Golem Message', response.json()['error'])
Example #9
0
    def setUp(self):
        self.request_factory = RequestFactory()
        self.want_to_compute = WantToComputeTaskFactory()
        self.message_to_view = {
            "task_id": self.want_to_compute.task_id,  # pylint: disable=no-member
            "perf_index": self.want_to_compute.perf_index,  # pylint: disable=no-member
            "price": self.want_to_compute.price,  # pylint: disable=no-member
            "max_resource_size": self.want_to_compute.max_resource_size,  # pylint: disable=no-member
            "max_memory_size": self.want_to_compute.max_memory_size,  # pylint: disable=no-member
        }
        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        compute_task_def = tasks.ComputeTaskDefFactory(
            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,
        )

        self.force_report_computed_task = message.concents.ForceReportComputedTask(
        )
        self.force_report_computed_task.report_computed_task = message.tasks.ReportComputedTask(
        )
        self.force_report_computed_task.report_computed_task.task_to_compute = task_to_compute
Example #10
0
def create_signed_task_to_compute(
    deadline: int,
    timestamp: Optional[Union[datetime.datetime, str]] = None,
    provider_public_key: Optional[bytes] = None,
    provider_private_key: Optional[bytes] = None,
    requestor_public_key: Optional[bytes] = None,
    requestor_private_key: Optional[bytes] = None,
    price: int = 1,
    size: int = 1,
    package_hash: str = 'sha1:57786d92d1a6f7eaaba1c984db5e108c68b03f0d',
    render_parameters: Optional[Dict[str, Any]] = None,
) -> TaskToCompute:
    # Temporary workaround for requestor's and provider's keys until all Concent use cases will have payments
    # When we will have payments then all keys will be taken from SCIBaseTest class
    if provider_public_key is None and provider_private_key is None:
        provider_public_key = PROVIDER_PUBLIC_KEY
        provider_private_key = PROVIDER_PRIVATE_KEY
    if requestor_public_key is None and requestor_private_key is None:
        requestor_public_key = REQUESTOR_PUBLIC_KEY
        requestor_private_key = REQUESTOR_PRIVATE_KEY

    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            deadline=deadline,
            extra_data={
                'output_format':
                'png',
                'scene_file':
                '/golem/resources/golem-header-light.blend',
                'frames': [1],
                'resolution':
                render_parameters.get('resolution')
                if render_parameters is not None else [400, 400],
                'use_compositing':
                render_parameters.get('use_compositing')
                if render_parameters is not None else False,
                'samples':
                render_parameters.get('samples')
                if render_parameters is not None else 0,
                'crops': [{
                    'borders_x':
                    render_parameters['borders_x']
                    if render_parameters is not None else [0.0, 1.0],
                    'borders_y':
                    render_parameters['borders_y']
                    if render_parameters is not None else [0.0, 1.0],
                }]
            })

        task_header: TaskHeader = TaskHeaderFactory(
            task_id=compute_task_def['task_id'],
            sign__privkey=requestor_private_key,
        )

        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(provider_public_key),
            task_header=task_header,
            sign__privkey=provider_private_key)

        task_to_compute = TaskToComputeFactory(
            requestor_public_key=encode_hex(requestor_public_key),
            compute_task_def=compute_task_def,
            want_to_compute_task=want_to_compute_task,
            requestor_ethereum_public_key=encode_hex(requestor_public_key),
            price=price,
            size=size,
            package_hash=package_hash,
        )
        task_to_compute.generate_ethsig(requestor_private_key)
        task_to_compute.sign_all_promissory_notes(
            deposit_contract_address=settings.GNT_DEPOSIT_CONTRACT_ADDRESS,
            private_key=requestor_private_key,
        )
        signed_task_to_compute: TaskToCompute = sign_message(
            task_to_compute, requestor_private_key)  # type: ignore
        return signed_task_to_compute
Example #11
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.want_to_compute_task = WantToComputeTaskFactory(
            node_name=1,
            task_id=self._get_uuid(),
            perf_index=3,
            price=4,
            max_resource_size=5,
            max_memory_size=6,
            num_cores=7,
        )
        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(),
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.report_computed_task = message.tasks.ReportComputedTask(
                task_to_compute=self.task_to_compute,
                size=self.size
            )
            self.force_golem_data = message.concents.ForceReportComputedTask(
                report_computed_task=self.report_computed_task
            )
        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.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.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.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=self.report_computed_task
        )

        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.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'])
        )
        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()
def create_signed_task_to_compute(
    deadline: int,
    timestamp: Optional[Union[datetime.datetime, str]] = None,
    provider_public_key: Optional[bytes] = None,
    requestor_public_key: Optional[bytes] = None,
    requestor_ethereum_public_key: Optional[bytes] = None,
    requestor_ethereum_private_key: Optional[bytes] = None,
    provider_ethereum_public_key: Optional[bytes] = None,
    want_to_compute_task: Optional[WantToComputeTask] = None,
    price: int = 1,
    size: int = 1,
    package_hash: str = 'sha1:57786d92d1a6f7eaaba1c984db5e108c68b03f0d',
    script_src: Optional[str] = None,
) -> TaskToCompute:
    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            deadline=deadline,
            extra_data={
                'output_format': 'png',
                'scene_file': '/golem/resources/golem-header-light.blend',
                'frames': [1],
                'script_src': script_src,
            })
        if script_src is not None:
            compute_task_def['extra_data']['script_src'] = script_src
        want_to_compute_task = want_to_compute_task if want_to_compute_task is not None else WantToComputeTaskFactory(
            provider_public_key=encode_hex(provider_public_key)
            if provider_public_key is not None else
            _get_provider_hex_public_key(),
            provider_ethereum_public_key=encode_hex(
                provider_ethereum_public_key) if provider_ethereum_public_key
            is not None else encode_hex(PROVIDER_ETHEREUM_PUBLIC_KEY),
        )
        want_to_compute_task = sign_message(want_to_compute_task,
                                            PROVIDER_PRIVATE_KEY)
        task_to_compute = TaskToComputeFactory(
            requestor_public_key=encode_hex(requestor_public_key)
            if requestor_public_key is not None else
            _get_requestor_hex_public_key(),
            compute_task_def=compute_task_def,
            want_to_compute_task=want_to_compute_task,
            requestor_ethereum_public_key=encode_hex(
                requestor_ethereum_public_key) if requestor_ethereum_public_key
            is not None else encode_hex(REQUESTOR_ETHEREUM_PUBLIC_KEY),
            price=price,
            size=size,
            package_hash=package_hash,
        )
        task_to_compute.generate_ethsig(
            requestor_ethereum_private_key if requestor_ethereum_private_key
            is not None else REQUESTOR_ETHEREUM_PRIVATE_KEY)
        signed_task_to_compute: TaskToCompute = sign_message(
            task_to_compute, REQUESTOR_PRIVATE_KEY)
        return signed_task_to_compute