def test_case_3_test_for_invalid_time(cluster_consts: ProtocolConstants, cluster_url: str) -> None:  # pylint: disable=unused-argument
    receive_pending_messages_for_requestor_and_provider(
        cluster_url,
        sci_base,
        CONCENT_PUBLIC_KEY
    )
    current_time = get_current_utc_timestamp()

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

    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        get_subtask_results_verify(
            current_time,
            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,
            is_verification_deadline_before_current_time=True,
            additional_verification_call_time=cluster_consts.additional_verification_call_time,
            minimum_upload_rate=cluster_consts.minimum_upload_rate,
            render_parameters=get_render_params()
        ),
        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_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_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_ping_message_send_to_concent_with_supported_golem_messages_should_get_http400_response_with_message_unknown_error(
    cluster_url: str,
    cluster_consts: ProtocolConstants,
    concent_1_golem_messages_version: str,
    concent_2_golem_messages_version: str,
) -> None:
    # Sending Ping message to concent with supported versions of Golem Messages.
    # Expected: nginx-router will forward it to the cluster with that version, user will receive Http400,
    # with error code ErrorCode.MESSAGE_UNKNOWN, because concent doesn't handle Ping message.
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        Ping(),
        expected_status=400,
        expected_golem_version=concent_1_golem_messages_version,
        expected_error_code='message.unknown',
    )
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        Ping(),
        expected_status=400,
        expected_golem_version=concent_2_golem_messages_version,
        expected_error_code='message.unknown',
    )
Ejemplo n.º 6
0
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_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_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',
    )
Ejemplo n.º 9
0
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',
    )
Ejemplo n.º 10
0
def test_case_2d_send_correct_force_payment(cluster_consts, cluster_url,
                                            test_id):
    # Test CASE 2D - Send correct ForcePayment
    current_time = get_current_utc_timestamp()
    (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '2D')
    correct_force_payment = force_payment(subtask_results_accepted_list=[
        subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            task_to_compute=create_signed_task_to_compute(
                timestamp=parse_timestamp_to_utc_datetime(current_time),
                task_id=task_id + 'a',
                subtask_id=subtask_id + 'A',
                deadline=current_time,
                price=1000,
            )),
        subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            task_to_compute=create_signed_task_to_compute(
                timestamp=parse_timestamp_to_utc_datetime(current_time),
                task_id=task_id + 'b',
                subtask_id=subtask_id + 'B',
                deadline=current_time,
                price=1000,
            ))
    ])
    correct_force_payment.sig = None
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        correct_force_payment,
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted.TYPE,
        expected_content_type='application/octet-stream',
    )
    time.sleep(5)
    api_request(
        cluster_url,
        'receive-out-of-band',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted.TYPE,
        expected_content_type='application/octet-stream',
    )
Ejemplo n.º 11
0
def test_case_1_provider_forces_report_computed_task_and_gets_accepted(cluster_consts, cluster_url, test_id):
    current_time = get_current_utc_timestamp()
    (task_id, subtask_id) = get_task_id_and_subtask_id(test_id, '1')
    task_to_compute = create_signed_task_to_compute(
        task_id=task_id,
        subtask_id=subtask_id,
        deadline=current_time + 1
    )
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_report_computed_task(
            task_to_compute=task_to_compute
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=ForceReportComputedTask.TYPE,
        expected_content_type='application/octet-stream',
    )
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        ack_report_computed_task(
            task_to_compute=task_to_compute
        ),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY, CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=200,
        expected_message_type=ForceReportComputedTaskResponse.TYPE,
        expected_content_type='application/octet-stream',
    )
def test_case_4_test_for_duplicated_request(cluster_consts: ProtocolConstants, cluster_url: str) -> None:  # pylint: disable=unused-argument
    receive_pending_messages_for_requestor_and_provider(
        cluster_url,
        sci_base,
        CONCENT_PUBLIC_KEY
    )
    current_time = get_current_utc_timestamp()

    result_file_content_1 = 'test'
    source_file_content_2 = 'test'
    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()

    subtask_results_verify = get_subtask_results_verify(
        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,
        render_parameters=get_render_params()
    )

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

    # Set signature to None so message can be serialized again.
    subtask_results_verify.sig = None

    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        subtask_results_verify,
        expected_status=200,
        expected_message_type=message.concents.ServiceRefused,
        expected_content_type='application/octet-stream',
    )
Ejemplo n.º 13
0
def send_correct_ack_report_computed_task(
    cluster_url: str,
    report_computed_task: ReportComputedTask,
    expected_status: Optional[int] = None
) -> None:
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_ack_report_computed_task(
            report_computed_task=report_computed_task
        ),
        expected_status=expected_status,
    )
Ejemplo n.º 14
0
def test_case_2d_send_correct_force_payment(cluster_consts: ProtocolConstants,
                                            cluster_url: str) -> None:
    # Test CASE 2D - Send correct ForcePayment
    current_time = get_current_utc_timestamp()
    correct_force_payment = force_payment(subtask_results_accepted_list=[
        create_signed_subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=create_signed_task_to_compute(
                    timestamp=parse_timestamp_to_utc_datetime(current_time),
                    deadline=current_time,
                    price=1000,
                ))),
        create_signed_subtask_results_accepted(
            payment_ts=current_time - cluster_consts.payment_due_time -
            AVERAGE_TIME_FOR_TWO_BLOCKS,
            report_computed_task=create_signed_report_computed_task(
                task_to_compute=create_signed_task_to_compute(
                    timestamp=parse_timestamp_to_utc_datetime(current_time),
                    deadline=current_time,
                    price=1000,
                )))
    ])
    correct_force_payment.sig = None
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        correct_force_payment,
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted,
        expected_content_type='application/octet-stream',
    )
    time.sleep(5)
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=message.concents.ForcePaymentCommitted,
        expected_content_type='application/octet-stream',
    )
