def blockchain_provider(): result = setup_testchain_and_raiden( 'matrix', 'auto', lambda x: None, ) args = result['args'] # The setup of the testchain returns a TextIOWrapper but # for the tests we need a filename args['password_file'] = args['password_file'].name return args
def blockchain_provider(): result = setup_testchain_and_raiden( transport='matrix', matrix_server='auto', print_step=lambda x: None, contracts_version=None, # cli tests should work with production contracts ) args = result['args'] # The setup of the testchain returns a TextIOWrapper but # for the tests we need a filename args['password_file'] = args['password_file'].name return args
def blockchain_provider(): result = setup_testchain_and_raiden( transport='matrix', matrix_server='auto', print_step=lambda x: None, # cli tests should work with production contracts contracts_version=RED_EYES_CONTRACT_VERSION, ) args = result['args'] # The setup of the testchain returns a TextIOWrapper but # for the tests we need a filename args['password_file'] = args['password_file'].name return args
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)
def smoketest(ctx, debug, local_matrix, **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, load_smoketest_config, run_smoketests, setup_testchain_and_raiden, ) report_file = tempfile.mktemp(suffix='.log') configure_logging({'': 'DEBUG'}, log_file=report_file) 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') smoketest_config = load_smoketest_config() if not smoketest_config: append_report( 'Smoketest configuration', 'Could not load the smoketest genesis configuration file.', ) result = setup_testchain_and_raiden( smoketest_config, ctx.parent.params['transport'], ctx.parent.params['matrix_server'], print_step, ) args = result['args'] contract_addresses = result['contract_addresses'] token = result['token'] ethereum = result['ethereum'] ethereum_config = result['ethereum_config'] smoketest_config['transport'] = args['transport'] 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') # 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( contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY], to_canonical_address(token.contract.address), to_canonical_address(TEST_PARTNER_ADDRESS), None, None, ) 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, ) smoketest_config['contracts'][ 'registry_address'] = to_checksum_address( contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY], ) smoketest_config['contracts'][ 'secret_registry_address'] = to_checksum_address( contract_addresses[CONTRACT_SECRET_REGISTRY], ) smoketest_config['contracts'][ 'discovery_address'] = to_checksum_address( contract_addresses[CONTRACT_ENDPOINT_REGISTRY], ) smoketest_config['contracts']['token_address'] = to_checksum_address( token.contract.address, ) success = False try: print_step('Running smoketest') error = run_smoketests(app.raiden, smoketest_config, debug=debug) if error is not None: append_report('Smoketest assertion error', error) else: success = True finally: app.stop() ethereum.send_signal(2) err, out = ethereum.communicate() append_report('Ethereum init stdout', ethereum_config['init_log_out'].decode('utf-8')) append_report('Ethereum init stderr', ethereum_config['init_log_err'].decode('utf-8')) append_report('Ethereum stdout', out) append_report('Ethereum stderr', err) append_report('Smoketest configuration', json.dumps(smoketest_config)) if success: print_step( f'Smoketest successful, report was written to {report_file}') else: print_step( f'Smoketest had errors, report was written to {report_file}', 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' and local_matrix.lower() != 'none': args['mapped_socket'] = None print_step('Starting Matrix transport') try: with HTTPExecutor( local_matrix, url=urljoin(args['matrix_server'], '/_matrix/client/versions'), method='GET', timeout=30, shell=True, ): args['extra_config'] = { 'transport': { 'matrix': { 'discovery_room': { 'server': 'matrix.local.raiden' }, 'server_name': 'matrix.local.raiden', }, }, } success = _run_smoketest() except (PermissionError, ProcessExitedWithError): 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 elif args['transport'] == 'matrix' and local_matrix.lower() == "none": args['mapped_socket'] = None success = _run_smoketest() else: # Shouldn't happen raise RuntimeError(f"Invalid transport type '{args['transport']}'") if not success: sys.exit(1)
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)
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)
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)