예제 #1
0
def test_case_1_provider_forces_report_computed_task_and_gets_accepted(cluster_consts, cluster_url, test_id):
    current_time = get_current_utc_timestamp()
    (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '1')
    task_to_compute = create_signed_task_to_compute(
        task_id=task_id,
        subtask_id=subtask_id,
        deadline=current_time + 1
    )
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_report_computed_task(
            task_to_compute=task_to_compute
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=ForceReportComputedTask.TYPE,
        expected_content_type='application/octet-stream',
    )
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        ack_report_computed_task(
            task_to_compute=task_to_compute
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=ForceReportComputedTaskResponse.TYPE,
        expected_content_type='application/octet-stream',
    )
예제 #2
0
def test_case_2_test_for_non_existing_file(cluster_consts, cluster_url,
                                           test_id):
    current_time = get_current_utc_timestamp()
    (subtask_id, task_id) = get_task_id_and_subtask_id(test_id,
                                                       'non_existing_file')

    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_force_get_task_result(
            task_id,
            subtask_id,
            current_time,
            cluster_consts,
            size=1024,
            package_hash='sha1:b3ff7013c4644cdcbb6c7e4f1e5fdb10b9ceda5d'),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.AckForceGetTaskResult.TYPE,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForceGetTaskResultUpload.TYPE,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=204,
    )
예제 #3
0
def test_case_1_provider_forces_report_computed_task_and_gets_accepted(
    cluster_consts: ProtocolConstants,
    cluster_url: str,
) -> None:
    current_time = get_current_utc_timestamp()
    task_to_compute = create_signed_task_to_compute(deadline=current_time + 1)
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_report_computed_task(task_to_compute=task_to_compute),
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=ForceReportComputedTask,
        expected_content_type='application/octet-stream',
    )
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        ack_report_computed_task(task_to_compute=task_to_compute),
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=ForceReportComputedTaskResponse,
        expected_content_type='application/octet-stream',
    )
예제 #4
0
def test_case_2d_send_correct_force_payment(cluster_consts, cluster_url,
                                            test_id):
    # Test CASE 2D - Send correct ForcePayment
    current_time = get_current_utc_timestamp()
    (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2D')
    correct_force_payment = force_payment(subtask_results_accepted_list=[
        subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            task_to_compute=create_signed_task_to_compute(
                timestamp=parse_timestamp_to_utc_datetime(current_time),
                task_id=task_id + 'a',
                subtask_id=subtask_id + 'A',
                deadline=current_time,
                price=1000,
            )),
        subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            task_to_compute=create_signed_task_to_compute(
                timestamp=parse_timestamp_to_utc_datetime(current_time),
                task_id=task_id + 'b',
                subtask_id=subtask_id + 'B',
                deadline=current_time,
                price=1000,
            ))
    ])
    correct_force_payment.sig = None
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        correct_force_payment,
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted.TYPE,
        expected_content_type='application/octet-stream',
    )
    time.sleep(5)
    api_request(
        cluster_url,
        'receive-out-of-band',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted.TYPE,
        expected_content_type='application/octet-stream',
    )
def test_case_2a_send_duplicated_force_subtask_results(
        cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    #  Test CASE 2A + 2D + 3 - Send ForceSubtaskResults with same task_id as stored by Concent before
    #  Step 1. Send ForceSubtaskResults first time
    current_time = get_current_utc_timestamp()
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.minimum_upload_rate),
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.minimum_upload_rate),
        price=1000,
    )
    force_subtask_results = create_force_subtask_results(
        timestamp=timestamp_to_isoformat(current_time),
        ack_report_computed_task=create_ack_report_computed_task(
            timestamp=timestamp_to_isoformat(current_time),
            report_computed_task=create_report_computed_task(
                task_to_compute=signed_task_to_compute)))
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_subtask_results,
        expected_status=202,
    )
    time.sleep(1)
    #  Step 2. Send ForceSubtaskResults second time with same task_id
    # Signature must be set to None, because msg will be signed again in api_request()
    force_subtask_results.sig = None
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_subtask_results,
        expected_status=200,
        expected_message_type=message.concents.ServiceRefused,
        expected_content_type='application/octet-stream',
    )
    #  Step 3. Requestor wants to receive ForceSubtaskResults from Concent
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults,
        expected_content_type='application/octet-stream',
    )
