Example #1
0
def local_matrix_servers(
    request,
    transport_protocol,
    matrix_server_count,
    synapse_config_generator,
    port_generator,
    broadcast_rooms,
    chain_id,
):
    if transport_protocol is not TransportProtocol.MATRIX:
        yield [None]
        return

    broadcast_rooms_aliases = [
        make_room_alias(chain_id, room_name) for room_name in broadcast_rooms
    ]

    starter = matrix_server_starter(
        free_port_generator=port_generator,
        broadcast_rooms_aliases=broadcast_rooms_aliases,
        count=matrix_server_count,
        config_generator=synapse_config_generator,
        log_context=request.node.name,
    )
    with starter as server_urls:
        yield server_urls
Example #2
0
def local_matrix_servers_with_executor(
    request,
    transport_protocol,
    matrix_server_count,
    synapse_config_generator,
    port_generator,
    broadcast_rooms,
    chain_id,
) -> Iterable[List[Tuple[ParsedURL, HTTPExecutor]]]:
    if transport_protocol is not TransportProtocol.MATRIX:
        yield []
        return

    broadcast_rooms_aliases = [
        make_room_alias(chain_id, room_name) for room_name in broadcast_rooms
    ]

    starter = matrix_server_starter(
        free_port_generator=port_generator,
        broadcast_rooms_aliases=broadcast_rooms_aliases,
        count=matrix_server_count,
        config_generator=synapse_config_generator,
        log_context=request.node.name,
    )
    with starter as servers:
        yield servers
Example #3
0
def setup_matrix_for_smoketest(
        print_step: Callable,
        free_port_generator: Iterable[Port]) -> Iterator[List["ParsedURL"]]:
    from raiden.tests.utils.transport import matrix_server_starter

    print_step("Starting Matrix transport")

    with matrix_server_starter(free_port_generator=free_port_generator) as ctx:
        yield ctx
Example #4
0
def setup_matrix_for_smoketest(
    print_step: Callable,
    free_port_generator: Iterable[Port],
    broadcast_rooms_aliases: Iterable[str],
) -> Iterator[List[Tuple["ParsedURL", HTTPExecutor]]]:
    from raiden.tests.utils.transport import matrix_server_starter

    print_step("Starting Matrix transport")

    with matrix_server_starter(free_port_generator, broadcast_rooms_aliases) as ctx:
        yield ctx
Example #5
0
def local_matrix_servers(request, transport_protocol, matrix_server_count,
                         synapse_config_generator, port_generator):
    if transport_protocol is not TransportProtocol.MATRIX:
        yield [None]
        return

    starter = matrix_server_starter(
        free_port_generator=port_generator,
        count=matrix_server_count,
        config_generator=synapse_config_generator,
        log_context=request.node.name,
    )
    with starter as server_urls:
        yield server_urls
Example #6
0
def local_matrix_servers(
        request,
        transport_protocol,
        matrix_server_count,
        synapse_config_generator,
):
    if transport_protocol is not TransportProtocol.MATRIX:
        yield [None]
        return

    starter = matrix_server_starter(
        count=matrix_server_count,
        config_generator=synapse_config_generator,
        log_context=request.node.name,
    )
    with starter as server_urls:
        yield server_urls
Example #7
0
def local_matrix_servers(
    request,
    transport_protocol,
    matrix_server_count,
    synapse_config_generator,
):
    if transport_protocol is not TransportProtocol.MATRIX:
        yield [None]
        return

    starter = matrix_server_starter(
        count=matrix_server_count,
        config_generator=synapse_config_generator,
        log_context=request.node.name,
        initial_port=request.config.getoption('synapse_base_port'),
    )
    with starter as server_urls:
        yield server_urls
