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: 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: 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_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 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_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, ) signed_report_computed_task = create_signed_report_computed_task(task_to_compute=signed_task_to_compute) 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=signed_report_computed_task ) ), 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_signed_subtask_results_accepted( payment_ts=current_time + 1, report_computed_task=signed_report_computed_task, timestamp=timestamp_to_isoformat(current_time) ) ), 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_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_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)