예제 #6
0
def test_case_2_test_for_non_existing_file(cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    current_time    = get_current_utc_timestamp()

    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_force_get_task_result(
            current_time,
            size    = 1024,
            package_hash = 'sha1:b3ff7013c4644cdcbb6c7e4f1e5fdb10b9ceda5d'
        ),
        expected_status=200,
        expected_message_type=message.concents.AckForceGetTaskResult,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceGetTaskResultUpload,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        expected_status=204,
    )
예제 #7
0
def test_case_2d_send_correct_force_payment(cluster_consts: ProtocolConstants,
                                            cluster_url: str) -> None:
    # Test CASE 2D - Send correct ForcePayment
    current_time = get_current_utc_timestamp()
    correct_force_payment = force_payment(subtask_results_accepted_list=[
        create_signed_subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=create_signed_task_to_compute(
                    timestamp=parse_timestamp_to_utc_datetime(current_time),
                    deadline=current_time,
                    price=1000,
                ))),
        create_signed_subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=create_signed_task_to_compute(
                    timestamp=parse_timestamp_to_utc_datetime(current_time),
                    deadline=current_time,
                    price=1000,
                )))
    ])
    correct_force_payment.sig = None
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        correct_force_payment,
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted,
        expected_content_type='application/octet-stream',
    )
    time.sleep(5)
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted,
        expected_content_type='application/octet-stream',
    )
예제 #8
0
def upload_file_to_storage_cluster(file_content, file_path, upload_token):
    dumped_upload_token = shortcuts.dump(upload_token, None,
                                         CONCENT_PUBLIC_KEY)
    b64_encoded_token = b64encode(dumped_upload_token).decode()
    headers = {
        'Authorization':
        'Golem ' + b64_encoded_token,
        'Concent-Auth':
        b64encode(
            create_client_auth_message(PROVIDER_PRIVATE_KEY,
                                       PROVIDER_PUBLIC_KEY,
                                       CONCENT_PUBLIC_KEY)).decode(),
        'Concent-upload-path':
        file_path,
        'Content-Type':
        'application/octet-stream'
    }
    return requests.post("{}upload/".format(STORAGE_CLUSTER_ADDRESS),
                         headers=headers,
                         data=file_content,
                         verify=False)
def test_case_1_test_for_positive_case(cluster_consts: ProtocolConstants, cluster_url: str) -> None:  # pylint: disable=unused-argument
    receive_pending_messages_for_requestor_and_provider(
        cluster_url,
        sci_base,
        CONCENT_PUBLIC_KEY
    )
    current_time = get_current_utc_timestamp()
    provider_deposit_value = sci_base.get_provider_gntb_balance()
    requestor_deposit_value = sci_base.get_requestor_deposit_value()

    current_dir = os.path.dirname(os.path.abspath(__file__))
    with open(os.path.join(current_dir, 'tests_resources', 'source.zip'), 'rb') as archive:
        source_file_content = archive.read()
    with open(os.path.join(current_dir, 'tests_resources', 'result.zip'), 'rb') as archive:
        result_file_content = archive.read()

    result_file_size = len(result_file_content)
    source_file_size = len(source_file_content)
    result_file_checksum = 'sha1:' + hashlib.sha1(result_file_content).hexdigest()
    source_file_checksum = 'sha1:' + hashlib.sha1(source_file_content).hexdigest()

    subtask_results_verify = get_subtask_results_verify(
        current_time,
        reason=message.tasks.SubtaskResultsRejected.REASON.VerificationNegative,
        report_computed_task_size=result_file_size,
        report_computed_task_package_hash=result_file_checksum,
        task_to_compute_size=source_file_size,
        task_to_compute_package_hash=source_file_checksum,
        price=10000,
        render_parameters=get_render_params()
    )

    ack_subtask_results_verify = api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        subtask_results_verify,
        expected_status=200,
        expected_message_type=message.concents.AckSubtaskResultsVerify,
        expected_content_type='application/octet-stream',
    )

    response = upload_file_to_storage_cluster(
        result_file_content,
        ack_subtask_results_verify.file_transfer_token.files[0]['path'],  # type: ignore
        ack_subtask_results_verify.file_transfer_token,  # type: ignore
        sci_base.provider_private_key,
        sci_base.provider_public_key,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )
    assert_condition(response.status_code, 200, 'File has not been stored on cluster')
    print('\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'.format(
        subtask_results_verify.task_id,
        result_file_checksum,
        result_file_size
    ))

    response = upload_file_to_storage_cluster(
        source_file_content,
        ack_subtask_results_verify.file_transfer_token.files[1]['path'],  # type: ignore
        ack_subtask_results_verify.file_transfer_token,  # type: ignore
        sci_base.provider_private_key,
        sci_base.provider_public_key,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )
    assert_condition(response.status_code, 200, 'File has not been stored on cluster')
    print('\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'.format(
        subtask_results_verify.task_id,
        source_file_checksum,
        source_file_size
    ))

    # Adding calculated number of seconds to time sleep makes us sure that subtask is after deadline.
    sleep_time = calculate_verification_deadline(
        subtask_results_verify.subtask_results_rejected.timestamp,
        cluster_consts.additional_verification_call_time,
        subtask_results_verify.subtask_results_rejected.report_computed_task.size,
        cluster_consts.minimum_upload_rate,
    ) - current_time
    print(f"Going to sleep for {sleep_time} secs...")
    time.sleep(
        sleep_time
    )

    api_request(
        cluster_url,
        'receive',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.requestor_private_key, sci_base.requestor_public_key, CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.SubtaskResultsSettled,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.provider_private_key, sci_base.provider_public_key, CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.SubtaskResultsSettled,
        expected_content_type='application/octet-stream',
    )
    sci_base.ensure_that_provider_has_specific_gntb_balance(value=provider_deposit_value + 10000)
    sci_base.ensure_that_requestor_has_specific_deposit_balance(value=requestor_deposit_value - 10000)