Example #8
0
def smoketest(ctx, debug, eth_client):
    """ Test, that the raiden installation is sane. """
    from raiden.tests.utils.smoketest import setup_testchain_and_raiden, run_smoketest
    from raiden.tests.utils.transport import make_requests_insecure, matrix_server_starter

    report_file = mktemp(suffix=".log")
    configure_logging(
        logger_level_config={"": "DEBUG"},
        log_file=report_file,
        disable_debug_logfile=ctx.parent.params["disable_debug_logfile"],
    )
    free_port_generator = get_free_port()
    click.secho(f"Report file: {report_file}", fg="yellow")

    def append_report(subject: str, data: Optional[AnyStr] = None):
        with open(report_file, "a", encoding="UTF-8") as handler:
            handler.write(f'{f" {subject.upper()} ":=^80}{os.linesep}')
            if data is not None:
                write_data: str
                if isinstance(data, bytes):
                    write_data = data.decode()
                else:
                    write_data = data
                handler.writelines([write_data + os.linesep])

    append_report("Raiden version", json.dumps(get_system_spec()))
    append_report("Raiden log")

    step_count = 7
    if ctx.parent.params["transport"] == "matrix":
        step_count = 8
    step = 0

    stdout = sys.stdout

    def print_step(description: str, error: bool = False) -> None:
        nonlocal step
        step += 1
        click.echo(
            "{} {}".format(
                click.style(f"[{step}/{step_count}]", fg="blue"),
                click.style(description, fg="green" if not error else "red"),
            ),
            file=stdout,
        )

    print_step("Getting smoketest configuration")
    contracts_version = environment_type_to_contracts_version(
        ctx.parent.params["environment_type"])

    with setup_testchain_and_raiden(
            transport=ctx.parent.params["transport"],
            eth_client=eth_client,
            matrix_server=ctx.parent.params["matrix_server"],
            contracts_version=contracts_version,
            print_step=print_step,
            free_port_generator=free_port_generator,
    ) as result:
        args = result["args"]
        contract_addresses = result["contract_addresses"]
        token = result["token"]
        ethereum_nodes = result["ethereum_nodes"]
        # Also respect environment type
        args["environment_type"] = ctx.parent.params["environment_type"]
        for option_ in run.params:
            if option_.name in args.keys():
                args[option_.name] = option_.process_value(
                    ctx, args[option_.name])
            else:
                args[option_.name] = option_.default

        port = next(free_port_generator)

        args["api_address"] = "localhost:" + str(port)

        if args["transport"] == "udp":
            with SocketFactory("127.0.0.1", port,
                               strategy="none") as mapped_socket:
                args["mapped_socket"] = mapped_socket
                success = run_smoketest(
                    print_step=print_step,
                    append_report=append_report,
                    args=args,
                    contract_addresses=contract_addresses,
                    token=token,
                    debug=debug,
                    ethereum_nodes=ethereum_nodes,
                )
        elif args["transport"] == "matrix":
            args["mapped_socket"] = None
            print_step("Starting Matrix transport")
            try:
                with matrix_server_starter(
                        free_port_generator=free_port_generator
                ) as server_urls:
                    # Disable TLS verification so we can connect to the self signed certificate
                    make_requests_insecure()
                    urllib3.disable_warnings(InsecureRequestWarning)
                    args["extra_config"] = {
                        "transport": {
                            "matrix": {
                                "available_servers": server_urls
                            }
                        }
                    }
                    success = run_smoketest(
                        print_step=print_step,
                        append_report=append_report,
                        args=args,
                        contract_addresses=contract_addresses,
                        token=token,
                        debug=debug,
                        ethereum_nodes=ethereum_nodes,
                    )
            except (PermissionError, ProcessExitedWithError,
                    FileNotFoundError):
                append_report("Matrix server start exception",
                              traceback.format_exc())
                print_step(
                    f"Error during smoketest setup, report was written to {report_file}",
                    error=True,
                )
                success = False
        else:
            # Shouldn't happen
            raise RuntimeError(f"Invalid transport type '{args['transport']}'")

    if not success:
        sys.exit(1)
