signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def attr_ignore_predicate(self,fact_dict):
if '<STR_LIT:@>' in fact_dict['<STR_LIT>']:<EOL><INDENT>return True<EOL><DEDENT>if fact_dict['<STR_LIT>'] in ['<STR_LIT>','<STR_LIT:id>','<STR_LIT>']:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
The attr_ignore predicate is called for each fact that would be generated for an XML attribute. It takes a fact dictionary of the following form as input:: { 'node_id': 'N001:L000:N000:A000', 'term': 'Hashes/Hash/Simple_Hash_Value', 'attribute': 'condition', 'value': u'Equals' }...
f9160:c0:m7
def datatype_extractor(self,iobject, fact, attr_info, namespace_mapping, add_fact_kargs):
<EOL>if "<STR_LIT>" in attr_info:<EOL><INDENT>embedded_type_info = attr_info.get('<STR_LIT>',None)<EOL>if embedded_type_info:<EOL><INDENT>add_fact_kargs['<STR_LIT>'] = embedded_type_info<EOL>add_fact_kargs['<STR_LIT>'] = namespace_mapping[None]<EOL>add_fact_kargs['<STR_LIT>'] = FactDataType.REFERENCE<EOL><DEDENT>return...
The datatype extractor is called for each fact with the aim of determining the fact's datatype. The extractor function has the following signature: - Inputs: - info_object: the information object to which the fact is to be added - fact: the fact dictionary of the following form:: { 'node_id': 'N001:L000:N00...
f9160:c0:m8
def generate_accounts(seeds):
return {<EOL>seed: {<EOL>'<STR_LIT>': encode_hex(sha3(seed)),<EOL>'<STR_LIT:address>': encode_hex(privatekey_to_address(sha3(seed))),<EOL>}<EOL>for seed in seeds<EOL>}<EOL>
Create private keys and addresses for all seeds.
f9167:m0
def mk_genesis(accounts, initial_alloc=denoms.ether * <NUM_LIT>):
genesis = GENESIS_STUB.copy()<EOL>genesis['<STR_LIT>'] = encode_hex(CLUSTER_NAME)<EOL>genesis['<STR_LIT>'].update({<EOL>account: {<EOL>'<STR_LIT>': str(initial_alloc),<EOL>}<EOL>for account in accounts<EOL>})<EOL>genesis['<STR_LIT>']['<STR_LIT>'] = dict(balance=str(initial_alloc))<EOL>return genesis<EOL>
Create a genesis-block dict with allocation for all `accounts`. :param accounts: list of account addresses (hex) :param initial_alloc: the amount to allocate for the `accounts` :return: genesis dict
f9167:m1
@click.argument(<EOL>'<STR_LIT>',<EOL>nargs=-<NUM_LIT:1>,<EOL>type=str,<EOL>)<EOL>@click.argument(<EOL>'<STR_LIT>',<EOL>type=str,<EOL>)<EOL>@cli.command()<EOL>@click.pass_context<EOL>def geth_commands(ctx, geth_hosts, datadir):
pretty = ctx.obj['<STR_LIT>']<EOL>nodes = [] <EOL>for i, host in enumerate(geth_hosts):<EOL><INDENT>nodes.append(create_node_configuration(host=host, node_key_seed=i))<EOL><DEDENT>for node in nodes:<EOL><INDENT>node.pop('<STR_LIT>')<EOL>node.pop('<STR_LIT>')<EOL><DEDENT>config = {'<STR_LIT>'.format(**node): '<STR_LIT:...
This is helpful to setup a private cluster of geth nodes that won't need discovery (because they can use the content of `static_nodes` as `static-nodes.json`).
f9168:m7
def rgb_color_picker(obj, min_luminance=None, max_luminance=None):
color_value = int.from_bytes(<EOL>hashlib.md5(str(obj).encode('<STR_LIT:utf-8>')).digest(),<EOL>'<STR_LIT>',<EOL>) % <NUM_LIT><EOL>color = Color(f'<STR_LIT>')<EOL>if min_luminance and color.get_luminance() < min_luminance:<EOL><INDENT>color.set_luminance(min_luminance)<EOL><DEDENT>elif max_luminance and color.get_lumin...
Modified version of colour.RGB_color_picker
f9171:m0
def _address_rxp(self, addr):
try:<EOL><INDENT>addr = to_checksum_address(addr)<EOL>rxp = '<STR_LIT>' + pex(address_checksum_and_decode(addr)) + f'<STR_LIT>'<EOL>self._extra_keys[pex(address_checksum_and_decode(addr))] = addr.lower()<EOL>self._extra_keys[addr[<NUM_LIT:2>:].lower()] = addr.lower()<EOL><DEDENT>except ValueError:<EOL><INDENT>rxp = add...
Create a regex string for addresses, that matches several representations: - with(out) '0x' prefix - `pex` version This function takes care of maintaining additional lookup keys for substring matches. In case the given string is no address, it returns the original string.
f9172:c0:m1
def _make_regex(self):
rxp = "<STR_LIT:|>".join(<EOL>map(self._address_rxp, self.keys()),<EOL>)<EOL>self._regex = re.compile(<EOL>rxp,<EOL>re.IGNORECASE,<EOL>)<EOL>
Compile rxp with all keys concatenated.
f9172:c0:m2
def __call__(self, match):
return '<STR_LIT>'.format(self[match.group(<NUM_LIT:0>).lower()])<EOL>
Lookup for each rxp match.
f9172:c0:m6
def translate(self, text):
return self._regex.sub(self, text)<EOL>
Translate text.
f9172:c0:m7
def visit_call(self, node):
try:<EOL><INDENT>self._force_joinall_to_use_set(node)<EOL><DEDENT>except InferenceError:<EOL><INDENT>pass<EOL><DEDENT>
Called on expressions of the form `expr()`, where `expr` is a simple name e.g. `f()` or a path e.g. `v.f()`.
f9173:c0:m0
def _force_joinall_to_use_set(self, node):
for inferred_func in node.func.infer():<EOL><INDENT>if is_joinall(inferred_func):<EOL><INDENT>is_every_value_a_set = all(<EOL>inferred_first_arg.pytype() == '<STR_LIT>'<EOL>for inferred_first_arg in node.args[<NUM_LIT:0>].infer()<EOL>)<EOL>if not is_every_value_a_set:<EOL><INDENT>self.add_message(JOINALL_ID, node=node)...
This detect usages of the form: >>> from gevent import joinall >>> joinall(...) or: >>> import gevent >>> gevent.joinall(...)
f9173:c0:m1
@property<EOL><INDENT>def nodes(self) -> List[str]:<DEDENT>
if self._scenario_version == <NUM_LIT:1> and '<STR_LIT>' in self._config:<EOL><INDENT>range_config = self._config['<STR_LIT>']<EOL>try:<EOL><INDENT>start, stop = range_config['<STR_LIT>'], range_config['<STR_LIT>'] + <NUM_LIT:1><EOL><DEDENT>except KeyError:<EOL><INDENT>raise MissingNodesConfiguration(<EOL>'<STR_LIT>'<E...
Return the list of nodes configured in the scenario's yaml. Should the scenario use version 1, we check if there is a 'setting'. If so, we derive the list of nodes from this dictionary, using its 'first', 'last' and 'template' keys. Should any of these keys be missing, we throw an appro...
f9175:c0:m9
@property<EOL><INDENT>def commands(self) -> dict:<DEDENT>
return self._config.get('<STR_LIT>', {})<EOL>
Return the commands configured for the nodes.
f9175:c0:m10
@property<EOL><INDENT>def version(self) -> int:<DEDENT>
version = self._config.get('<STR_LIT:version>', <NUM_LIT:1>)<EOL>if version not in SUPPORTED_SCENARIO_VERSIONS:<EOL><INDENT>raise InvalidScenarioVersion(f'<STR_LIT>')<EOL><DEDENT>return version<EOL>
Return the scenario's version. If this is not present, we default to version 1. :raises InvalidScenarioVersion: if the supplied version is not present in :var:`SUPPORTED_SCENARIO_VERSIONS`.
f9175:c1:m4
@property<EOL><INDENT>def name(self) -> str:<DEDENT>
return self._yaml_path.stem<EOL>
Return the name of the scenario file, sans extension.
f9175:c1:m5
@property<EOL><INDENT>def settings(self):<DEDENT>
return self._config.get('<STR_LIT>', {})<EOL>
Return the 'settings' dictionary for the scenario.
f9175:c1:m6
@property<EOL><INDENT>def protocol(self) -> str:<DEDENT>
if self.nodes.mode is NodeMode.MANAGED:<EOL><INDENT>if '<STR_LIT>' in self._config:<EOL><INDENT>log.warning('<STR_LIT>')<EOL><DEDENT>return '<STR_LIT:http>'<EOL><DEDENT>return self._config.get('<STR_LIT>', '<STR_LIT:http>')<EOL>
Return the designated protocol of the scenario. If the node's mode is :attr:`NodeMode.MANAGED`, we always choose `http` and display a warning if there was a 'protocol' set explicitly in the scenario's yaml. Otherwise we simply access the 'protocol' key of the yaml, defaulting to ...
f9175:c1:m7
@property<EOL><INDENT>def timeout(self) -> int:<DEDENT>
return self.settings.get('<STR_LIT>', TIMEOUT)<EOL>
Returns the scenario's set timeout in seconds.
f9175:c1:m8
@property<EOL><INDENT>def notification_email(self) -> Union[str, None]:<DEDENT>
return self.settings.get('<STR_LIT>')<EOL>
Return the email address to which notifications are to be sent. If this isn't set, we return None.
f9175:c1:m9
@property<EOL><INDENT>def chain_name(self) -> str:<DEDENT>
return self.settings.get('<STR_LIT>', '<STR_LIT>')<EOL>
Return the name of the chain to be used for this scenario.
f9175:c1:m10
@property<EOL><INDENT>def services(self):<DEDENT>
return self.settings.get('<STR_LIT>', {})<EOL>
Return the
f9175:c1:m11
@property<EOL><INDENT>def gas_price(self) -> str:<DEDENT>
return self._config.get('<STR_LIT>', '<STR_LIT>')<EOL>
Return the configured gas price for this scenario. This defaults to 'fast'.
f9175:c1:m12
@property<EOL><INDENT>def nodes(self) -> NodesConfig:<DEDENT>
return self._nodes<EOL>
Return the configuration of nodes used in this scenario.
f9175:c1:m14
@property<EOL><INDENT>def configuration(self):<DEDENT>
try:<EOL><INDENT>return self._config['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ScenarioError(<EOL>"<STR_LIT>",<EOL>)<EOL><DEDENT>
Return the scenario's configuration. :raises ScenarioError: if no 'scenario' key is present in the yaml file.
f9175:c1:m15
@property<EOL><INDENT>def task(self) -> Tuple[str, Any]:<DEDENT>
try:<EOL><INDENT>items, = self.configuration.items()<EOL><DEDENT>except ValueError:<EOL><INDENT>raise MultipleTaskDefinitions(<EOL>'<STR_LIT>',<EOL>)<EOL><DEDENT>return items<EOL>
Return the scenario's task configuration as a tuple. :raises MultipleTaskDefinitions: if there is more than one task config under the 'scenario' key.
f9175:c1:m16
@property<EOL><INDENT>def task_config(self) -> Dict:<DEDENT>
_, root_task_config = self.task<EOL>return root_task_config<EOL>
Return the task config for this scenario.
f9175:c1:m17
@property<EOL><INDENT>def task_class(self):<DEDENT>
from scenario_player.tasks.base import get_task_class_for_type<EOL>root_task_type, _ = self.task<EOL>task_class = get_task_class_for_type(root_task_type)<EOL>return task_class<EOL>
Return the Task class type configured for the scenario.
f9175:c1:m18
def decode_event(abi: ABI, log_: Dict) -> Dict:
if isinstance(log_['<STR_LIT>'][<NUM_LIT:0>], str):<EOL><INDENT>log_['<STR_LIT>'][<NUM_LIT:0>] = decode_hex(log_['<STR_LIT>'][<NUM_LIT:0>])<EOL><DEDENT>elif isinstance(log_['<STR_LIT>'][<NUM_LIT:0>], int):<EOL><INDENT>log_['<STR_LIT>'][<NUM_LIT:0>] = decode_hex(hex(log_['<STR_LIT>'][<NUM_LIT:0>]))<EOL><DEDENT>event_id ...
Helper function to unpack event data using a provided ABI Args: abi: The ABI of the contract, not the ABI of the event log_: The raw event data Returns: The decoded event
f9180:m0
def query_blockchain_events(<EOL>web3: Web3,<EOL>contract_manager: ContractManager,<EOL>contract_address: Address,<EOL>contract_name: str,<EOL>topics: List,<EOL>from_block: BlockNumber,<EOL>to_block: BlockNumber,<EOL>) -> List[Dict]:
filter_params = {<EOL>'<STR_LIT>': from_block,<EOL>'<STR_LIT>': to_block,<EOL>'<STR_LIT:address>': to_checksum_address(contract_address),<EOL>'<STR_LIT>': topics,<EOL>}<EOL>events = web3.eth.getLogs(filter_params)<EOL>contract_abi = contract_manager.get_contract_abi(contract_name)<EOL>return [<EOL>decode_event(<EOL>abi...
Returns events emmitted by a contract for a given event name, within a certain range. Args: web3: A Web3 instance contract_manager: A contract manager contract_address: The address of the contract to be filtered, can be `None` contract_name: The name of the contract topics: ...
f9180:m1
def get_or_deploy_token(runner) -> Tuple[ContractProxy, int]:
token_contract = runner.contract_manager.get_contract(CONTRACT_CUSTOM_TOKEN)<EOL>token_config = runner.scenario.get('<STR_LIT>', {})<EOL>if not token_config:<EOL><INDENT>token_config = {}<EOL><DEDENT>address = token_config.get('<STR_LIT:address>')<EOL>block = token_config.get('<STR_LIT>', <NUM_LIT:0>)<EOL>reuse = token...
Deploy or reuse
f9189:m1
def get_udc_and_token(runner) -> Tuple[Optional[ContractProxy], Optional[ContractProxy]]:
from scenario_player.runner import ScenarioRunner<EOL>assert isinstance(runner, ScenarioRunner)<EOL>udc_config = runner.scenario.services.get('<STR_LIT>', {})<EOL>if not udc_config.get('<STR_LIT>', False):<EOL><INDENT>return None, None<EOL><DEDENT>udc_address = udc_config.get('<STR_LIT:address>')<EOL>if udc_address is ...
Return contract proxies for the UserDepositContract and associated token
f9189:m2
def mint_token_if_balance_low(<EOL>token_contract: ContractProxy,<EOL>target_address: str,<EOL>min_balance: int,<EOL>fund_amount: int,<EOL>gas_limit: int,<EOL>mint_msg: str,<EOL>no_action_msg: str = None,<EOL>) -> Optional[TransactionHash]:
balance = token_contract.contract.functions.balanceOf(target_address).call()<EOL>if balance < min_balance:<EOL><INDENT>mint_amount = fund_amount - balance<EOL>log.debug(mint_msg, address=target_address, amount=mint_amount)<EOL>return token_contract.transact('<STR_LIT>', gas_limit, mint_amount, target_address)<EOL><DEDE...
Check token balance and mint if below minimum
f9189:m3
def start(self, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
if self.pre_start_check():<EOL><INDENT>raise AlreadyRunning(self)<EOL><DEDENT>if self.process is None:<EOL><INDENT>command = self.command<EOL>if not self._shell:<EOL><INDENT>command = self.command_parts<EOL><DEDENT>env = os.environ.copy()<EOL>env[ENV_UUID] = self._uuid<EOL>popen_kwargs = {<EOL>'<STR_LIT>': self._shell,...
Merged copy paste from the inheritance chain with modified stdout/err behaviour
f9189:c5:m0
def stop(self, sig=None, timeout=<NUM_LIT:10>):
if self.process is None:<EOL><INDENT>return self<EOL><DEDENT>if sig is None:<EOL><INDENT>sig = self._sig_stop<EOL><DEDENT>try:<EOL><INDENT>os.killpg(self.process.pid, sig)<EOL><DEDENT>except OSError as err:<EOL><INDENT>if err.errno in IGNORED_ERROR_CODES:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT...
Copy paste job from `SimpleExecutor.stop()` to add the `timeout` parameter.
f9189:c5:m1
def determine_run_number(self) -> int:
run_number = <NUM_LIT:0><EOL>run_number_file = self.data_path.joinpath('<STR_LIT>')<EOL>if run_number_file.exists():<EOL><INDENT>run_number = int(run_number_file.read_text()) + <NUM_LIT:1><EOL><DEDENT>run_number_file.write_text(str(run_number))<EOL>log.info('<STR_LIT>', run_number=run_number)<EOL>return run_number<EOL>
Determine the current run number. We check for a run number file, and use any number that is logged there after incrementing it.
f9190:c0:m1
def select_chain(self, chain_urls: Dict[str, List[str]]) -> Tuple[str, List[str]]:
chain_name = self.scenario.chain_name<EOL>if chain_name in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>chain_name = random.choice(list(chain_urls.keys()))<EOL><DEDENT>log.info('<STR_LIT>', chain=chain_name)<EOL>try:<EOL><INDENT>return chain_name, chain_urls[chain_name]<EOL><DEDENT>except KeyError:<EOL><INDENT>...
Select a chain and return its name and RPC URL. If the currently loaded scenario's designated chain is set to 'any', we randomly select a chain from the given `chain_urls`. Otherwise, we will return `ScenarioRunner.scenario.chain_name` and whatever value may be associated with this key ...
f9190:c0:m2
def _check_workflows_align(config):
jobs_default = config['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>jobs_nightly = config['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>if jobs_default == jobs_nightly[:len(jobs_default)]:<EOL><INDENT>return True, []<EOL><DEDENT>job_diff = unified_diff(<EOL>[f"<STR_LIT>" for line in jobs_default],<EOL>[f"<STR_LIT>" for line ...
Ensure that the common shared jobs in the `raiden-default` and `nightly` workflows are identical.
f9205:m3
def find_max_pending_transfers(gas_limit):
tester = ContractTester(generate_keys=<NUM_LIT:2>)<EOL>tester.deploy_contract('<STR_LIT>')<EOL>tester.deploy_contract(<EOL>'<STR_LIT>',<EOL>_initialAmount=<NUM_LIT>,<EOL>_decimalUnits=<NUM_LIT:3>,<EOL>_tokenName='<STR_LIT>',<EOL>_tokenSymbol='<STR_LIT>',<EOL>)<EOL>tester.deploy_contract(<EOL>'<STR_LIT>',<EOL>_token_add...
Measure gas consumption of TokenNetwork.unlock() depending on number of pending transfers and find the maximum number of pending transfers so gas_limit is not exceeded.
f9206:m0
def wait_for_newchannel(<EOL>raiden: '<STR_LIT>',<EOL>payment_network_id: PaymentNetworkID,<EOL>token_address: TokenAddress,<EOL>partner_address: Address,<EOL>retry_timeout: float,<EOL>) -> None:
channel_state = views.get_channelstate_for(<EOL>views.state_from_raiden(raiden),<EOL>payment_network_id,<EOL>token_address,<EOL>partner_address,<EOL>)<EOL>while channel_state is None:<EOL><INDENT>gevent.sleep(retry_timeout)<EOL>channel_state = views.get_channelstate_for(<EOL>views.state_from_raiden(raiden),<EOL>payment...
Wait until the channel with partner_address is registered. Note: This does not time out, use gevent.Timeout.
f9212:m1
def wait_for_participant_newbalance(<EOL>raiden: '<STR_LIT>',<EOL>payment_network_id: PaymentNetworkID,<EOL>token_address: TokenAddress,<EOL>partner_address: Address,<EOL>target_address: Address,<EOL>target_balance: TokenAmount,<EOL>retry_timeout: float,<EOL>) -> None:
if target_address == raiden.address:<EOL><INDENT>balance = lambda channel_state: channel_state.our_state.contract_balance<EOL><DEDENT>elif target_address == partner_address:<EOL><INDENT>balance = lambda channel_state: channel_state.partner_state.contract_balance<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>...
Wait until a given channels balance exceeds the target balance. Note: This does not time out, use gevent.Timeout.
f9212:m2
def wait_for_payment_balance(<EOL>raiden: '<STR_LIT>',<EOL>payment_network_id: PaymentNetworkID,<EOL>token_address: TokenAddress,<EOL>partner_address: Address,<EOL>target_address: Address,<EOL>target_balance: TokenAmount,<EOL>retry_timeout: float,<EOL>) -> None:
def get_balance(end_state):<EOL><INDENT>if end_state.balance_proof:<EOL><INDENT>return end_state.balance_proof.transferred_amount<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT><DEDENT>if target_address == raiden.address:<EOL><INDENT>balance = lambda channel_state: get_balance(channel_state.partner_state)...
Wait until a given channel's balance exceeds the target balance. Note: This does not time out, use gevent.Timeout.
f9212:m3
def wait_for_channel_in_states(<EOL>raiden: '<STR_LIT>',<EOL>payment_network_id: PaymentNetworkID,<EOL>token_address: TokenAddress,<EOL>channel_ids: List[ChannelID],<EOL>retry_timeout: float,<EOL>target_states: Sequence[str],<EOL>) -> None:
chain_state = views.state_from_raiden(raiden)<EOL>token_network = views.get_token_network_by_token_address(<EOL>chain_state=chain_state,<EOL>payment_network_id=payment_network_id,<EOL>token_address=token_address,<EOL>)<EOL>if token_network is None:<EOL><INDENT>raise ValueError(<EOL>f'<STR_LIT>',<EOL>)<EOL><DEDENT>token...
Wait until all channels are in `target_states`. Raises: ValueError: If the token_address is not registered in the payment_network. Note: This does not time out, use gevent.Timeout.
f9212:m4
def wait_for_close(<EOL>raiden: '<STR_LIT>',<EOL>payment_network_id: PaymentNetworkID,<EOL>token_address: TokenAddress,<EOL>channel_ids: List[ChannelID],<EOL>retry_timeout: float,<EOL>) -> None:
return wait_for_channel_in_states(<EOL>raiden=raiden,<EOL>payment_network_id=payment_network_id,<EOL>token_address=token_address,<EOL>channel_ids=channel_ids,<EOL>retry_timeout=retry_timeout,<EOL>target_states=CHANNEL_AFTER_CLOSE_STATES,<EOL>)<EOL>
Wait until all channels are closed. Note: This does not time out, use gevent.Timeout.
f9212:m5
def wait_for_settle(<EOL>raiden: '<STR_LIT>',<EOL>payment_network_id: PaymentNetworkID,<EOL>token_address: TokenAddress,<EOL>channel_ids: List[ChannelID],<EOL>retry_timeout: float,<EOL>) -> None:
return wait_for_channel_in_states(<EOL>raiden=raiden,<EOL>payment_network_id=payment_network_id,<EOL>token_address=token_address,<EOL>channel_ids=channel_ids,<EOL>retry_timeout=retry_timeout,<EOL>target_states=(CHANNEL_STATE_SETTLED,),<EOL>)<EOL>
Wait until all channels are settled. Note: This does not time out, use gevent.Timeout.
f9212:m7
def wait_for_settle_all_channels(<EOL>raiden: '<STR_LIT>',<EOL>retry_timeout: float,<EOL>) -> None:
chain_state = views.state_from_raiden(raiden)<EOL>id_paymentnetworkstate = chain_state.identifiers_to_paymentnetworks.items()<EOL>for payment_network_id, payment_network_state in id_paymentnetworkstate:<EOL><INDENT>id_tokennetworkstate = payment_network_state.tokenidentifiers_to_tokennetworks.items()<EOL>for token_netw...
Wait until all channels are settled. Note: This does not time out, use gevent.Timeout.
f9212:m8
def wait_for_healthy(<EOL>raiden: '<STR_LIT>',<EOL>node_address: Address,<EOL>retry_timeout: float,<EOL>) -> None:
network_statuses = views.get_networkstatuses(<EOL>views.state_from_raiden(raiden),<EOL>)<EOL>while network_statuses.get(node_address) != NODE_NETWORK_REACHABLE:<EOL><INDENT>gevent.sleep(retry_timeout)<EOL>network_statuses = views.get_networkstatuses(<EOL>views.state_from_raiden(raiden),<EOL>)<EOL><DEDENT>
Wait until `node_address` becomes healthy. Note: This does not time out, use gevent.Timeout.
f9212:m9
def wait_for_transfer_success(<EOL>raiden: '<STR_LIT>',<EOL>payment_identifier: PaymentID,<EOL>amount: PaymentAmount,<EOL>retry_timeout: float,<EOL>) -> None:
found = False<EOL>while not found:<EOL><INDENT>state_events = raiden.wal.storage.get_events()<EOL>for event in state_events:<EOL><INDENT>found = (<EOL>isinstance(event, EventPaymentReceivedSuccess) and<EOL>event.identifier == payment_identifier and<EOL>event.amount == amount<EOL>)<EOL>if found:<EOL><INDENT>break<EOL><D...
Wait until a transfer with a specific identifier and amount is seen in the WAL. Note: This does not time out, use gevent.Timeout.
f9212:m10
def handle_tokennetwork_new(raiden: '<STR_LIT>', event: Event):
data = event.event_data<EOL>args = data['<STR_LIT:args>']<EOL>block_number = data['<STR_LIT>']<EOL>token_network_address = args['<STR_LIT>']<EOL>token_address = typing.TokenAddress(args['<STR_LIT>'])<EOL>block_hash = data['<STR_LIT>']<EOL>token_network_proxy = raiden.chain.token_network(token_network_address)<EOL>raide...
Handles a `TokenNetworkCreated` event.
f9213:m0
def assert_partner_state(end_state, partner_state, model):
assert end_state.address == model.participant_address<EOL>assert channel.get_amount_locked(end_state) == model.amount_locked<EOL>assert channel.get_balance(end_state, partner_state) == model.balance<EOL>assert channel.get_distributable(end_state, partner_state) == model.distributable<EOL>assert channel.get_next_nonce(e...
Checks that the stored data for both ends correspond to the model.
f9226:m0
def create_channel_from_models(our_model, partner_model):
channel_state = create(NettingChannelStateProperties(<EOL>reveal_timeout=<NUM_LIT:10>,<EOL>settle_timeout=<NUM_LIT:100>,<EOL>our_state=NettingChannelEndStateProperties(<EOL>address=our_model.participant_address,<EOL>balance=our_model.balance,<EOL>merkletree_leaves=our_model.merkletree_leaves,<EOL>),<EOL>partner_state=N...
Utility to instantiate state objects used throughout the tests.
f9226:m2
def trigger_presence_callback(self, user_states: Dict[str, UserPresence]):
if self._presence_callback is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>for user_id, presence in user_states.items():<EOL><INDENT>event = {<EOL>'<STR_LIT>': user_id,<EOL>'<STR_LIT:type>': '<STR_LIT>',<EOL>'<STR_LIT:content>': {<EOL>'<STR_LIT>': presence.value,<EOL>},<EOL>}<EOL>self._presence_callbac...
Trigger the registered presence listener with the given user presence
f9259:c1:m2
def get_list_of_block_numbers(item):
if isinstance(item, list):<EOL><INDENT>return [element['<STR_LIT>'] for element in item]<EOL><DEDENT>if isinstance(item, dict):<EOL><INDENT>block_number = item['<STR_LIT>']<EOL>return [block_number]<EOL><DEDENT>return list()<EOL>
Creates a list of block numbers of the given list/single event
f9268:m4
def wait_for_transaction(<EOL>receiver,<EOL>registry_address,<EOL>token_address,<EOL>sender_address,<EOL>):
while True:<EOL><INDENT>receiver_channel = RaidenAPI(receiver).get_channel_list(<EOL>registry_address=registry_address,<EOL>token_address=token_address,<EOL>partner_address=sender_address,<EOL>)<EOL>transaction_received = (<EOL>len(receiver_channel) == <NUM_LIT:1> and<EOL>receiver_channel[<NUM_LIT:0>].partner_state.bal...
Wait until a first transaction in a channel is received
f9292:m0
def saturated_count(connection_managers, registry_address, token_address):
return [<EOL>is_manager_saturated(manager, registry_address, token_address)<EOL>for manager in connection_managers<EOL>].count(True)<EOL>
Return count of nodes with count of open channels exceeding initial channel target
f9292:m3
def restart_network_and_apiservers(raiden_network, api_servers, port_generator, retry_timeout):
for rest_api in api_servers:<EOL><INDENT>rest_api.stop()<EOL><DEDENT>new_network = restart_network(raiden_network, retry_timeout)<EOL>new_servers = start_apiserver_for_network(new_network, port_generator)<EOL>return (new_network, new_servers)<EOL>
Stop an app and start it back
f9293:m6
def stress_send_serial_transfers(rest_apis, token_address, identifier_generator, deposit):
pairs = list(zip(rest_apis, rest_apis[<NUM_LIT:1>:] + [rest_apis[<NUM_LIT:0>]]))<EOL>for server_from, server_to in pairs:<EOL><INDENT>sequential_transfers(<EOL>server_from=server_from,<EOL>server_to=server_to,<EOL>number_of_transfers=deposit,<EOL>token_address=token_address,<EOL>identifier_generator=identifier_generato...
Send `deposit` transfers of value `1` one at a time, without changing the initial capacity.
f9293:m10
def stress_send_parallel_transfers(rest_apis, token_address, identifier_generator, deposit):
pairs = list(zip(rest_apis, rest_apis[<NUM_LIT:1>:] + [rest_apis[<NUM_LIT:0>]]))<EOL>gevent.wait([<EOL>gevent.spawn(<EOL>sequential_transfers,<EOL>server_from=server_from,<EOL>server_to=server_to,<EOL>number_of_transfers=deposit,<EOL>token_address=token_address,<EOL>identifier_generator=identifier_generator,<EOL>)<EOL>...
Send `deposit` transfers in parallel, without changing the initial capacity.
f9293:m11
def stress_send_and_receive_parallel_transfers(<EOL>rest_apis,<EOL>token_address,<EOL>identifier_generator,<EOL>deposit,<EOL>):
pairs = list(zip(rest_apis, rest_apis[<NUM_LIT:1>:] + [rest_apis[<NUM_LIT:0>]]))<EOL>foward_transfers = [<EOL>gevent.spawn(<EOL>sequential_transfers,<EOL>server_from=server_from,<EOL>server_to=server_to,<EOL>number_of_transfers=deposit,<EOL>token_address=token_address,<EOL>identifier_generator=identifier_generator,<EOL...
Send transfers of value one in parallel
f9293:m12
def timeout(blockchain_type: str):
return <NUM_LIT> if blockchain_type == '<STR_LIT>' else <NUM_LIT:30><EOL>
As parity nodes are slower, we need to set a longer timeout when waiting for onchain events to complete.
f9306:m0
def sign_and_inject(message: Message, signer: Signer, app: App) -> None:
message.sign(signer)<EOL>MessageHandler().on_message(app.raiden, message)<EOL>
Sign the message with key and inject it directly in the app transport layer.
f9312:m0
def transfer(<EOL>initiator_app: App,<EOL>target_app: App,<EOL>token_address: TokenAddress,<EOL>amount: PaymentAmount,<EOL>identifier: PaymentID,<EOL>fee: FeeAmount = <NUM_LIT:0>,<EOL>timeout: float = <NUM_LIT:10>,<EOL>) -> None:
assert identifier is not None, '<STR_LIT>'<EOL>assert isinstance(target_app.raiden.message_handler, WaitForMessage)<EOL>wait_for_unlock = target_app.raiden.message_handler.wait_for_message(<EOL>Unlock,<EOL>{'<STR_LIT>': identifier},<EOL>)<EOL>payment_network_identifier = initiator_app.raiden.default_registry.address<EO...
Nice to read shortcut to make successful LockedTransfer. Note: Only the initiator and target are synched.
f9312:m2
def transfer_and_assert_path(<EOL>path: List[App],<EOL>token_address: TokenAddress,<EOL>amount: PaymentAmount,<EOL>identifier: PaymentID,<EOL>fee: FeeAmount = <NUM_LIT:0>,<EOL>timeout: float = <NUM_LIT:10>,<EOL>) -> None:
assert identifier is not None, '<STR_LIT>'<EOL>secret = random_secret()<EOL>first_app = path[<NUM_LIT:0>]<EOL>payment_network_identifier = first_app.raiden.default_registry.address<EOL>token_network_address = views.get_token_network_identifier_by_token_address(<EOL>chain_state=views.state_from_app(first_app),<EOL>payme...
Nice to read shortcut to make successful LockedTransfer. Note: This utility *does not enforce the path*, however it does check the provided path is used in totality. It's the responsability of the caller to ensure the path will be used. All nodes in `path` are synched.
f9312:m3
def assert_synced_channel_state(<EOL>token_network_identifier: TokenNetworkID,<EOL>app0: App,<EOL>balance0: Balance,<EOL>pending_locks0: List[HashTimeLockState],<EOL>app1: App,<EOL>balance1: Balance,<EOL>pending_locks1: List[HashTimeLockState],<EOL>) -> None:
<EOL>channel0 = get_channelstate(app0, app1, token_network_identifier)<EOL>channel1 = get_channelstate(app1, app0, token_network_identifier)<EOL>assert channel0.our_state.contract_balance == channel1.partner_state.contract_balance<EOL>assert channel0.partner_state.contract_balance == channel1.our_state.contract_balance...
Assert the values of two synced channels. Note: This assert does not work for an intermediate state, where one message hasn't been delivered yet or has been completely lost.
f9312:m4
def wait_assert(func: Callable, *args, **kwargs) -> None:
while True:<EOL><INDENT>try:<EOL><INDENT>func(*args, **kwargs)<EOL><DEDENT>except AssertionError as e:<EOL><INDENT>try:<EOL><INDENT>gevent.sleep(<NUM_LIT:0.5>)<EOL><DEDENT>except gevent.Timeout:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
Utility to re-run `func` if it raises an assert. Return once `func` doesn't hit a failed assert anymore. This will loop forever unless a gevent.Timeout is used.
f9312:m5
def assert_mirror(original: NettingChannelState, mirror: NettingChannelState) -> None:
original_locked_amount = channel.get_amount_locked(original.our_state)<EOL>mirror_locked_amount = channel.get_amount_locked(mirror.partner_state)<EOL>assert original_locked_amount == mirror_locked_amount<EOL>balance0 = channel.get_balance(original.our_state, original.partner_state)<EOL>balance1 = channel.get_balance(mi...
Assert that `mirror` has a correct `partner_state` to represent `original`.
f9312:m6
def assert_locked(<EOL>from_channel: NettingChannelState,<EOL>pending_locks: List[HashTimeLockState],<EOL>) -> None:
<EOL>if pending_locks:<EOL><INDENT>leaves = [sha3(lock.encoded) for lock in pending_locks]<EOL>layers = compute_layers(leaves)<EOL>tree = MerkleTreeState(layers)<EOL><DEDENT>else:<EOL><INDENT>tree = make_empty_merkle_tree()<EOL><DEDENT>assert from_channel.our_state.merkletree == tree<EOL>for lock in pending_locks:<EOL>...
Assert the locks created from `from_channel`.
f9312:m7
def assert_balance(<EOL>from_channel: NettingChannelState,<EOL>balance: Balance,<EOL>locked: LockedAmount,<EOL>) -> None:
assert balance >= <NUM_LIT:0><EOL>assert locked >= <NUM_LIT:0><EOL>distributable = balance - locked<EOL>channel_distributable = channel.get_distributable(<EOL>from_channel.our_state,<EOL>from_channel.partner_state,<EOL>)<EOL>channel_balance = channel.get_balance(from_channel.our_state, from_channel.partner_state)<EOL>c...
Assert the from_channel overall token values.
f9312:m8
def make_mediated_transfer(<EOL>from_channel: NettingChannelState,<EOL>partner_channel: NettingChannelState,<EOL>initiator: InitiatorAddress,<EOL>target: TargetAddress,<EOL>lock: HashTimeLockState,<EOL>pkey: bytes,<EOL>secret: Optional[Secret] = None,<EOL>) -> LockedTransfer:
payment_identifier = channel.get_next_nonce(from_channel.our_state)<EOL>message_identifier = random.randint(<NUM_LIT:0>, UINT64_MAX)<EOL>lockedtransfer = channel.send_lockedtransfer(<EOL>from_channel,<EOL>initiator,<EOL>target,<EOL>lock.amount,<EOL>message_identifier,<EOL>payment_identifier,<EOL>lock.expiration,<EOL>lo...
Helper to create and register a mediated transfer from `from_channel` to `partner_channel`.
f9312:m9
def geth_to_cmd(<EOL>node: Dict,<EOL>datadir: str,<EOL>chain_id: int,<EOL>verbosity: str,<EOL>) -> List[str]:
node_config = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT:port>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT:password>',<EOL>]<EOL>cmd = ['<STR_LIT>']<EOL>for config in node_config:<EOL><INDENT>if config in node:<EOL><INDENT>value = node[config]<EOL>cmd.extend([f'<STR_LIT>', str(value)])<EOL...
Transform a node configuration into a cmd-args list for `subprocess.Popen`. Args: node: a node configuration datadir: the node's datadir verbosity: verbosity one of {'error', 'warn', 'info', 'debug'} Return: cmd-args list
f9313:m2
def geth_create_account(datadir: str, privkey: bytes):
keyfile_path = os.path.join(datadir, '<STR_LIT>')<EOL>with open(keyfile_path, '<STR_LIT:wb>') as handler:<EOL><INDENT>handler.write(<EOL>remove_0x_prefix(encode_hex(privkey)).encode(),<EOL>)<EOL><DEDENT>create = subprocess.Popen(<EOL>['<STR_LIT>', '<STR_LIT>', datadir, '<STR_LIT>', '<STR_LIT>', keyfile_path],<EOL>stdin...
Create an account in `datadir` -- since we're not interested in the rewards, we don't care about the created address. Args: datadir: the datadir in which the account is created privkey: the private key for the account
f9313:m4
def geth_generate_poa_genesis(<EOL>genesis_path: str,<EOL>genesis_description: GenesisDescription,<EOL>seal_account: bytes,<EOL>) -> None:
alloc = {<EOL>to_normalized_address(address): {<EOL>'<STR_LIT>': DEFAULT_BALANCE_BIN,<EOL>}<EOL>for address in genesis_description.prefunded_accounts<EOL>}<EOL>seal_address_normalized = remove_0x_prefix(<EOL>to_normalized_address(seal_account),<EOL>)<EOL>extra_data = geth_clique_extradata(<EOL>genesis_description.rando...
Writes a bare genesis to `genesis_path`.
f9313:m6
def geth_init_datadir(datadir: str, genesis_path: str):
try:<EOL><INDENT>args = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>datadir,<EOL>'<STR_LIT>',<EOL>genesis_path,<EOL>]<EOL>subprocess.check_output(args, stderr=subprocess.STDOUT)<EOL><DEDENT>except subprocess.CalledProcessError as e:<EOL><INDENT>msg = '<STR_LIT>'.format(<EOL>e.returncode,<EOL>e.output,<EOL>)<EOL>raise Value...
Initialize a clients datadir with our custom genesis block. Args: datadir: the datadir in which the blockchain is initialized.
f9313:m7
def eth_check_balance(web3: Web3, accounts_addresses: List[bytes], retries: int = <NUM_LIT:10>) -> None:
addresses = {to_checksum_address(account) for account in accounts_addresses}<EOL>for _ in range(retries):<EOL><INDENT>for address in addresses.copy():<EOL><INDENT>if web3.eth.getBalance(address, '<STR_LIT>') > <NUM_LIT:0>:<EOL><INDENT>addresses.remove(address)<EOL><DEDENT><DEDENT>gevent.sleep(<NUM_LIT:1>)<EOL><DEDENT>i...
Wait until the given addresses have a balance. Raises a ValueError if any of the addresses still have no balance after ``retries``.
f9313:m10
@contextmanager<EOL>def run_private_blockchain(<EOL>web3: Web3,<EOL>eth_nodes: List[EthNodeDescription],<EOL>base_datadir: str,<EOL>log_dir: str,<EOL>verbosity: str,<EOL>genesis_description: GenesisDescription,<EOL>):
<EOL>nodes_configuration = []<EOL>for node in eth_nodes:<EOL><INDENT>config = eth_node_config(<EOL>node.private_key,<EOL>node.p2p_port,<EOL>node.rpc_port,<EOL>**node.extra_config,<EOL>)<EOL>if node.miner:<EOL><INDENT>config['<STR_LIT>'] = to_checksum_address(config['<STR_LIT:address>'])<EOL>config['<STR_LIT>'] = True<E...
Starts a private network with private_keys accounts funded. Args: web3: A Web3 instance used to check when the private chain is running. accounts_to_fund: Accounts that will start with funds in the private chain. eth_nodes: A list of geth node description, containing...
f9313:m18
def burn_eth(raiden_service, amount_to_leave=<NUM_LIT:0>):
address = to_checksum_address(raiden_service.address)<EOL>client = raiden_service.chain.client<EOL>web3 = client.web3<EOL>gas_price = web3.eth.gasPrice<EOL>value = web3.eth.getBalance(address) - gas_price * (<NUM_LIT> + amount_to_leave)<EOL>transaction_hash = client.send_transaction(<EOL>to=HOP1,<EOL>value=value,<EOL>s...
Burns all the ETH on the account of the given raiden service
f9314:m0
@singledispatch<EOL>def create(properties: Any, defaults: Optional[Properties] = None) -> Any:
if isinstance(properties, Properties):<EOL><INDENT>return properties.TARGET_TYPE(**_properties_to_kwargs(properties, defaults))<EOL><DEDENT>return properties<EOL>
Create objects from their associated property class. E. g. a NettingChannelState from NettingChannelStateProperties. For any field in properties set to EMPTY a default will be used. The default values can be changed by giving another object of the same property type as the defaults argument.
f9315:m31
def create_network(<EOL>token_network_state: TokenNetworkState,<EOL>our_address: typing.Address,<EOL>routes: List[RouteProperties],<EOL>block_number: typing.BlockNumber,<EOL>block_hash: typing.BlockHash = None,<EOL>) -> Tuple[Any, List[NettingChannelState]]:
block_hash = block_hash or make_block_hash()<EOL>state = token_network_state<EOL>channels = list()<EOL>for count, route in enumerate(routes, <NUM_LIT:1>):<EOL><INDENT>if route.address1 == our_address:<EOL><INDENT>channel = route_properties_to_channel(route)<EOL>state_change = ContractReceiveChannelNew(<EOL>transaction_...
Creates a network from route properties. If the address in the route is our_address, create a channel also. Returns a list of created channels and the new state.
f9315:m45
def deploy_tokens_and_fund_accounts(<EOL>token_amount: int,<EOL>number_of_tokens: int,<EOL>deploy_service: BlockChainService,<EOL>participants: typing.List[typing.Address],<EOL>contract_manager: ContractManager,<EOL>) -> typing.List[typing.TokenAddress]:
result = list()<EOL>for _ in range(number_of_tokens):<EOL><INDENT>token_address = deploy_contract_web3(<EOL>CONTRACT_HUMAN_STANDARD_TOKEN,<EOL>deploy_service.client,<EOL>contract_manager=contract_manager,<EOL>constructor_arguments=(<EOL>token_amount,<EOL><NUM_LIT:2>,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>),<EOL>)<EOL>r...
Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and distributed among `blockchain_services`. Optionally the instances will be registered with the raiden registry. Args: token_amount (int): number of units that will be created per token number_of_tokens (int): numb...
f9319:m1
def make_requests_insecure():
<EOL>requests.Session.verify = property(lambda self: False, lambda self, val: None)<EOL>
Prevent `requests` from performing TLS verification. **THIS MUST ONLY BE USED FOR TESTING PURPOSES!**
f9320:m0
def all_combinations(values):
all_generators = (<EOL>combinations(values, r)<EOL>for r in range(<NUM_LIT:1>, len(values))<EOL>)<EOL>flat = chain.from_iterable(all_generators)<EOL>return flat<EOL>
Returns all possible combinations, from length 1 up to full-length of values.
f9322:m2
def fixture_all_combinations(invalid_values):
<EOL>invalid_values_items = list(invalid_values.items())<EOL>all_invalid_values = all_combinations(invalid_values_items)<EOL>for invalid_combinations in all_invalid_values:<EOL><INDENT>keys_values = (<EOL>product((key,), values)<EOL>for key, values in invalid_combinations<EOL>)<EOL>invalid_instances = product(*keys_val...
Generate all combinations for testing invalid values. `pytest.mark.parametrize` will generate the combination of the full-length values, this is not sufficient for an exhaustive failing test with default values, example:: @pytest.mark.parametrize('x', [0, 1]) @pytest.mark.parametrize('y', ...
f9322:m3
def payment_channel_open_and_deposit(app0, app1, token_address, deposit, settle_timeout):
assert token_address<EOL>token_network_address = app0.raiden.default_registry.get_token_network(token_address)<EOL>token_network_proxy = app0.raiden.chain.token_network(token_network_address)<EOL>channel_identifier = token_network_proxy.new_netting_channel(<EOL>partner=app1.raiden.address,<EOL>settle_timeout=settle_tim...
Open a new channel with app0 and app1 as participants
f9323:m1
def network_with_minimum_channels(apps, channels_per_node):
<EOL>if channels_per_node > len(apps):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(apps) == <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>unconnected_apps = dict()<EOL>channel_count = dict()<EOL>for curr_app in apps:<EOL><INDENT>all_apps = list(apps)<EOL>all_apps.remove(curr_app)<E...
Return the channels that should be created so that each app has at least `channels_per_node` with the other apps. Yields a two-tuple (app1, app2) that must be connected to respect `channels_per_node`. Any preexisting channels will be ignored, so the nodes might end up with more channels open than `chan...
f9323:m3
def create_sequential_channels(raiden_apps, channels_per_node):
num_nodes = len(raiden_apps)<EOL>if num_nodes < <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if channels_per_node not in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>, CHAIN):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if channels_per_node == <NUM_LIT:0>:<EOL><INDENT>app_channels = list()<EOL>...
Create a fully connected network with `num_nodes`, the nodes are connect sequentially. Returns: A list of apps of size `num_nodes`, with the property that every sequential pair in the list has an open channel with `deposit` for each participant.
f9323:m5
def create_apps(<EOL>chain_id,<EOL>contracts_path,<EOL>blockchain_services,<EOL>endpoint_discovery_services,<EOL>token_network_registry_address,<EOL>secret_registry_address,<EOL>service_registry_address,<EOL>user_deposit_address,<EOL>raiden_udp_ports,<EOL>reveal_timeout,<EOL>settle_timeout,<EOL>database_paths,<EOL>retr...
<EOL>services = zip(blockchain_services, endpoint_discovery_services, raiden_udp_ports)<EOL>apps = []<EOL>for idx, (blockchain, discovery, port) in enumerate(services):<EOL><INDENT>address = blockchain.client.address<EOL>host = '<STR_LIT:127.0.0.1>'<EOL>config = {<EOL>'<STR_LIT>': chain_id,<EOL>'<STR_LIT>': environment...
Create the apps.
f9323:m6
def parallel_start_apps(raiden_apps):
start_tasks = set()<EOL>for app in raiden_apps:<EOL><INDENT>greenlet = gevent.spawn(app.raiden.start)<EOL>greenlet.name = f'<STR_LIT>'<EOL>start_tasks.add(greenlet)<EOL><DEDENT>gevent.joinall(start_tasks, raise_error=True)<EOL>
Start all the raiden apps in parallel.
f9323:m7
def wait_for_alarm_start(raiden_apps, retry_timeout=DEFAULT_RETRY_TIMEOUT):
apps = list(raiden_apps)<EOL>while apps:<EOL><INDENT>app = apps[-<NUM_LIT:1>]<EOL>if app.raiden.alarm.known_block_number is None:<EOL><INDENT>gevent.sleep(retry_timeout)<EOL><DEDENT>else:<EOL><INDENT>apps.pop()<EOL><DEDENT><DEDENT>
Wait until all Alarm tasks start & set up the last_block
f9323:m9
def wait_for_usable_channel(<EOL>app0,<EOL>app1,<EOL>registry_address,<EOL>token_address,<EOL>our_deposit,<EOL>partner_deposit,<EOL>retry_timeout=DEFAULT_RETRY_TIMEOUT,<EOL>):
waiting.wait_for_newchannel(<EOL>app0.raiden,<EOL>registry_address,<EOL>token_address,<EOL>app1.raiden.address,<EOL>retry_timeout,<EOL>)<EOL>waiting.wait_for_participant_newbalance(<EOL>app0.raiden,<EOL>registry_address,<EOL>token_address,<EOL>app1.raiden.address,<EOL>app0.raiden.address,<EOL>our_deposit,<EOL>retry_tim...
Wait until the channel from app0 to app1 is usable. The channel and the deposits are registered, and the partner network state is reachable.
f9323:m10
def wait_for_channels(<EOL>app_channels,<EOL>registry_address,<EOL>token_addresses,<EOL>deposit,<EOL>retry_timeout=DEFAULT_RETRY_TIMEOUT,<EOL>):
for app0, app1 in app_channels:<EOL><INDENT>for token_address in token_addresses:<EOL><INDENT>wait_for_usable_channel(<EOL>app0,<EOL>app1,<EOL>registry_address,<EOL>token_address,<EOL>deposit,<EOL>deposit,<EOL>retry_timeout,<EOL>)<EOL>wait_for_usable_channel(<EOL>app1,<EOL>app0,<EOL>registry_address,<EOL>token_address,...
Wait until all channels are usable from both directions.
f9323:m12
def ensure_executable(cmd):
if not shutil.which(cmd):<EOL><INDENT>print(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % cmd,<EOL>)<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>
look for the given command and make sure it can be executed
f9324:m0
def check_dict_nested_attrs(item: Dict, dict_data: Dict) -> bool:
for key, value in dict_data.items():<EOL><INDENT>if key not in item:<EOL><INDENT>return False<EOL><DEDENT>item_value = item[key]<EOL>if isinstance(item_value, Mapping):<EOL><INDENT>if not check_dict_nested_attrs(item_value, value):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>elif item_value != value:<EOL><INDENT>retur...
Checks the values from `dict_data` are contained in `item` >>> d = {'a': 1, 'b': {'c': 2}} >>> check_dict_nested_attrs(d, {'a': 1) True >>> check_dict_nested_attrs(d, {'b': {'c': 2}}) True >>> check_dict_nested_attrs(d, {'d': []}) False
f9325:m0
def check_nested_attrs(item: Any, attributes: Dict) -> bool:
for name, value in attributes.items():<EOL><INDENT>item_value = getattr(item, name, NOVALUE)<EOL>if isinstance(value, Mapping):<EOL><INDENT>if not check_nested_attrs(item_value, value):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>elif item_value != value:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>
Checks the attributes from `item` match the values defined in `attributes`. >>> from collections import namedtuple >>> A = namedtuple('A', 'a') >>> B = namedtuple('B', 'b') >>> d = {'a': 1} >>> check_nested_attrs(A(1), {'a': 1}) True >>> check_nested_attrs(A(B(1)), {'a': {'b': 1}}) True...
f9325:m1
def search_for_item(<EOL>item_list: List,<EOL>item_type: Any,<EOL>attributes: Dict,<EOL>) -> Optional[Any]:
for item in item_list:<EOL><INDENT>if isinstance(item, item_type) and check_nested_attrs(item, attributes):<EOL><INDENT>return item<EOL><DEDENT><DEDENT>return None<EOL>
Search for the first item of type `item_type` with `attributes` in `item_list`. `attributes` are compared using the utility `check_nested_attrs`.
f9325:m2
def raiden_events_search_for_item(<EOL>raiden: RaidenService,<EOL>item_type: Event,<EOL>attributes: Dict,<EOL>) -> Optional[Event]:
return search_for_item(raiden.wal.storage.get_events(), item_type, attributes)<EOL>
Search for the first event of type `item_type` with `attributes` in the `raiden` database. `attributes` are compared using the utility `check_nested_attrs`.
f9325:m3
def raiden_state_changes_search_for_item(<EOL>raiden: RaidenService,<EOL>item_type: StateChange,<EOL>attributes: Dict,<EOL>) -> Optional[StateChange]:
return search_for_item(<EOL>raiden.wal.storage.get_statechanges_by_identifier(<NUM_LIT:0>, '<STR_LIT>'),<EOL>item_type,<EOL>attributes,<EOL>)<EOL>
Search for the first event of type `item_type` with `attributes` in the `raiden` database. `attributes` are compared using the utility `check_nested_attrs`.
f9325:m4
def wait_for_raiden_event(<EOL>raiden: RaidenService,<EOL>item_type: Event,<EOL>attributes: Dict,<EOL>retry_timeout: float,<EOL>) -> Event:
found = None<EOL>while found is None:<EOL><INDENT>found = raiden_events_search_for_item(raiden, item_type, attributes)<EOL>gevent.sleep(retry_timeout)<EOL><DEDENT>return found<EOL>
Wait until an event is seen in the WAL events Note: This does not time out, use gevent.Timeout.
f9325:m7
def wait_for_state_change(<EOL>raiden: RaidenService,<EOL>item_type: StateChange,<EOL>attributes: Dict,<EOL>retry_timeout: float,<EOL>) -> StateChange:
found = None<EOL>while found is None:<EOL><INDENT>found = raiden_state_changes_search_for_item(raiden, item_type, attributes)<EOL>gevent.sleep(retry_timeout)<EOL><DEDENT>return found<EOL>
Wait until a state change is seen in the WAL Note: This does not time out, use gevent.Timeout.
f9325:m8
def dont_handle_lock_expired_mock(app):
def do_nothing(raiden, message): <EOL><INDENT>pass<EOL><DEDENT>return patch.object(<EOL>app.raiden.message_handler,<EOL>'<STR_LIT>',<EOL>side_effect=do_nothing,<EOL>)<EOL>
Takes in a raiden app and returns a mock context where lock_expired is not processed
f9326:m0
def dont_handle_node_change_network_state():
def empty_state_transition(chain_state, state_change): <EOL><INDENT>return TransitionResult(chain_state, list())<EOL><DEDENT>return patch(<EOL>'<STR_LIT>',<EOL>empty_state_transition,<EOL>)<EOL>
Returns a mock context where ActionChangeNodeNetworkState is not processed
f9326:m1