def test_case_2a_send_duplicated_force_subtask_results(cluster_consts,
                                                       cluster_url, test_id):
    #  Test CASE 2A + 2D + 3 - Send ForceSubtaskResults with same task_id as stored by Concent before
    #  Step 1. Send ForceSubtaskResults first time
    current_time = get_current_utc_timestamp()
    (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2A')
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.concent_upload_rate),
        task_id=task_id,
        subtask_id=subtask_id,
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.concent_upload_rate),
        price=10000,
    )
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_subtask_results(
            timestamp=timestamp_to_isoformat(current_time),
            ack_report_computed_task=ack_report_computed_task(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=report_computed_task(
                    task_to_compute=signed_task_to_compute))),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    time.sleep(1)
    #  Step 2. Send ForceSubtaskResults second time with same task_id
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_subtask_results(
            timestamp=timestamp_to_isoformat(current_time),
            ack_report_computed_task=ack_report_computed_task(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=report_computed_task(
                    task_to_compute=signed_task_to_compute))),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ServiceRefused.TYPE,
        expected_content_type='application/octet-stream',
    )
    #  Step 3. Requestor wants to receive ForceSubtaskResults from Concent
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults.TYPE,
        expected_content_type='application/octet-stream',
    )
def test_case_2d_requestor_rejects_subtask_results(cluster_consts, cluster_url,
                                                   test_id):
    # Test CASE 2D + 3 + 4B + 5. Requestor sends ForceSubtaskResultsResponse with SubtaskResultsRejected
    current_time = get_current_utc_timestamp()
    (subtask_id, task_id) = get_task_id_and_subtask_id(test_id, '2D')
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.concent_upload_rate),
        task_id=task_id,
        subtask_id=subtask_id,
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.concent_upload_rate),
        price=10000,
    )
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_subtask_results(
            timestamp=timestamp_to_isoformat(current_time),
            ack_report_computed_task=ack_report_computed_task(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=report_computed_task(
                    task_to_compute=signed_task_to_compute, ))),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults.TYPE,
        expected_content_type='application/octet-stream',
    )
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_subtask_results_response(
            timestamp=timestamp_to_isoformat(current_time),
            subtask_results_rejected=subtask_results_rejected(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=report_computed_task(
                    timestamp=timestamp_to_isoformat(current_time),
                    task_to_compute=signed_task_to_compute,
                ))),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResultsResponse.
        TYPE,
        expected_content_type='application/octet-stream',
    )