Ejemplo n.º 15
0
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',
    )
Ejemplo n.º 16
0
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',
    )
Ejemplo n.º 17
0
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_6_test_with_invalid_blender_script_parameters(cluster_consts: ProtocolConstants, cluster_url: str) -> None:  # pylint: disable=unused-argument
    receive_pending_messages_for_requestor_and_provider(
        cluster_url,
        sci_base,
        CONCENT_PUBLIC_KEY
    )
    current_time = get_current_utc_timestamp()

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

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

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

    # Setting parameters which are necessary for proper blender work to invalid values
    subtask_results_verify.task_to_compute.compute_task_def['extra_data']['crops'] = None
    subtask_results_verify.task_to_compute.compute_task_def['extra_data']['resolution'] = None
    subtask_results_verify.task_to_compute.compute_task_def['extra_data']['samples'] = None
    subtask_results_verify.task_to_compute.compute_task_def['extra_data']['use_compositing'] = None

    api_request(
        cluster_url,
        'send',
        sci_base.provider_private_key,
        CONCENT_PUBLIC_KEY,
        subtask_results_verify,
        expected_status=400,
        expected_error_code='message.invalid',
    )
Ejemplo n.º 19
0
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_ping_message_send_to_concent_with_unsupported_golem_messages_should_get_http404_response_with_not_found_error(
    cluster_url: str,
    cluster_consts: ProtocolConstants,
    concent_1_golem_messages_version: str,
    concent_2_golem_messages_version: str,
) -> None:
    # Sending Ping message to concent with unsupported version of Golem Messages.
    # Expected: nginx-router will respond with Http404.
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        Ping(),
        headers={
            'Content-Type': 'application/octet-stream',
            'X-Golem-Messages': '1.0.0'
        },
        expected_status=404,
        expected_error_code='not-found',
    )
def test_case_ping_message_send_to_concent_with_malformed_golem_messages_should_get_http400_response_with_bad_request_error(
    cluster_url: str,
    cluster_consts: ProtocolConstants,
    concent_1_golem_messages_version: str,
    concent_2_golem_messages_version: str,
) -> None:
    # Sending Ping message to concent with malformed header(Golem Messages version has a wrong, non-semver format).
    # Expected: ngingx-router will respond with Http400 with error code "bad-request".
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        Ping(),
        headers={
            'Content-Type': 'application/octet-stream',
            'X-Golem-Messages': 'X.X.X'
        },
        expected_status=400,
        expected_error_code='bad-request',
    )
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',
    )
Ejemplo n.º 23
0
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',
    )
Ejemplo n.º 24
0
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_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',
    )
Ejemplo n.º 26
0
def send_correct_force_get_task_result(
    cluster_url: str,
    report_computed_task: ReportComputedTask,
    expected_status: Optional[int] = None,
) -> None:
    response = api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_force_get_task_result(
            report_computed_task=report_computed_task,
        ),
        expected_status=expected_status,
    )
    responses_global.append(response.__class__.__name__)
Ejemplo n.º 27
0
def send_correct_force_report_computed_task(
    cluster_url: str,
    report_computed_task: ReportComputedTask,
    expected_status: Optional[int] = None
) -> None:
    response = api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        get_force_report_computed_task(
            report_computed_task=report_computed_task,
        ),
        expected_status=expected_status,
    )
    responses_global.append(response['error_code'] if isinstance(response, dict) else response)
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',
    )
Ejemplo n.º 29
0
def test_case_1_provider_forces_report_computed_task_and_gets_accepted(
    cluster_consts: ProtocolConstants,
    cluster_url: str,
) -> None:
    current_time = get_current_utc_timestamp()
    task_to_compute = create_signed_task_to_compute(deadline=current_time + 1)
    api_request(
        cluster_url,
        'send',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        force_report_computed_task(task_to_compute=task_to_compute),
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=ForceReportComputedTask,
        expected_content_type='application/octet-stream',
    )
    api_request(
        cluster_url,
        'send',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        ack_report_computed_task(task_to_compute=task_to_compute),
        expected_status=202,
    )
    api_request(
        cluster_url,
        'receive',
        PROVIDER_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(PROVIDER_PRIVATE_KEY, PROVIDER_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        expected_status=200,
        expected_message_type=ForceReportComputedTaskResponse,
        expected_content_type='application/octet-stream',
    )
Ejemplo n.º 30
0
def test_case_2_test_for_non_existing_file(cluster_consts, cluster_url,
                                           test_id):
    current_time = get_current_utc_timestamp()
    (subtask_id, task_id) = get_task_id_and_subtask_id(test_id,
                                                       'non_existing_file')

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

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

    api_request(
        cluster_url,
        'receive',
        REQUESTOR_PRIVATE_KEY,
        CONCENT_PUBLIC_KEY,
        create_client_auth_message(REQUESTOR_PRIVATE_KEY, REQUESTOR_PUBLIC_KEY,
                                   CONCENT_PUBLIC_KEY),
        headers={
            'Content-Type': 'application/octet-stream',
        },
        expected_status=204,
    )