def test_case_2c_send_force_payment_with_no_value_to_be_paid( cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2C - Send ForcePayment with no value to be paid receive_pending_messages_for_requestor_and_provider( cluster_url, sci_base, CONCENT_PUBLIC_KEY) current_time = get_current_utc_timestamp() api_request( cluster_url, 'send', sci_base.provider_private_key, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), 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=0, 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=0, 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, ), ]), expected_status=200, expected_message_type=message.concents.ServiceRefused, )
def test_case_2b_send_force_payment_beyond_payment_time( cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2B - Send ForcePayment beyond payment time receive_pending_messages_for_requestor_and_provider( cluster_url, sci_base, CONCENT_PUBLIC_KEY) current_time = get_current_utc_timestamp() api_request( cluster_url, 'send', sci_base.provider_private_key, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted_list=[ create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), payment_ts=current_time, 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=15000, 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=15000, 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) ]), expected_status=200, expected_message_type=message.concents.ForcePaymentRejected, 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_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_2c_wrong_timestamps(cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2C - Send ForceSubtaskResults with wrong timestamps current_time = get_current_utc_timestamp() 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=create_signed_task_to_compute( timestamp=calculate_timestamp( current_time, cluster_consts.concent_messaging_time, cluster_consts.minimum_upload_rate), deadline=calculate_deadline_too_far_in_the_future( current_time, cluster_consts.concent_messaging_time, cluster_consts.minimum_upload_rate), price=1000, )))), expected_status=200, expected_message_type=message.concents.ForceSubtaskResultsRejected, expected_content_type='application/octet-stream', )
def test_case_2b_not_enough_funds(cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2B - Send ForceSubtaskResults with not enough amount of funds on account current_time = get_current_utc_timestamp() 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=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), requestor_ethereum_public_key= REQUESTOR_ETHEREUM_PUBLIC_KEY_FOR_EMPTY_ACCOUNT, requestor_ethereum_private_key= REQUESTOR_ETHEREUM_PRIVATE_KEY_FOR_EMPTY_ACCOUNT, provider_ethereum_public_key= DIFFERENT_PROVIDER_ETHEREUM_PUBLIC_KEY, price=10000, )))), expected_status=200, expected_message_type=message.concents.ServiceRefused, expected_content_type='application/octet-stream', )
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_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', )
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_2_a_force_payment_with_subtask_result_accepted_where_ethereum_accounts_are_different( cluster_consts: ProtocolConstants, cluster_url: str, ) -> None: # Test CASE 2A - Send ForcePayment with SubtaskResultsAccepted where ethereum accounts are different current_time = get_current_utc_timestamp() api_request( cluster_url, 'send', PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted_list=[ create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=15000, ))), create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=15000, requestor_ethereum_public_key= DIFFERENT_REQUESTOR_ETHEREUM_PUBLIC_KEY, requestor_ethereum_private_key= DIFFERENT_REQUESTOR_ETHEREUM_PRIVATE_KEY, ))) ]), expected_status=200, expected_message_type=message.concents.ServiceRefused, 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', )
def test_case_2c_send_force_payment_with_no_value_to_be_paid( cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2C - Send ForcePayment with no value to be paid current_time = get_current_utc_timestamp() api_request( cluster_url, 'send', PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted_list=[ create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=0, ))), create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=0, ))) ]), expected_status=400, expected_error_code='message.value_negative', )
def test_case_2b_send_force_payment_beyond_payment_time( cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2B - Send ForcePayment beyond payment time current_time = get_current_utc_timestamp() api_request( cluster_url, 'send', PROVIDER_PRIVATE_KEY, CONCENT_PUBLIC_KEY, force_payment( timestamp=timestamp_to_isoformat(current_time), subtask_results_accepted_list=[ create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), payment_ts=current_time, 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=15000, ))), create_signed_subtask_results_accepted( timestamp=timestamp_to_isoformat(current_time), 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=15000, ))) ]), expected_status=200, expected_message_type=message.concents.ForcePaymentRejected, expected_content_type='application/octet-stream', )
def create_report_computed_task() -> ReportComputedTask: current_time = get_current_utc_timestamp() task_to_compute = create_signed_task_to_compute( timestamp=timestamp_to_isoformat(current_time), deadline=(current_time + 100), price=10000, ) report_computed_task = ReportComputedTaskFactory( task_to_compute=task_to_compute, ) sign_message(report_computed_task, PROVIDER_PRIVATE_KEY) return report_computed_task
def get_subtask_results_verify( task_id, subtask_id, current_time, reason, report_computed_task_size, report_computed_task_package_hash, task_to_compute_size, task_to_compute_package_hash, requestor_ethereum_public_key=None, provider_ethereum_public_key=None, price=1, script_src=None, ): task_to_compute = create_signed_task_to_compute( task_id=task_id, subtask_id=subtask_id, deadline=current_time + CALCULATED_VERIFICATION_TIME, price=price if price is not None else 1, size=task_to_compute_size, package_hash=task_to_compute_package_hash, requestor_ethereum_public_key=requestor_ethereum_public_key, provider_ethereum_public_key=provider_ethereum_public_key, script_src=script_src, ) report_computed_task = message.ReportComputedTask( task_to_compute=task_to_compute, subtask_id=subtask_id, size=report_computed_task_size, package_hash=report_computed_task_package_hash, ) report_computed_task.sign_message(PROVIDER_PRIVATE_KEY, report_computed_task.get_short_hash()) with freeze_time(timestamp_to_isoformat(current_time - 1)): subtask_results_rejected = message.tasks.SubtaskResultsRejected( reason=reason, report_computed_task=report_computed_task, ) subtask_results_rejected.sign_message( REQUESTOR_PRIVATE_KEY, subtask_results_rejected.get_short_hash(), ) subtask_results_verify = message.concents.SubtaskResultsVerify( subtask_results_rejected=subtask_results_rejected, ) return subtask_results_verify
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', )
def test_case_2b_not_enough_funds(cluster_consts: ProtocolConstants, cluster_url: str) -> None: # Test CASE 2B - Send ForceSubtaskResults with not enough amount of funds on account receive_pending_messages_for_requestor_and_provider( cluster_url, sci_base, CONCENT_PUBLIC_KEY) current_time = get_current_utc_timestamp() api_request( cluster_url, 'send', sci_base.provider_empty_account_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=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=10000, provider_public_key=sci_base. provider_empty_account_public_key, provider_private_key=sci_base. provider_empty_account_private_key, requestor_public_key=sci_base. requestor_empty_account_public_key, requestor_private_key=sci_base. requestor_empty_account_private_key), provider_private_key=sci_base. provider_empty_account_private_key, ), requestor_private_key=sci_base. requestor_empty_account_private_key, )), expected_status=200, expected_message_type=message.concents.ServiceRefused, expected_content_type='application/octet-stream', )
def test_case_multiple_force_subtask_results_does_not_cause_integrity_errors( cluster_consts: ProtocolConstants, cluster_url: str ) -> None: clear_responses() provider_private_key, provider_public_key = generate_ecc_key_pair() requestor_private_key, requestor_public_key = generate_ecc_key_pair() 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=provider_public_key, provider_private_key=provider_private_key, requestor_public_key=requestor_public_key, requestor_private_key=requestor_private_key ) report_computed_task = create_signed_report_computed_task( task_to_compute=signed_task_to_compute, provider_private_key=provider_private_key, ) call_function_in_threads( func=send_correct_force_subtask_results, number_of_threads=NUMBER_OF_TESTING_THREADS, cluster_url=cluster_url, report_computed_task=report_computed_task, current_time=current_time, provider_private_key=provider_private_key, requestor_private_key=requestor_private_key, ) end_time = time.time() + MAXIMUM_WAITING_TIME_FOR_ALL_RESPONSES while len(responses_global) != NUMBER_OF_TESTING_THREADS: time.sleep(0.1) if time.time() >= end_time: break expected_responses = ['ServiceRefused', 'ServiceRefused', 'ServiceRefused'] assert len(expected_responses) == NUMBER_OF_TESTING_THREADS, 'Did you change number of testing threads and forget to change expected_responses?' print('Responses = ' + str(responses_global)) assert_content_equal(actual=responses_global, expected=expected_responses) print('Single test passed successfully')
def get_force_get_task_result(task_id, subtask_id, current_time, cluster_consts, size, package_hash): task_to_compute = create_signed_task_to_compute( task_id=task_id, subtask_id=subtask_id, deadline=current_time, price=0, ) with freeze_time(timestamp_to_isoformat(current_time - 1)): report_computed_task = message.ReportComputedTask( task_to_compute=task_to_compute, size=size, package_hash=package_hash, subtask_id=subtask_id, ) with freeze_time(timestamp_to_isoformat(current_time)): force_get_task_result = message.concents.ForceGetTaskResult( report_computed_task=report_computed_task, ) return force_get_task_result
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 get_force_get_task_result( current_time: int, size: int, package_hash: str, ) -> message.concents.ForceGetTaskResult: task_to_compute = create_signed_task_to_compute( deadline=current_time, price=1, ) with freeze_time(timestamp_to_isoformat(current_time - 1)): report_computed_task = ReportComputedTaskFactory( task_to_compute=task_to_compute, size=size, package_hash=package_hash, ) sign_message(report_computed_task, PROVIDER_PRIVATE_KEY) with freeze_time(timestamp_to_isoformat(current_time)): force_get_task_result = message.concents.ForceGetTaskResult( report_computed_task=report_computed_task, ) return force_get_task_result
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_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)
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', )
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', )
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', )
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 get_subtask_results_verify( current_time: int, reason: message.tasks.SubtaskResultsRejected.REASON, report_computed_task_size: int, report_computed_task_package_hash: str, task_to_compute_size: int, task_to_compute_package_hash: str, 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, is_verification_deadline_before_current_time: bool = False, additional_verification_call_time: int = 0, minimum_upload_rate: int = 0, render_parameters: Dict[str, Any] = None ) -> message.concents.SubtaskResultsVerify: task_to_compute = create_signed_task_to_compute( deadline=current_time, price=price if price is not None else 1, size=task_to_compute_size, package_hash=task_to_compute_package_hash, render_parameters=render_parameters, provider_public_key=provider_public_key if provider_public_key else sci_base.provider_public_key, provider_private_key=provider_private_key if provider_private_key else sci_base.provider_private_key, requestor_public_key=requestor_public_key if requestor_public_key else sci_base.requestor_public_key, requestor_private_key=requestor_private_key if requestor_private_key else sci_base.requestor_private_key, ) report_computed_task = message.ReportComputedTask( task_to_compute=task_to_compute, size=report_computed_task_size, package_hash=report_computed_task_package_hash, ) report_computed_task.sign_message( provider_private_key if provider_private_key else sci_base.provider_private_key, report_computed_task.get_short_hash() ) with freeze_time(timestamp_to_isoformat(current_time - 1)): subtask_results_rejected = message.tasks.SubtaskResultsRejected( reason=reason, report_computed_task=report_computed_task, ) if is_verification_deadline_before_current_time: override_timestamp( subtask_results_rejected, subtask_results_rejected.timestamp - ( additional_verification_call_time + calculate_maximum_download_time( report_computed_task.size, minimum_upload_rate, ) + 1 ) ) subtask_results_rejected.sign_message( requestor_private_key if requestor_private_key else sci_base.requestor_private_key, subtask_results_rejected.get_short_hash(), ) subtask_results_verify = message.concents.SubtaskResultsVerify( subtask_results_rejected=subtask_results_rejected, ) subtask_results_verify.sign_concent_promissory_note( deposit_contract_address=GNT_DEPOSIT_CONTRACT_ADDRESS, private_key=provider_private_key or sci_base.provider_private_key, ) return subtask_results_verify
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', )