def test_case_1_test_for_positive_case(cluster_consts, cluster_url, test_id):  # pylint: disable=unused-argument
    current_time = get_current_utc_timestamp()
    (subtask_id, task_id) = get_task_id_and_subtask_id(test_id,
                                                       'existing_file')

    current_dir = os.path.dirname(os.path.abspath(__file__))
    with open(os.path.join(current_dir, 'tests_resources', 'source.zip'),
              'rb') as archive:
        source_file_content = archive.read()
    with open(os.path.join(current_dir, 'tests_resources', 'result.zip'),
              'rb') as archive:
        result_file_content = archive.read()

    result_file_size = len(result_file_content)
    source_file_size = len(source_file_content)
    result_file_checksum = 'sha1:' + hashlib.sha1(
        result_file_content).hexdigest()
    source_file_checksum = 'sha1:' + hashlib.sha1(
        source_file_content).hexdigest()

    ack_subtask_results_verify = api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_subtask_results_verify(
            task_id,
            subtask_id,
            current_time,
            reason=message.tasks.SubtaskResultsRejected.REASON.
            VerificationNegative,
            report_computed_task_size=result_file_size,
            report_computed_task_package_hash=result_file_checksum,
            task_to_compute_size=source_file_size,
            task_to_compute_package_hash=source_file_checksum,
            script_src=
            '# This template is rendered by\n# apps.blender.resources.scenefileeditor.generate_blender_crop_file(),\n# written to tempfile and passed as arg to blender.\nimport bpy\n\nclass EngineWarning(bpy.types.Operator):\n    bl_idname = "wm.engine_warning"\n    bl_label = "Inform about not supported rendering engine"\n\n    def execute(self, context):\n        self.report({"ERROR"}, "Engine " + bpy.context.scene.render.engine + \\\n                               " not supported by Golem")\n        return {"FINISHED"}\n\nclass ShowInformation(bpy.types.Operator):\n    bl_idname = "wm.scene_information"\n    bl_label = "Inform user about scene settings"\n\n\n    def execute(self, context):\n        self.report({"INFO"}, "Resolution: " +\n                              str(bpy.context.scene.render.resolution_x) +\n                               " x " +\n                               str(bpy.context.scene.render.resolution_y))\n        self.report({"INFO"}, "File format: " +\n                               str(bpy.context.scene.render.file_extension))\n        self.report({"INFO"}, "Filepath: " +\n                              str(bpy.context.scene.render.filepath))\n        self.report({"INFO"}, "Frames: " +\n                              str(bpy.context.scene.frame_start) + "-" +\n                              str(bpy.context.scene.frame_end) + ";" +\n                              str(bpy.context.scene.frame_step))\n\n        return {"FINISHED"}\n\n\nbpy.utils.register_class(EngineWarning)\nengine = bpy.context.scene.render.engine\nif engine not in ("BLENDER_RENDER", "CYCLES"):\n    bpy.ops.wm.engine_warning()\n\nbpy.utils.register_class(ShowInformation)\nbpy.ops.wm.scene_information()\n\n\nfor scene in bpy.data.scenes:\n\n    scene.render.tile_x = 0\n    scene.render.tile_y = 0\n    scene.render.resolution_x = 1024\n    scene.render.resolution_y = 768\n    scene.render.resolution_percentage = 100\n    scene.render.use_border = True\n    scene.render.use_crop_to_border = True\n    scene.render.border_max_x = 1.0\n    scene.render.border_min_x = 0.0\n    scene.render.border_min_y = 0.0\n    scene.render.border_max_y = 1.0\n    scene.render.use_compositing = bool(False)\n\n#and check if additional files aren\'t missing\nbpy.ops.file.report_missing_files()\n',
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.AckSubtaskResultsVerify.TYPE,
        expected_content_type='application/octet-stream',
    )

    response = upload_file_to_storage_cluster(
        result_file_content,
        ack_subtask_results_verify.file_transfer_token.files[0]['path'],
        ack_subtask_results_verify.file_transfer_token,
        PROVIDER_PRIVATE_KEY,
        PROVIDER_PUBLIC_KEY,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )
    assert_condition(response.status_code, 200,
                     'File has not been stored on cluster')
    print(
        '\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'
        .format(task_id, result_file_checksum, result_file_size))

    response = upload_file_to_storage_cluster(
        source_file_content,
        ack_subtask_results_verify.file_transfer_token.files[1]['path'],
        ack_subtask_results_verify.file_transfer_token,
        PROVIDER_PRIVATE_KEY,
        PROVIDER_PUBLIC_KEY,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )
    assert_condition(response.status_code, 200,
                     'File has not been stored on cluster')
    print(
        '\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'
        .format(task_id, source_file_checksum, source_file_size))

    # Adding 10 seconds to time sleep makes us sure that subtask is after deadline.
    time.sleep(CALCULATED_VERIFICATION_TIME *
               (ADDITIONAL_VERIFICATION_TIME_MULTIPLIER / BLENDER_THREADS))

    api_request(
        cluster_url,
        'receive-out-of-band',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.SubtaskResultsSettled.TYPE,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive-out-of-band',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.SubtaskResultsSettled.TYPE,
        expected_content_type='application/octet-stream',
    )