Example #9
0
def smoketest(ctx, debug, **kwargs):  # pylint: disable=unused-argument
    """ Test, that the raiden installation is sane. """
    from raiden.api.python import RaidenAPI
    from raiden.tests.utils.smoketest import (
        TEST_PARTNER_ADDRESS,
        TEST_DEPOSIT_AMOUNT,
        run_smoketests,
        setup_testchain_and_raiden,
    )

    report_file = mktemp(suffix='.log')
    configure_logging(
        logger_level_config={'': 'DEBUG'},
        log_file=report_file,
        disable_debug_logfile=ctx.parent.params['disable_debug_logfile'],
    )
    click.secho(
        f'Report file: {report_file}',
        fg='yellow',
    )

    def append_report(subject, data):
        with open(report_file, 'a', encoding='UTF-8') as handler:
            handler.write(f'{f" {subject.upper()} ":=^80}{os.linesep}')
            if data is not None:
                if isinstance(data, bytes):
                    data = data.decode()
                handler.writelines([data + os.linesep])

    append_report('Raiden version', json.dumps(get_system_spec()))
    append_report('Raiden log', None)

    step_count = 7
    if ctx.parent.params['transport'] == 'matrix':
        step_count = 8
    step = 0

    def print_step(description, error=False):
        nonlocal step
        step += 1
        click.echo(
            '{} {}'.format(
                click.style(f'[{step}/{step_count}]', fg='blue'),
                click.style(description, fg='green' if not error else 'red'),
            ), )

    print_step('Getting smoketest configuration')

    result = setup_testchain_and_raiden(
        ctx.parent.params['transport'],
        ctx.parent.params['matrix_server'],
        print_step,
        'pre_limits',  # smoke test should work with pre-limits contract version
    )
    args = result['args']
    contract_addresses = result['contract_addresses']
    token = result['token']
    ethereum = result['ethereum']

    for option_ in run.params:
        if option_.name in args.keys():
            args[option_.name] = option_.process_value(ctx, args[option_.name])
        else:
            args[option_.name] = option_.default

    port = next(get_free_port('127.0.0.1', 5001))

    args['api_address'] = 'localhost:' + str(port)

    def _run_smoketest():
        print_step('Starting Raiden')

        config = deepcopy(App.DEFAULT_CONFIG)
        if args.get('extra_config', dict()):
            merge_dict(config, args['extra_config'])
            del args['extra_config']
        args['config'] = config

        raiden_stdout = StringIO()
        with contextlib.redirect_stdout(raiden_stdout):
            try:
                # invoke the raiden app
                app = run_app(**args)

                raiden_api = RaidenAPI(app.raiden)
                rest_api = RestAPI(raiden_api)
                api_server = APIServer(rest_api)
                (api_host, api_port) = split_endpoint(args['api_address'])
                api_server.start(api_host, api_port)

                raiden_api.channel_open(
                    registry_address=contract_addresses[
                        CONTRACT_TOKEN_NETWORK_REGISTRY],
                    token_address=to_canonical_address(token.contract.address),
                    partner_address=to_canonical_address(TEST_PARTNER_ADDRESS),
                )
                raiden_api.set_total_channel_deposit(
                    contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY],
                    to_canonical_address(token.contract.address),
                    to_canonical_address(TEST_PARTNER_ADDRESS),
                    TEST_DEPOSIT_AMOUNT,
                )
                token_addresses = [to_checksum_address(token.contract.address)]

                success = False
                print_step('Running smoketest')
                error = run_smoketests(
                    app.raiden,
                    args['transport'],
                    token_addresses,
                    contract_addresses[CONTRACT_ENDPOINT_REGISTRY],
                    debug=debug,
                )
                if error is not None:
                    append_report('Smoketest assertion error', error)
                else:
                    success = True
            finally:
                app.stop()
                app.raiden.get()
                node = ethereum[0]
                node.send_signal(2)
                err, out = node.communicate()

                append_report('Ethereum stdout', out)
                append_report('Ethereum stderr', err)
        append_report('Raiden Node stdout', raiden_stdout.getvalue())
        if success:
            print_step(f'Smoketest successful')
        else:
            print_step(f'Smoketest had errors', error=True)
        return success

    if args['transport'] == 'udp':
        with SocketFactory('127.0.0.1', port,
                           strategy='none') as mapped_socket:
            args['mapped_socket'] = mapped_socket
            success = _run_smoketest()
    elif args['transport'] == 'matrix':
        args['mapped_socket'] = None
        print_step('Starting Matrix transport')
        try:
            with matrix_server_starter() as server_urls:
                # Disable TLS verification so we can connect to the self signed certificate
                make_requests_insecure()
                urllib3.disable_warnings(InsecureRequestWarning)
                args['extra_config'] = {
                    'transport': {
                        'matrix': {
                            'available_servers': server_urls,
                        },
                    },
                }
                success = _run_smoketest()
        except (PermissionError, ProcessExitedWithError, FileNotFoundError):
            append_report('Matrix server start exception',
                          traceback.format_exc())
            print_step(
                f'Error during smoketest setup, report was written to {report_file}',
                error=True,
            )
            success = False
    else:
        # Shouldn't happen
        raise RuntimeError(f"Invalid transport type '{args['transport']}'")

    if not success:
        sys.exit(1)
