def setup_tps(rpc_server, config_path, privatekey, registry_address, token_address, deposit, settle_timeout): """ Creates the required contract and the fully connected Raiden network prior to running the test. Args: rpc_server (str): A string in the format '{host}:{port}' used to define the JSON-RPC end-point. config_path (str): A full/relative path to the yaml configuration file. channelmanager_address (str): The address of the channel manager contract. token_address (str): The address of the token used for testing. deposit (int): The default deposit that will be made for all test nodes. """ host, port = rpc_server.split(':') rpc_client = JSONRPCClient( host, port, privatekey, ) blockchain_service = BlockChainService( privatekey, rpc_client, GAS_LIMIT, GAS_PRICE, ) blockchain_service.default_registry.add_token(token_address) with codecs.open(config_path, encoding='utf8') as handler: config = yaml.load(handler) node_addresses = [] for node in config['nodes']: privkey = sha3('{}:{}'.format(node['host'], node['port'])) node_addresses.append(privatekey_to_address(privkey)) random_raiden_network( token_address, blockchain_service, node_addresses, deposit, settle_timeout, )
def tps_run(host, port, config, privatekey, rpc_server, registry_address, token_address, transfer_amount, parallel): # pylint: disable=too-many-locals,too-many-arguments ourprivkey, _ = hostport_to_privkeyaddr(host, port) rpc_connection = rpc_server.split(':') rpc_connection = (rpc_connection[0], int(rpc_connection[1])) with codecs.open(config, encoding='utf8') as handler: config = yaml.load(handler) config['host'] = host config['port'] = port config['privkey'] = ourprivkey rpc_connection = rpc_server.split(':') host, port = (rpc_connection[0], int(rpc_connection[1])) rpc_client = JSONRPCClient( host, port, privatekey, ) blockchain_service = BlockChainService( privatekey, rpc_client, GAS_PRICE, ) discovery = Discovery() found_ouraddress = False for node in config['nodes']: _, address = hostport_to_privkeyaddr(node['host'], node['port']) discovery.register(address, node['host'], node['port']) if host == node['host'] and str(port) == node['port']: found_ouraddress = True if not found_ouraddress: print('We are not registered in the configuration file') sys.exit(1) app = App( config, blockchain_service, discovery, ) for _ in range(parallel): gevent.spawn(random_transfer, app, token_address, transfer_amount) # wait for interrupt event = gevent.event.Event() gevent.signal(signal.SIGQUIT, event.set) gevent.signal(signal.SIGTERM, event.set) gevent.signal(signal.SIGINT, event.set) event.wait() app.stop()