def test_case_4b_requestor_accepts_subtaks_results(
        cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    # Test CASE 4B + 5. Requestor sends ForceSubtaskResultsResponse with SubtaskResultsAccepted
    #  Step 1. Provider sends ForceSubtaskResults
    current_time = get_current_utc_timestamp()
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.minimum_upload_rate),
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.minimum_upload_rate),
        price=1000,
    )
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results(
            timestamp=timestamp_to_isoformat(current_time),
            ack_report_computed_task=create_ack_report_computed_task(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=create_report_computed_task(
                    task_to_compute=signed_task_to_compute))),
        expected_status=202,
    )
    time.sleep(1)
    #  Step 2. Requestor receives ForceSubtaskResults
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults,
        expected_content_type='application/octet-stream',
    )
    #  Step 3. Requestor sends ForceSubtaskResultsResponse
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results_response(
            timestamp=timestamp_to_isoformat(current_time),
            subtask_results_accepted=create_subtask_results_accepted(
                timestamp=timestamp_to_isoformat(current_time),
                payment_ts=timestamp_to_isoformat(current_time + 1),
                task_to_compute=signed_task_to_compute)),
        expected_status=202,
    )
    #  Step 4. Provider receives ForceSubtaskResultsResponse
    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResultsResponse,
        expected_content_type='application/octet-stream',
    )
예제 #14
0
def test_case_2d_send_correct_force_payment(cluster_consts: ProtocolConstants,
                                            cluster_url: str) -> None:
    # Test CASE 2D - Send correct ForcePayment
    receive_pending_messages_for_requestor_and_provider(
        cluster_url, sci_base, CONCENT_PUBLIC_KEY)
    provider_gntb_balance = sci_base.get_provider_gntb_balance()
    current_time = get_current_utc_timestamp()
    correct_force_payment = force_payment(subtask_results_accepted_list=[
        create_signed_subtask_results_accepted(
            timestamp=timestamp_to_isoformat(current_time -
                                             cluster_consts.payment_due_time +
                                             AVERAGE_TIME_FOR_TWO_BLOCKS),
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=create_signed_task_to_compute(
                    timestamp=parse_timestamp_to_utc_datetime(current_time),
                    deadline=current_time,
                    price=1000,
                    provider_public_key=sci_base.provider_public_key,
                    provider_private_key=sci_base.provider_private_key,
                    requestor_public_key=sci_base.requestor_public_key,
                    requestor_private_key=sci_base.requestor_private_key,
                ),
                provider_private_key=sci_base.provider_private_key),
            requestor_private_key=sci_base.requestor_private_key,
        ),
        create_signed_subtask_results_accepted(
            timestamp=timestamp_to_isoformat(current_time -
                                             cluster_consts.payment_due_time +
                                             AVERAGE_TIME_FOR_TWO_BLOCKS),
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=create_signed_task_to_compute(
                    timestamp=parse_timestamp_to_utc_datetime(current_time),
                    deadline=current_time,
                    price=1000,
                    provider_public_key=sci_base.provider_public_key,
                    provider_private_key=sci_base.provider_private_key,
                    requestor_public_key=sci_base.requestor_public_key,
                    requestor_private_key=sci_base.requestor_private_key,
                ),
                provider_private_key=sci_base.provider_private_key),
            requestor_private_key=sci_base.requestor_private_key,
        ),
    ])
    correct_force_payment.sig = None
    requestor_deposit_value = sci_base.get_requestor_deposit_value()
    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        correct_force_payment,
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted,
        expected_content_type='application/octet-stream',
    )
    time.sleep(5)
    api_request(
        cluster_url,
        'receive',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.requestor_private_key,
                                   sci_base.requestor_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted,
        expected_content_type='application/octet-stream',
    )
    sci_base.ensure_that_provider_has_specific_gntb_balance(
        value=provider_gntb_balance + 2000)
    sci_base.ensure_that_requestor_has_specific_deposit_balance(
        value=requestor_deposit_value - 2000)