Example #10
0
def smoketest(ctx, debug, eth_client):
    """ Test, that the raiden installation is sane. """
    from raiden.tests.utils.smoketest import setup_testchain_and_raiden, run_smoketest
    from raiden.tests.utils.transport import make_requests_insecure, matrix_server_starter

    report_file = mktemp(suffix='.log')
    configure_logging(
        logger_level_config={'': 'DEBUG'},
        log_file=report_file,
        disable_debug_logfile=ctx.parent.params['disable_debug_logfile'],
    )
    click.secho(f'Report file: {report_file}', fg='yellow')

    def append_report(subject: str, data: Optional[AnyStr] = None):
        with open(report_file, 'a', encoding='UTF-8') as handler:
            handler.write(f'{f" {subject.upper()} ":=^80}{os.linesep}')
            if data is not None:
                if isinstance(data, bytes):
                    data = data.decode()
                handler.writelines([data + os.linesep])

    append_report('Raiden version', json.dumps(get_system_spec()))
    append_report('Raiden log')

    step_count = 7
    if ctx.parent.params['transport'] == 'matrix':
        step_count = 8
    step = 0

    stdout = sys.stdout

    def print_step(description: str, error: bool = False) -> None:
        nonlocal step
        step += 1
        click.echo(
            '{} {}'.format(
                click.style(f'[{step}/{step_count}]', fg='blue'),
                click.style(description, fg='green' if not error else 'red'),
            ),
            file=stdout,
        )

    print_step('Getting smoketest configuration')
    contracts_version = environment_type_to_contracts_version(
        ctx.parent.params['environment_type'], )

    with setup_testchain_and_raiden(
            transport=ctx.parent.params['transport'],
            eth_client=eth_client,
            matrix_server=ctx.parent.params['matrix_server'],
            contracts_version=contracts_version,
            print_step=print_step,
    ) as result:
        args = result['args']
        contract_addresses = result['contract_addresses']
        token = result['token']
        ethereum_nodes = result['ethereum_nodes']
        # Also respect environment type
        args['environment_type'] = ctx.parent.params['environment_type']
        for option_ in run.params:
            if option_.name in args.keys():
                args[option_.name] = option_.process_value(
                    ctx, args[option_.name])
            else:
                args[option_.name] = option_.default

        port = next(get_free_port(5001))

        args['api_address'] = 'localhost:' + str(port)

        if args['transport'] == 'udp':
            with SocketFactory('127.0.0.1', port,
                               strategy='none') as mapped_socket:
                args['mapped_socket'] = mapped_socket
                success = run_smoketest(
                    print_step=print_step,
                    append_report=append_report,
                    args=args,
                    contract_addresses=contract_addresses,
                    token=token,
                    debug=debug,
                    ethereum_nodes=ethereum_nodes,
                )
        elif args['transport'] == 'matrix':
            args['mapped_socket'] = None
            print_step('Starting Matrix transport')
            try:
                with matrix_server_starter() as server_urls:
                    # Disable TLS verification so we can connect to the self signed certificate
                    make_requests_insecure()
                    urllib3.disable_warnings(InsecureRequestWarning)
                    args['extra_config'] = {
                        'transport': {
                            'matrix': {
                                'available_servers': server_urls,
                            },
                        },
                    }
                    success = run_smoketest(
                        print_step=print_step,
                        append_report=append_report,
                        args=args,
                        contract_addresses=contract_addresses,
                        token=token,
                        debug=debug,
                        ethereum_nodes=ethereum_nodes,
                    )
            except (PermissionError, ProcessExitedWithError,
                    FileNotFoundError):
                append_report('Matrix server start exception',
                              traceback.format_exc())
                print_step(
                    f'Error during smoketest setup, report was written to {report_file}',
                    error=True,
                )
                success = False
        else:
            # Shouldn't happen
            raise RuntimeError(f"Invalid transport type '{args['transport']}'")

    if not success:
        sys.exit(1)
