Exemplo n.º 1
0
    def setup_token_contract_for_token_network(
            self, proxy_manager: ProxyManager) -> CustomToken:
        """Ensure there is a deployed token contract and return a `CustomToken`
        proxy to it. This token will be used for the scenario's token network.

        This will either:

        - Use the token from the address provided in the scenario
          configuration.
        - Use a previously deployed token, with the details loaded from the
          disk.
        - Deploy a new token if neither of the above options is used.
        """
        token_definition = self.definition.token
        reuse_token_from_file = token_definition.can_reuse_token

        if token_definition.address:
            token_address = to_canonical_address(token_definition.address)
        elif reuse_token_from_file:
            token_details = load_token_configuration_from_file(
                token_definition.token_file)
            token_address = to_canonical_address(token_details["address"])
        else:
            contract_data = proxy_manager.contract_manager.get_contract(
                CONTRACT_CUSTOM_TOKEN)
            contract, receipt = self.client.deploy_single_contract(
                contract_name=CONTRACT_CUSTOM_TOKEN,
                contract=contract_data,
                constructor_parameters=(
                    ORCHESTRATION_MAXIMUM_BALANCE,
                    token_definition.decimals,
                    token_definition.name,
                    token_definition.symbol,
                ),
            )
            token_address = to_canonical_address(contract.address)

            if token_definition.should_reuse_token:
                details = TokenDetails({
                    "name":
                    token_definition.name,
                    "address":
                    to_checksum_address(token_address),
                    "block":
                    receipt["blockNumber"],
                })
                save_token_configuration_to_file(token_definition.token_file,
                                                 details)

        return proxy_manager.custom_token(TokenAddress(token_address),
                                          "latest")
Exemplo n.º 2
0
    def setup_raiden_nodes_with_sufficient_user_deposit_balances(
        self,
        pool: Pool,
        userdeposit_proxy: UserDeposit,
        node_addresses: Set[ChecksumAddress],
        mint_greenlets: Set[Greenlet],
    ) -> Set[Greenlet]:
        """Makes sure every Raiden node's account has enough tokens in the
        user deposit contract.

        For these transfers to work, the approve and mint transacations have to
        be mined and confirmed. This is necessary because otherwise the gas
        estimation of the deposits fail.
        """
        msg = "udc is not enabled, this function should not be called"
        assert is_udc_enabled(self.definition.settings.services.udc), msg

        minimum_effective_deposit = self.definition.settings.services.udc.token.balance_per_node
        maximum_funding = self.definition.settings.services.udc.token.max_funding

        log.debug("Depositing utility tokens for the nodes")
        greenlets: Set[Greenlet] = set()
        for address in node_addresses:
            g = pool.spawn(
                userdeposit_maybe_deposit,
                userdeposit_proxy=userdeposit_proxy,
                mint_greenlets=mint_greenlets,
                target_address=to_canonical_address(address),
                minimum_effective_deposit=minimum_effective_deposit,
                maximum_funding=maximum_funding,
            )
            greenlets.add(g)

        return greenlets
Exemplo n.º 3
0
def get_token_network_registry_from_dependencies(
    settings: SettingsConfig,
    proxy_manager: ProxyManager,
    development_environment: ContractDevEnvironment,
    smoketest_deployment_data: DeployedContracts = None,
) -> TokenNetworkRegistry:
    """Return contract proxies for the UserDepositContract and associated token.

    This will return a proxy to the `UserDeposit` contract as determined by the
    **local** Raiden dependency.
    """
    chain_id = settings.chain_id
    assert chain_id, "Missing configuration, either set udc_address or the chain_id"

    if chain_id != CHAINNAME_TO_ID["smoketest"]:
        contracts = get_contracts_deployment_info(
            chain_id,
            version=RAIDEN_CONTRACT_VERSION,
            development_environment=development_environment,
        )
    else:
        contracts = smoketest_deployment_data

    msg = f"invalid chain_id, {chain_id} is not available for version {RAIDEN_CONTRACT_VERSION}"
    assert contracts, msg

    token_network_address = contracts["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY]["address"]

    token_network_proxy = proxy_manager.token_network_registry(
        TokenNetworkRegistryAddress(to_canonical_address(token_network_address)),
        "latest",
    )
    return token_network_proxy
Exemplo n.º 4
0
    def setup_raiden_nodes_ether_balances(
        self, pool: Pool, node_addresses: Set[ChecksumAddress]
    ) -> Set[Greenlet]:
        """ Makes sure every Raiden node has at least `NODE_ACCOUNT_BALANCE_MIN`. """

        greenlets: Set[Greenlet] = set()
        for address in node_addresses:
            g = pool.spawn(
                eth_maybe_transfer,
                orchestration_client=self.client,
                target=to_canonical_address(address),
                minimum_balance=NODE_ACCOUNT_BALANCE_MIN,
                maximum_balance=NODE_ACCOUNT_BALANCE_FUND,
            )
            greenlets.add(g)

        return greenlets
Exemplo n.º 5
0
 def ensure_token_network_discovery(
         self, token: CustomToken,
         token_network_addresses: TokenNetworkAddress) -> None:
     """Ensure that all our nodes have discovered the same token network."""
     for node in self.node_controller:  # type: ignore
         node_endpoint = API_URL_TOKEN_NETWORK_ADDRESS.format(
             protocol=self.protocol,
             target_host=node.base_url,
             token_address=to_checksum_address(token.address),
         )
         address = wait_for_token_network_discovery(
             node_endpoint, self.definition.settings, self.session)
         if to_canonical_address(address) != Address(
                 token_network_addresses):
             raise RuntimeError(
                 f"Nodes diverged on the token network address, there should be "
                 f"exactly one token network available for all nodes. Current "
                 f"values : {to_hex(token_network_addresses)}")
Exemplo n.º 6
0
def dummy_scenario_runner(mocked_responses, mocked_scenario_runner):
    return mocked_scenario_runner("dummy_scenario", to_canonical_address(TEST_TOKEN_ADDRESS))