예제 #15
0
def test_case_1_test_for_existing_file(cluster_consts, cluster_url, test_id):
    current_time = get_current_utc_timestamp()
    (subtask_id, task_id) = get_task_id_and_subtask_id(test_id,
                                                       'existing_file')

    file_content = task_id
    file_size = len(file_content)
    file_check_sum = 'sha1:' + hashlib.sha1(file_content.encode()).hexdigest()
    file_path = get_storage_result_file_path(
        task_id=task_id,
        subtask_id=subtask_id,
    )

    # Case 1 - test for existing file
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_force_get_task_result(
            task_id,
            subtask_id,
            current_time,
            cluster_consts,
            size=file_size,
            package_hash=file_check_sum,
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.AckForceGetTaskResult.TYPE,
        expected_content_type='application/octet-stream',
    )

    force_get_task_result_upload = api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForceGetTaskResultUpload.TYPE,
        expected_content_type='application/octet-stream',
    )

    response = upload_file_to_storage_cluster(
        file_content, file_path,
        force_get_task_result_upload.file_transfer_token)

    assert_condition(response.status_code, 200,
                     'File has not been stored on cluster')
    print(
        '\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'
        .format(task_id, file_check_sum, file_size))

    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForceGetTaskResultDownload.TYPE,
        expected_content_type='application/octet-stream',
    )
예제 #16
0
 def receive(self, cluster_url, party, endpoint):
     print_message(None, cluster_url, endpoint)
     priv_key, pub_key = self.select_keys(party)
     auth_data = create_client_auth_message(priv_key, pub_key, self.concent_pub_key)
     self._exchange_message(priv_key, cluster_url, auth_data)
예제 #17
0
def test_case_4b_requestor_accepts_subtaks_results(
        cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    # Test CASE 4B + 5. Requestor sends ForceSubtaskResultsResponse with SubtaskResultsAccepted
    #  Step 1. Provider sends ForceSubtaskResults
    receive_pending_messages_for_requestor_and_provider(
        cluster_url, sci_base, CONCENT_PUBLIC_KEY)
    current_time = get_current_utc_timestamp()
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.minimum_upload_rate),
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.minimum_upload_rate),
        price=1000,
        provider_public_key=sci_base.provider_public_key,
        provider_private_key=sci_base.provider_private_key,
        requestor_public_key=sci_base.requestor_public_key,
        requestor_private_key=sci_base.requestor_private_key)
    signed_report_computed_task = create_signed_report_computed_task(
        task_to_compute=signed_task_to_compute,
        provider_private_key=sci_base.provider_private_key,
    )
    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results(
            timestamp=timestamp_to_isoformat(current_time),
            ack_report_computed_task=create_ack_report_computed_task(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=signed_report_computed_task,
                requestor_private_key=sci_base.requestor_private_key)),
        expected_status=202,
    )
    time.sleep(1)
    #  Step 2. Requestor receives ForceSubtaskResults
    api_request(
        cluster_url,
        'receive',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.requestor_private_key,
                                   sci_base.requestor_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults,
        expected_content_type='application/octet-stream',
    )
    #  Step 3. Requestor sends ForceSubtaskResultsResponse
    api_request(
        cluster_url,
        'send',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results_response(
            timestamp=timestamp_to_isoformat(current_time),
            subtask_results_accepted=create_signed_subtask_results_accepted(
                payment_ts=current_time + 1,
                report_computed_task=signed_report_computed_task,
                requestor_private_key=sci_base.requestor_private_key,
            )),
        expected_status=202,
    )
    #  Step 4. Provider receives ForceSubtaskResultsResponse
    api_request(
        cluster_url,
        'receive',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.provider_private_key,
                                   sci_base.provider_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResultsResponse,
        expected_content_type='application/octet-stream',
    )
예제 #18
0
def test_case_1_test_for_existing_file(cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    current_time = get_current_utc_timestamp()

    file_content = 'test'
    file_size = len(file_content)
    file_check_sum = 'sha1:' + hashlib.sha1(file_content.encode()).hexdigest()

    force_get_task_result = get_force_get_task_result(
        current_time,
        size=file_size,
        package_hash=file_check_sum,
    )

    file_path = get_storage_result_file_path(
        task_id=force_get_task_result.task_id,
        subtask_id=force_get_task_result.subtask_id,
    )

    # Case 1 - test for existing file
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_get_task_result,
        expected_status=200,
        expected_message_type=message.concents.AckForceGetTaskResult,
        expected_content_type='application/octet-stream',
    )

    force_get_task_result_upload = api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceGetTaskResultUpload,
        expected_content_type='application/octet-stream',
    )

    response = upload_file_to_storage_cluster(
        file_content,
        file_path,
        force_get_task_result_upload.file_transfer_token,  # type: ignore
        PROVIDER_PRIVATE_KEY,
        PROVIDER_PUBLIC_KEY,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )

    assert_condition(response.status_code, 200, 'File has not been stored on cluster')
    print('\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'.format(
        force_get_task_result.task_id,
        file_check_sum,
        file_size
    ))
    time.sleep(0.5)

    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceGetTaskResultDownload,
        expected_content_type='application/octet-stream',
    )