Example #11
0
def smoketest(ctx, debug, **kwargs):  # pylint: disable=unused-argument
    """ Test, that the raiden installation is sane. """
    from raiden.api.python import RaidenAPI
    from raiden.tests.utils.smoketest import (
        TEST_PARTNER_ADDRESS,
        TEST_DEPOSIT_AMOUNT,
        run_smoketests,
        setup_testchain_and_raiden,
    )

    report_file = mktemp(suffix='.log')
    configure_logging(
        logger_level_config={'': 'DEBUG'},
        log_file=report_file,
        disable_debug_logfile=ctx.parent.params['disable_debug_logfile'],
    )
    click.secho(
        f'Report file: {report_file}',
        fg='yellow',
    )

    def append_report(subject, data):
        with open(report_file, 'a', encoding='UTF-8') as handler:
            handler.write(f'{f" {subject.upper()} ":=^80}{os.linesep}')
            if data is not None:
                if isinstance(data, bytes):
                    data = data.decode()
                handler.writelines([data + os.linesep])

    append_report('Raiden version', json.dumps(get_system_spec()))
    append_report('Raiden log', None)

    step_count = 7
    if ctx.parent.params['transport'] == 'matrix':
        step_count = 8
    step = 0

    def print_step(description, error=False):
        nonlocal step
        step += 1
        click.echo(
            '{} {}'.format(
                click.style(f'[{step}/{step_count}]', fg='blue'),
                click.style(description, fg='green' if not error else 'red'),
            ),
        )

    print_step('Getting smoketest configuration')

    result = setup_testchain_and_raiden(
        ctx.parent.params['transport'],
        ctx.parent.params['matrix_server'],
        print_step,
        'pre_limits',  # smoke test should work with pre-limits contract version
    )
    args = result['args']
    contract_addresses = result['contract_addresses']
    token = result['token']
    ethereum = result['ethereum']

    for option_ in run.params:
        if option_.name in args.keys():
            args[option_.name] = option_.process_value(ctx, args[option_.name])
        else:
            args[option_.name] = option_.default

    port = next(get_free_port('127.0.0.1', 5001))

    args['api_address'] = 'localhost:' + str(port)

    def _run_smoketest():
        print_step('Starting Raiden')

        config = deepcopy(App.DEFAULT_CONFIG)
        if args.get('extra_config', dict()):
            merge_dict(config, args['extra_config'])
            del args['extra_config']
        args['config'] = config

        raiden_stdout = StringIO()
        with contextlib.redirect_stdout(raiden_stdout):
            try:
                # invoke the raiden app
                app = run_app(**args)

                raiden_api = RaidenAPI(app.raiden)
                rest_api = RestAPI(raiden_api)
                api_server = APIServer(rest_api)
                (api_host, api_port) = split_endpoint(args['api_address'])
                api_server.start(api_host, api_port)

                raiden_api.channel_open(
                    registry_address=contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY],
                    token_address=to_canonical_address(token.contract.address),
                    partner_address=to_canonical_address(TEST_PARTNER_ADDRESS),
                )
                raiden_api.set_total_channel_deposit(
                    contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY],
                    to_canonical_address(token.contract.address),
                    to_canonical_address(TEST_PARTNER_ADDRESS),
                    TEST_DEPOSIT_AMOUNT,
                )
                token_addresses = [to_checksum_address(token.contract.address)]

                success = False
                print_step('Running smoketest')
                error = run_smoketests(
                    app.raiden,
                    args['transport'],
                    token_addresses,
                    contract_addresses[CONTRACT_ENDPOINT_REGISTRY],
                    debug=debug,
                )
                if error is not None:
                    append_report('Smoketest assertion error', error)
                else:
                    success = True
            finally:
                app.stop()
                app.raiden.get()
                node = ethereum[0]
                node.send_signal(2)
                err, out = node.communicate()

                append_report('Ethereum stdout', out)
                append_report('Ethereum stderr', err)
        append_report('Raiden Node stdout', raiden_stdout.getvalue())
        if success:
            print_step(f'Smoketest successful')
        else:
            print_step(f'Smoketest had errors', error=True)
        return success

    if args['transport'] == 'udp':
        with SocketFactory('127.0.0.1', port, strategy='none') as mapped_socket:
            args['mapped_socket'] = mapped_socket
            success = _run_smoketest()
    elif args['transport'] == 'matrix':
        args['mapped_socket'] = None
        print_step('Starting Matrix transport')
        try:
            with matrix_server_starter() as server_urls:
                # Disable TLS verification so we can connect to the self signed certificate
                make_requests_insecure()
                urllib3.disable_warnings(InsecureRequestWarning)
                args['extra_config'] = {
                    'transport': {
                        'matrix': {
                            'available_servers': server_urls,
                        },
                    },
                }
                success = _run_smoketest()
        except (PermissionError, ProcessExitedWithError, FileNotFoundError):
            append_report('Matrix server start exception', traceback.format_exc())
            print_step(
                f'Error during smoketest setup, report was written to {report_file}',
                error=True,
            )
            success = False
    else:
        # Shouldn't happen
        raise RuntimeError(f"Invalid transport type '{args['transport']}'")

    if not success:
        sys.exit(1)