def test_case_2c_wrong_timestamps(cluster_consts, cluster_url, test_id): # Test CASE 2C - Send ForceSubtaskResults with wrong timestamps current_time = get_current_utc_timestamp() (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2C') 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=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_too_far_in_the_future( current_time, cluster_consts.concent_messaging_time, cluster_consts.concent_upload_rate), price=10000, )))), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ForceSubtaskResultsRejected. TYPE, expected_content_type='application/octet-stream', )
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', )
def test_case_3_test_for_invalid_time(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') file_content = task_id file_size = len(file_content) file_check_sum = 'sha1:' + hashlib.sha1(file_content.encode()).hexdigest() api_request( cluster_url, 'send', PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY, get_subtask_results_verify( task_id, subtask_id, current_time - (CALCULATED_VERIFICATION_TIME * (ADDITIONAL_VERIFICATION_TIME_MULTIPLIER / BLENDER_THREADS)), reason=message.tasks.SubtaskResultsRejected.REASON. VerificationNegative, report_computed_task_size=file_size, report_computed_task_package_hash=file_check_sum, task_to_compute_size=file_size, task_to_compute_package_hash=file_check_sum, ), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ServiceRefused.TYPE, expected_content_type='application/octet-stream', )
def test_case_2_test_for_resources_failure_reason(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') file_content = task_id file_size = len(file_content) file_check_sum = 'sha1:' + hashlib.sha1(file_content.encode()).hexdigest() 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. ResourcesFailure, report_computed_task_size=file_size, report_computed_task_package_hash=file_check_sum, task_to_compute_size=file_size, task_to_compute_package_hash=file_check_sum, ), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ServiceRefused.TYPE, expected_content_type='application/octet-stream', )
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_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, )
def test_case_2_a_force_payment_with_subtask_result_accepted_where_ethereum_accounts_are_different( cluster_consts, cluster_url, test_id): # Test CASE 2A - Send ForcePayment with SubtaskResultsAccepted where ethereum accounts are different current_time = get_current_utc_timestamp() (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2A') api_request( cluster_url, 'send', PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted_list=[ subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=15000, )), subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=15000, requestor_ethereum_public_key=encode_hex( b'0' * GOLEM_PUBLIC_KEY_LENGTH))) ]), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ServiceRefused.TYPE, expected_content_type='application/octet-stream', )
def test_case_2c_send_force_payment_with_no_value_to_be_paid( cluster_consts, cluster_url, test_id): # Test CASE 2C - Send ForcePayment with no value to be paid current_time = get_current_utc_timestamp() (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2C') api_request( cluster_url, 'send', PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted_list=[ subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=0, )), subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=0, )) ]), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ForcePaymentRejected.TYPE, expected_content_type='application/octet-stream', )
def test_case_5_test_requestor_status_account_negative(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') result_file_content_1 = task_id source_file_content_2 = subtask_id result_file_size_1 = len(result_file_content_1) source_file_size_2 = len(source_file_content_2) result_file_check_sum_1 = 'sha1:' + hashlib.sha1( result_file_content_1.encode()).hexdigest() source_file_check_sum_2 = 'sha1:' + hashlib.sha1( source_file_content_2.encode()).hexdigest() 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_1, report_computed_task_package_hash=result_file_check_sum_1, task_to_compute_size=source_file_size_2, task_to_compute_package_hash=source_file_check_sum_2, requestor_ethereum_public_key='33' * 64, provider_ethereum_public_key='32' * 64, price=0), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ServiceRefused.TYPE, expected_content_type='application/octet-stream', )
def test_case_2b_not_enough_funds(cluster_consts, cluster_url, test_id): # Test CASE 2B - Send ForceSubtaskResults with not enough amount of funds on account current_time = get_current_utc_timestamp() (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2B') 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=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), requestor_ethereum_public_key=encode_hex( b'0' * GOLEM_PUBLIC_KEY_LENGTH), provider_ethereum_public_key=encode_hex( b'1' * GOLEM_PUBLIC_KEY_LENGTH), price=0, )))), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ServiceRefused.TYPE, expected_content_type='application/octet-stream', )
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_4b_requestor_accepts_subtaks_results(cluster_consts, cluster_url, test_id): # Test CASE 4B + 5. Requestor sends ForceSubtaskResultsResponse with SubtaskResultsAccepted # Step 1. Provider sends ForceSubtaskResults current_time = get_current_utc_timestamp() (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '4B') 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. 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), headers={ 'Content-Type': 'application/octet-stream', }, expected_status=200, expected_message_type=message.concents.ForceSubtaskResults.TYPE, expected_content_type='application/octet-stream', ) # Step 3. Requestor sends ForceSubtaskResultsResponse api_request( cluster_url, 'send', REQUESTOR_PRIVATE_KEY, CONCENT_PUBLIC_KEY, force_subtask_results_response( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted=subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), payment_ts=timestamp_to_isoformat(current_time + 1), task_to_compute=signed_task_to_compute)), headers={ 'Content-Type': 'application/octet-stream', }, 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), 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_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), task_id=task_id, subtask_id=subtask_id, deadline=calculate_deadline(current_time, cluster_consts.concent_messaging_time), 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_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, 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, 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', )
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_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', )