예제 #19
0
def test_case_2a_send_duplicated_force_subtask_results(
        cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    #  Test CASE 2A + 2D + 3 + 4B + 5 - Send ForceSubtaskResults with same task_id as stored by Concent before
    #  Step 1. Send ForceSubtaskResults first time
    receive_pending_messages_for_requestor_and_provider(
        cluster_url, sci_base, CONCENT_PUBLIC_KEY)
    current_time = get_current_utc_timestamp()
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.minimum_upload_rate),
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.minimum_upload_rate),
        price=1000,
        provider_public_key=sci_base.provider_public_key,
        provider_private_key=sci_base.provider_private_key,
        requestor_public_key=sci_base.requestor_public_key,
        requestor_private_key=sci_base.requestor_private_key)
    force_subtask_results = create_force_subtask_results(
        timestamp=timestamp_to_isoformat(current_time),
        ack_report_computed_task=create_ack_report_computed_task(
            timestamp=timestamp_to_isoformat(current_time),
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=signed_task_to_compute,
                provider_private_key=sci_base.provider_private_key,
            ),
            requestor_private_key=sci_base.requestor_private_key,
        ))
    signed_report_computed_task = create_signed_report_computed_task(
        task_to_compute=signed_task_to_compute,
        provider_private_key=sci_base.provider_private_key,
    )
    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        force_subtask_results,
        expected_status=202,
    )
    time.sleep(1)
    #  Step 2. Send ForceSubtaskResults second time with same task_id
    # Signature must be set to None, because msg will be signed again in api_request()
    force_subtask_results.sig = None
    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        force_subtask_results,
        expected_status=200,
        expected_message_type=message.concents.ServiceRefused,
        expected_content_type='application/octet-stream',
    )
    #  Step 3. Requestor wants to receive ForceSubtaskResults from Concent
    api_request(
        cluster_url,
        'receive',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.requestor_private_key,
                                   sci_base.requestor_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults,
        expected_content_type='application/octet-stream',
    )

    #  Step 4. Requestor sends ForceSubtaskResultsResponse for the first ForceSubtaskResults
    api_request(
        cluster_url,
        'send',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results_response(
            timestamp=timestamp_to_isoformat(current_time),
            subtask_results_accepted=create_signed_subtask_results_accepted(
                payment_ts=current_time + 1,
                report_computed_task=signed_report_computed_task,
                requestor_private_key=sci_base.requestor_private_key,
            )),
        expected_status=202,
    )
    #  Step 5. Provider receives ForceSubtaskResultsResponse
    api_request(
        cluster_url,
        'receive',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.provider_private_key,
                                   sci_base.provider_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResultsResponse,
        expected_content_type='application/octet-stream',
    )
예제 #20
0
def test_case_2d_requestor_rejects_subtask_results(
        cluster_consts: ProtocolConstants, cluster_url: str) -> None:
    # Test CASE 2D + 3 + 4B + 5. Requestor sends ForceSubtaskResultsResponse with SubtaskResultsRejected
    receive_pending_messages_for_requestor_and_provider(
        cluster_url, sci_base, CONCENT_PUBLIC_KEY)
    current_time = get_current_utc_timestamp()
    signed_task_to_compute = create_signed_task_to_compute(
        timestamp=calculate_timestamp(current_time,
                                      cluster_consts.concent_messaging_time,
                                      cluster_consts.minimum_upload_rate),
        deadline=calculate_deadline(current_time,
                                    cluster_consts.concent_messaging_time,
                                    cluster_consts.minimum_upload_rate),
        price=1000,
        provider_public_key=sci_base.provider_public_key,
        provider_private_key=sci_base.provider_private_key,
        requestor_public_key=sci_base.requestor_public_key,
        requestor_private_key=sci_base.requestor_private_key)
    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results(
            timestamp=timestamp_to_isoformat(current_time),
            ack_report_computed_task=create_ack_report_computed_task(
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=create_signed_report_computed_task(
                    task_to_compute=signed_task_to_compute,
                    provider_private_key=sci_base.provider_private_key,
                ),
                requestor_private_key=sci_base.requestor_private_key)),
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.requestor_private_key,
                                   sci_base.requestor_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResults,
        expected_content_type='application/octet-stream',
    )
    api_request(
        cluster_url,
        'send',
        sci_base.requestor_private_key,
        CONCENT_PUBLIC_KEY,
        create_force_subtask_results_response(
            timestamp=timestamp_to_isoformat(current_time),
            subtask_results_rejected=create_subtask_results_rejected(
                reason=message.tasks.SubtaskResultsRejected.REASON.
                VerificationNegative,
                timestamp=timestamp_to_isoformat(current_time),
                report_computed_task=create_signed_report_computed_task(
                    task_to_compute=signed_task_to_compute,
                    timestamp=timestamp_to_isoformat(current_time),
                    provider_private_key=sci_base.provider_private_key,
                ),
                requestor_private_key=sci_base.requestor_private_key)),
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(sci_base.provider_private_key,
                                   sci_base.provider_public_key,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForceSubtaskResultsResponse,
        expected_content_type='application/octet-stream',
    )
def test_case_6_test_without_script_src_in(cluster_consts, cluster_url,
                                           test_id):  # pylint: disable=unused-argument
    current_time = get_current_utc_timestamp()
    (subtask_id, task_id) = get_task_id_and_subtask_id(test_id,
                                                       'without_script_src')

    current_dir = os.path.dirname(os.path.abspath(__file__))
    with open(os.path.join(current_dir, 'tests_resources', 'source.zip'),
              'rb') as archive:
        source_file_content = archive.read()
    with open(os.path.join(current_dir, 'tests_resources', 'result.zip'),
              'rb') as archive:
        result_file_content = archive.read()

    result_file_size = len(result_file_content)
    source_file_size = len(source_file_content)
    result_file_checksum = 'sha1:' + hashlib.sha1(
        result_file_content).hexdigest()
    source_file_checksum = 'sha1:' + hashlib.sha1(
        source_file_content).hexdigest()

    ack_subtask_results_verify = api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_subtask_results_verify(
            task_id,
            subtask_id,
            current_time,
            reason=message.tasks.SubtaskResultsRejected.REASON.
            VerificationNegative,
            report_computed_task_size=result_file_size,
            report_computed_task_package_hash=result_file_checksum,
            task_to_compute_size=source_file_size,
            task_to_compute_package_hash=source_file_checksum,
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.AckSubtaskResultsVerify.TYPE,
        expected_content_type='application/octet-stream',
    )

    response = upload_file_to_storage_cluster(
        result_file_content,
        ack_subtask_results_verify.file_transfer_token.files[0]['path'],
        ack_subtask_results_verify.file_transfer_token,
        PROVIDER_PRIVATE_KEY,
        PROVIDER_PUBLIC_KEY,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )
    assert_condition(response.status_code, 200,
                     'File has not been stored on cluster')
    print(
        '\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'
        .format(task_id, result_file_checksum, result_file_size))

    response = upload_file_to_storage_cluster(
        source_file_content,
        ack_subtask_results_verify.file_transfer_token.files[1]['path'],
        ack_subtask_results_verify.file_transfer_token,
        PROVIDER_PRIVATE_KEY,
        PROVIDER_PUBLIC_KEY,
        CONCENT_PUBLIC_KEY,
        STORAGE_CLUSTER_ADDRESS,
    )
    assert_condition(response.status_code, 200,
                     'File has not been stored on cluster')
    print(
        '\nUploaded file with task_id {}. Checksum of this file is {}, and size of this file is {}.\n'
        .format(task_id, source_file_checksum, source_file_size))

    # Adding 10 seconds to time sleep makes us sure that subtask is after deadline.
    time.sleep(CALCULATED_VERIFICATION_TIME *
               (ADDITIONAL_VERIFICATION_TIME_MULTIPLIER / BLENDER_THREADS))

    api_request(
        cluster_url,
        'receive-out-of-band',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.SubtaskResultsSettled.TYPE,
        expected_content_type='application/octet-stream',
    )

    api_request(
        cluster_url,
        'receive-out-of-band',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.SubtaskResultsSettled.TYPE,
        expected_content_type='application/octet-stream',
    )