Exemplo n.º 1
0
def deploy_token_network_registry(
    secret_registry_deploy_result: Callable[[], SecretRegistry],
    deploy_client: JSONRPCClient,
    contract_manager: ContractManager,
    proxy_manager: ProxyManager,
    chain_id: ChainID,
    settle_timeout_min: int,
    settle_timeout_max: int,
    max_token_networks: int,
) -> TokenNetworkRegistry:
    secret_registry_proxy = secret_registry_deploy_result()
    contract, receipt = deploy_client.deploy_single_contract(
        contract_name=CONTRACT_TOKEN_NETWORK_REGISTRY,
        contract=contract_manager.get_contract(
            CONTRACT_TOKEN_NETWORK_REGISTRY),
        constructor_parameters=[
            secret_registry_proxy.address,
            chain_id,
            settle_timeout_min,
            settle_timeout_max,
            max_token_networks,
        ],
    )

    return proxy_manager.token_network_registry(
        TokenNetworkRegistryAddress(to_canonical_address(contract.address)),
        BlockNumber(receipt["blockNumber"]),
    )
Exemplo n.º 2
0
def jsonrpc_services(
    proxy_manager: ProxyManager,
    private_keys: List[PrivateKey],
    secret_registry_address: SecretRegistryAddress,
    service_registry_address: ServiceRegistryAddress,
    token_network_registry_address: TokenNetworkRegistryAddress,
    web3: Web3,
    contract_manager: ContractManager,
) -> BlockchainServices:
    secret_registry = proxy_manager.secret_registry(secret_registry_address)
    service_registry = None
    if service_registry_address:
        service_registry = proxy_manager.service_registry(service_registry_address)
    deploy_registry = proxy_manager.token_network_registry(token_network_registry_address)

    blockchain_services = list()
    for privkey in private_keys:
        rpc_client = JSONRPCClient(web3, privkey)
        proxy_manager = ProxyManager(
            rpc_client=rpc_client,
            contract_manager=contract_manager,
            metadata=ProxyManagerMetadata(
                token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
                filters_start_at=GENESIS_BLOCK_NUMBER,
            ),
        )
        blockchain_services.append(proxy_manager)

    return BlockchainServices(
        deploy_registry=deploy_registry,
        secret_registry=secret_registry,
        service_registry=service_registry,
        proxy_manager=proxy_manager,
        blockchain_services=blockchain_services,
    )
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 register_token_and_return_the_network_proxy(
    contract_manager: ContractManager,
    deploy_client: JSONRPCClient,
    token_proxy: Token,
    token_network_registry_address: TokenNetworkRegistryAddress,
) -> TokenNetwork:
    blockchain_service = ProxyManager(
        rpc_client=deploy_client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )

    token_network_registry_proxy = blockchain_service.token_network_registry(
        token_network_registry_address)
    token_network_address = token_network_registry_proxy.add_token(
        token_address=token_proxy.address,
        channel_participant_deposit_limit=
        RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
        token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
        block_identifier=deploy_client.get_confirmed_blockhash(),
    )

    blockchain_service = ProxyManager(
        rpc_client=deploy_client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )
    return blockchain_service.token_network(token_network_address)
Exemplo n.º 5
0
def test_token_network_registry_max_token_networks(
        deploy_client, token_network_registry_address, contract_manager):
    """ get_max_token_networks() should return an integer """
    proxy_manager = ProxyManager(
        rpc_client=deploy_client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )
    token_network_registry_proxy = proxy_manager.token_network_registry(
        to_canonical_address(token_network_registry_address))
    assert (token_network_registry_proxy.get_max_token_networks(
        block_identifier="latest") == UINT256_MAX)
Exemplo n.º 6
0
def deploy_all_tokens_register_and_return_their_addresses(
    token_amount: TokenAmount,
    number_of_tokens: int,
    private_keys: List[PrivateKey],
    proxy_manager: ProxyManager,
    token_network_registry_address: TokenNetworkRegistryAddress,
    register_tokens: bool,
    contract_manager: ContractManager,
    token_contract_name: str,
) -> List[TokenAddress]:
    """ Fixture that yields `number_of_tokens` ERC20 token addresses, where the
    `token_amount` (per token) is distributed among the addresses behind `deploy_client` and
    potentially pre-registered with the Raiden Registry.
    The following arguments can control the behavior:

    Args:
        token_amount: the overall number of units minted per token
        number_of_tokens: the number of token instances
        register_tokens: controls if tokens will be registered with raiden Registry
    """

    participants = [privatekey_to_address(key) for key in private_keys]
    token_addresses = deploy_tokens_and_fund_accounts(
        token_amount=token_amount,
        number_of_tokens=number_of_tokens,
        proxy_manager=proxy_manager,
        participants=participants,
        contract_manager=contract_manager,
        token_contract_name=token_contract_name,
    )

    if register_tokens:
        for token in token_addresses:
            registry = proxy_manager.token_network_registry(
                token_network_registry_address)
            registry.add_token(
                token_address=token,
                channel_participant_deposit_limit=
                RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
                token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
                block_identifier=proxy_manager.client.
                blockhash_from_blocknumber("latest"),
            )

    return token_addresses
Exemplo n.º 7
0
def test_token_network_registry_with_zero_token_address(
        deploy_client, token_network_registry_address, contract_manager):
    """ Try to register a token at 0x0000..00 """
    proxy_manager = ProxyManager(
        rpc_client=deploy_client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )
    token_network_registry_proxy = proxy_manager.token_network_registry(
        token_network_registry_address)
    with pytest.raises(InvalidTokenAddress, match="0x00..00 will fail"):
        token_network_registry_proxy.add_token(
            token_address=NULL_ADDRESS_BYTES,
            channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
            token_network_deposit_limit=TokenAmount(UINT256_MAX),
            block_identifier=deploy_client.get_confirmed_blockhash(),
        )
Exemplo n.º 8
0
def load_deployment_addresses_from_udc(
    proxy_manager: ProxyManager,
    user_deposit_address: UserDepositAddress,
    block_identifier: BlockIdentifier,
) -> DeploymentAddresses:
    """Given a user deposit address, this function returns the list of contract addresses
    which are used as services which are bound to the user deposit contract deployed.
    """
    block_identifier = BLOCK_ID_LATEST
    user_deposit = proxy_manager.user_deposit(
        UserDepositAddress(to_canonical_address(user_deposit_address)),
        block_identifier=block_identifier,
    )
    monitoring_service_address = user_deposit.monitoring_service_address(
        block_identifier)
    one_to_n_address = user_deposit.one_to_n_address(
        block_identifier=block_identifier)

    monitoring_service_proxy = proxy_manager.monitoring_service(
        address=monitoring_service_address, block_identifier=block_identifier)

    token_network_registry_address = monitoring_service_proxy.token_network_registry_address(
        block_identifier=block_identifier)

    token_network_registry_proxy = proxy_manager.token_network_registry(
        token_network_registry_address, block_identifier=block_identifier)
    secret_registry_address = token_network_registry_proxy.get_secret_registry_address(
        block_identifier=block_identifier)
    service_registry_address = monitoring_service_proxy.service_registry_address(
        block_identifier=block_identifier)

    return DeploymentAddresses(
        token_network_registry_address=token_network_registry_address,
        secret_registry_address=secret_registry_address,
        user_deposit_address=user_deposit_address,
        service_registry_address=service_registry_address,
        monitoring_service_address=monitoring_service_address,
        one_to_n_address=one_to_n_address,
    )
def test_token_network_registry(
    deploy_client: JSONRPCClient,
    contract_manager: ContractManager,
    token_network_registry_address: TokenNetworkRegistryAddress,
    token_contract_name: str,
) -> None:
    proxy_manager = ProxyManager(
        rpc_client=deploy_client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )

    confirmed_block_identifier = deploy_client.get_confirmed_blockhash()

    token_network_registry_proxy = proxy_manager.token_network_registry(
        token_network_registry_address,
        block_identifier=confirmed_block_identifier)

    assert (token_network_registry_proxy.settlement_timeout_min(
        BLOCK_ID_LATEST) == TEST_SETTLE_TIMEOUT_MIN)
    assert (token_network_registry_proxy.settlement_timeout_max(
        BLOCK_ID_LATEST) == TEST_SETTLE_TIMEOUT_MAX)
    assert (token_network_registry_proxy.get_token_network_created(
        block_identifier=BLOCK_ID_LATEST) == 0)

    bad_token_address = make_token_address()

    # Registering a non-existing token network should fail
    with pytest.raises(AddressWithoutCode):
        token_network_registry_proxy.add_token(
            token_address=bad_token_address,
            channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
            token_network_deposit_limit=TokenAmount(UINT256_MAX),
            given_block_identifier=confirmed_block_identifier,
        )

    test_token = deploy_token(
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        initial_amount=TokenAmount(1000),
        decimals=0,
        token_name="TKN",
        token_symbol="TKN",
        token_contract_name=token_contract_name,
    )
    test_token_address = TokenAddress(to_canonical_address(test_token.address))

    # Check the proper exception is raised if the token does not comply to the
    # ERC20 interface. In this case the token does not have the totalSupply()
    # function implemented #3697 which is validated in the smart contract.
    with patch.object(Token, "total_supply", return_value=None):
        with pytest.raises(InvalidToken):
            token_network_registry_proxy.add_token(
                token_address=test_token_address,
                channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
                token_network_deposit_limit=TokenAmount(UINT256_MAX),
                given_block_identifier=deploy_client.get_confirmed_blockhash(),
            )

    # Register a valid token
    preblockhash = deploy_client.get_confirmed_blockhash()
    token_network_address = token_network_registry_proxy.add_token(
        token_address=test_token_address,
        channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
        token_network_deposit_limit=TokenAmount(UINT256_MAX),
        given_block_identifier=preblockhash,
    )
    assert token_network_address is not None
    assert (token_network_registry_proxy.get_token_network_created(
        block_identifier=BLOCK_ID_LATEST) == 1)

    # Re-registering the same token should fail with a recoverable error
    # because it is a race condition.
    with pytest.raises(RaidenRecoverableError):
        token_network_registry_proxy.add_token(
            token_address=test_token_address,
            channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
            token_network_deposit_limit=TokenAmount(UINT256_MAX),
            given_block_identifier=preblockhash,
        )

    logs = token_network_registry_proxy.filter_token_added_events()
    assert is_same_address(logs[0]["args"]["token_address"],
                           test_token.address)
    assert is_same_address(logs[0]["args"]["token_network_address"],
                           token_network_address)
    assert (token_network_registry_proxy.get_token_network(
        bad_token_address, BLOCK_ID_LATEST) is None)

    result_address = token_network_registry_proxy.get_token_network(
        test_token_address, BLOCK_ID_LATEST)

    assert result_address
    assert to_normalized_address(result_address) == to_normalized_address(
        token_network_address)

    with pytest.raises(ValueError):
        assert token_network_registry_proxy.get_token_network(
            None,
            BLOCK_ID_LATEST  # type: ignore
        )

    # These are not registered token addresses
    assert (token_network_registry_proxy.get_token_network(
        bad_token_address, BLOCK_ID_LATEST) is None)
    assert (token_network_registry_proxy.get_token_network(
        test_token_address, BLOCK_ID_LATEST) is not None)
    address = token_network_registry_proxy.get_token_network(
        TokenAddress(token_network_address), BLOCK_ID_LATEST)
    assert address is None
def test_token_network_registry_allows_the_last_slot_to_be_used(
        deploy_client, token_network_registry_address, contract_manager,
        token_contract_name):
    proxy_manager = ProxyManager(
        rpc_client=deploy_client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )
    confirmed_block_identifier = deploy_client.get_confirmed_blockhash()

    token_network_registry_proxy = proxy_manager.token_network_registry(
        token_network_registry_address,
        block_identifier=confirmed_block_identifier)

    assert (token_network_registry_proxy.get_token_network_created(
        block_identifier=BLOCK_ID_LATEST) == 0)

    test_token = deploy_token(
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        initial_amount=TokenAmount(1000),
        decimals=0,
        token_name="TKN",
        token_symbol="TKN",
        token_contract_name=token_contract_name,
    )
    first_token_address = TokenAddress(to_canonical_address(
        test_token.address))
    preblockhash = deploy_client.get_confirmed_blockhash()

    # Register a valid token, this is the last slot and should succeeded
    token_network_registry_proxy.add_token(
        token_address=first_token_address,
        channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
        token_network_deposit_limit=TokenAmount(UINT256_MAX),
        given_block_identifier=preblockhash,
    )

    test_token = deploy_token(
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        initial_amount=TokenAmount(1000),
        decimals=0,
        token_name="TKN",
        token_symbol="TKN",
        token_contract_name=token_contract_name,
    )
    second_token_address = TokenAddress(
        to_canonical_address(test_token.address))
    preblockhash = deploy_client.get_confirmed_blockhash()

    # Tries to register a new valid token after all slots have been used. This
    # has to fail.
    with pytest.raises(MaxTokenNetworkNumberReached):
        token_network_registry_proxy.add_token(
            token_address=second_token_address,
            channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
            token_network_deposit_limit=TokenAmount(UINT256_MAX),
            given_block_identifier=preblockhash,
        )
Exemplo n.º 11
0
def setup_raiden(
    matrix_server: str,
    print_step: StepPrinter,
    contracts_version,
    eth_rpc_endpoint: str,
    web3: Web3,
    base_datadir: Path,
    keystore: Path,
) -> RaidenTestSetup:
    print_step("Deploying Raiden contracts")

    client = JSONRPCClient(web3, get_private_key(keystore))
    contract_manager = ContractManager(
        contracts_precompiled_path(contracts_version))

    proxy_manager = ProxyManager(
        rpc_client=client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )

    token = deploy_token(
        deploy_client=client,
        contract_manager=contract_manager,
        initial_amount=TokenAmount(1000),
        decimals=0,
        token_name="TKN",
        token_symbol="TKN",
        token_contract_name=CONTRACT_CUSTOM_TOKEN,
    )
    contract_addresses = deploy_smoketest_contracts(
        client=client,
        chain_id=CHAINNAME_TO_ID["smoketest"],
        contract_manager=contract_manager,
        token_address=token.address,
    )
    confirmed_block_identifier = client.get_confirmed_blockhash()
    registry = proxy_manager.token_network_registry(
        TokenNetworkRegistryAddress(
            contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY]),
        block_identifier=confirmed_block_identifier,
    )

    registry.add_token(
        token_address=TokenAddress(to_canonical_address(token.address)),
        channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
        token_network_deposit_limit=TokenAmount(UINT256_MAX),
        given_block_identifier=confirmed_block_identifier,
    )

    print_step("Setting up Raiden")
    user_deposit_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_USER_DEPOSIT])

    args = {
        "address": to_checksum_address(TEST_ACCOUNT_ADDRESS),
        "datadir": keystore,
        "eth_rpc_endpoint": eth_rpc_endpoint,
        "gas_price": "fast",
        "keystore_path": keystore,
        "matrix_server": matrix_server,
        "chain_id": str(CHAINNAME_TO_ID["smoketest"]),
        "password_file": click.File()(os.path.join(base_datadir, "pw")),
        "user_deposit_contract_address": user_deposit_contract_address,
        "sync_check": False,
        "environment_type": Environment.DEVELOPMENT,
    }

    # Wait until the secret registry is confirmed, otherwise the RaidenService
    # inialization will fail, needed for the check
    # `check_ethereum_confirmed_block_is_not_pruned`.
    current_block = client.block_number()
    target_block_number = current_block + DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS
    while current_block < target_block_number:
        current_block = client.block_number()
        sleep(0.5)

    return RaidenTestSetup(args=args,
                           token=token,
                           contract_addresses=contract_addresses)
Exemplo n.º 12
0
def setup_proxies_or_exit(
    config: Dict[str, Any],
    tokennetwork_registry_contract_address: TokenNetworkRegistryAddress,
    secret_registry_contract_address: Address,
    user_deposit_contract_address: Address,
    service_registry_contract_address: Address,
    proxy_manager: ProxyManager,
    contracts: Dict[str, Any],
    routing_mode: RoutingMode,
    pathfinding_service_address: str,
) -> Proxies:
    """
    Initialize and setup the contract proxies.

    Depending on the provided contract addresses via the CLI, the routing mode,
    the environment type and the network id try to initialize the proxies.
    Returns the initialized proxies or exits the application with an error if
    there is a problem.

    Also depending on the given arguments populate config with PFS related settings
    """
    node_network_id = config["chain_id"]
    environment_type = config["environment_type"]

    check_smart_contract_addresses(
        environment_type=environment_type,
        node_network_id=node_network_id,
        tokennetwork_registry_contract_address=
        tokennetwork_registry_contract_address,
        secret_registry_contract_address=secret_registry_contract_address,
        contracts=contracts,
    )

    token_network_registry = None
    try:
        if tokennetwork_registry_contract_address is not None:
            registered_address = tokennetwork_registry_contract_address
        else:
            registered_address = to_canonical_address(
                contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]["address"])
        token_network_registry = proxy_manager.token_network_registry(
            registered_address)
    except ContractCodeMismatch as e:
        handle_contract_code_mismatch(e)
    except AddressWithoutCode:
        handle_contract_no_code(
            "token network registry",
            Address(tokennetwork_registry_contract_address))
    except AddressWrongContract:
        handle_contract_wrong_address(
            "token network registry",
            Address(tokennetwork_registry_contract_address))

    secret_registry = None
    try:
        secret_registry = proxy_manager.secret_registry(
            secret_registry_contract_address or to_canonical_address(
                contracts[CONTRACT_SECRET_REGISTRY]["address"]))
    except ContractCodeMismatch as e:
        handle_contract_code_mismatch(e)
    except AddressWithoutCode:
        handle_contract_no_code("secret registry",
                                secret_registry_contract_address)
    except AddressWrongContract:
        handle_contract_wrong_address("secret registry",
                                      secret_registry_contract_address)

    # If services contracts are provided via the CLI use them instead
    if user_deposit_contract_address is not None:
        contracts[CONTRACT_USER_DEPOSIT] = user_deposit_contract_address
    if service_registry_contract_address is not None:
        contracts[
            CONTRACT_SERVICE_REGISTRY] = service_registry_contract_address

    user_deposit = None
    should_use_user_deposit = (
        environment_type == Environment.DEVELOPMENT
        and ID_TO_NETWORKNAME.get(node_network_id) != "smoketest"
        and CONTRACT_USER_DEPOSIT in contracts)
    if should_use_user_deposit:
        try:
            user_deposit = proxy_manager.user_deposit(
                user_deposit_contract_address or to_canonical_address(
                    contracts[CONTRACT_USER_DEPOSIT]["address"]))
        except ContractCodeMismatch as e:
            handle_contract_code_mismatch(e)
        except AddressWithoutCode:
            handle_contract_no_code("user deposit",
                                    user_deposit_contract_address)
        except AddressWrongContract:
            handle_contract_wrong_address("user_deposit",
                                          user_deposit_contract_address)

    service_registry = None
    if CONTRACT_SERVICE_REGISTRY in contracts or service_registry_contract_address:
        try:
            service_registry = proxy_manager.service_registry(
                service_registry_contract_address or to_canonical_address(
                    contracts[CONTRACT_SERVICE_REGISTRY]["address"]))
        except ContractCodeMismatch as e:
            handle_contract_code_mismatch(e)
        except AddressWithoutCode:
            handle_contract_no_code("service registry",
                                    service_registry_contract_address)
        except AddressWrongContract:
            handle_contract_wrong_address("secret registry",
                                          service_registry_contract_address)

    # By now these should be set or Raiden aborted
    assert token_network_registry, "TokenNetworkRegistry needs to be set"
    assert secret_registry, "SecretRegistry needs to be set"

    if routing_mode == RoutingMode.PFS:
        check_pfs_configuration(
            service_registry=service_registry,
            pathfinding_service_address=pathfinding_service_address,
        )

        pfs_info = configure_pfs_or_exit(
            pfs_url=pathfinding_service_address,
            routing_mode=routing_mode,
            service_registry=service_registry,
            node_network_id=node_network_id,
            token_network_registry_address=token_network_registry.address,
            pathfinding_max_fee=config["services"]["pathfinding_max_fee"],
        )
        msg = "Eth address of selected pathfinding service is unknown."
        assert pfs_info.payment_address is not None, msg

        # Only check that PFS is registered in production mode
        if environment_type == Environment.PRODUCTION:
            check_pfs_for_production(service_registry=service_registry,
                                     pfs_info=pfs_info)

        config["pfs_config"] = PFSConfig(
            info=pfs_info,
            maximum_fee=config["services"]["pathfinding_max_fee"],
            iou_timeout=config["services"]["pathfinding_iou_timeout"],
            max_paths=config["services"]["pathfinding_max_paths"],
        )
    else:
        config["pfs_config"] = None

    proxies = Proxies(
        token_network_registry=token_network_registry,
        secret_registry=secret_registry,
        user_deposit=user_deposit,
        service_registry=service_registry,
    )
    return proxies
Exemplo n.º 13
0
def setup_raiden(
    transport,
    matrix_server,
    print_step,
    contracts_version,
    eth_client,
    eth_rpc_endpoint,
    web3,
    base_datadir,
    keystore,
):
    print_step("Deploying Raiden contracts")

    if eth_client is EthClient.PARITY:
        client = JSONRPCClient(web3,
                               get_private_key(keystore),
                               gas_estimate_correction=lambda gas: gas * 2)
    else:
        client = JSONRPCClient(web3, get_private_key(keystore))
    contract_manager = ContractManager(
        contracts_precompiled_path(contracts_version))

    proxy_manager = ProxyManager(
        rpc_client=client,
        contract_manager=contract_manager,
        metadata=ProxyManagerMetadata(
            token_network_registry_deployed_at=GENESIS_BLOCK_NUMBER,
            filters_start_at=GENESIS_BLOCK_NUMBER,
        ),
    )

    token = deploy_token(
        deploy_client=client,
        contract_manager=contract_manager,
        initial_amount=1000,
        decimals=0,
        token_name="TKN",
        token_symbol="TKN",
        token_contract_name=CONTRACT_HUMAN_STANDARD_TOKEN,
    )
    contract_addresses = deploy_smoketest_contracts(
        client=client,
        chain_id=NETWORKNAME_TO_ID["smoketest"],
        contract_manager=contract_manager,
        token_address=to_canonical_address(token.contract.address),
    )
    registry = proxy_manager.token_network_registry(
        contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY])

    registry.add_token(
        token_address=to_canonical_address(token.contract.address),
        channel_participant_deposit_limit=UINT256_MAX,
        token_network_deposit_limit=UINT256_MAX,
        block_identifier=client.get_confirmed_blockhash(),
    )

    print_step("Setting up Raiden")
    tokennetwork_registry_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY])
    secret_registry_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_SECRET_REGISTRY])

    args = {
        "address": to_checksum_address(TEST_ACCOUNT_ADDRESS),
        "datadir": keystore,
        "eth_rpc_endpoint": eth_rpc_endpoint,
        "gas_price": "fast",
        "keystore_path": keystore,
        "matrix_server": matrix_server,
        "network_id": str(NETWORKNAME_TO_ID["smoketest"]),
        "password_file": click.File()(os.path.join(base_datadir, "pw")),
        "tokennetwork_registry_contract_address":
        tokennetwork_registry_contract_address,
        "secret_registry_contract_address": secret_registry_contract_address,
        "sync_check": False,
        "transport": transport,
    }

    service_registry_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_SERVICE_REGISTRY])
    args[
        "service_registry_contract_address"] = service_registry_contract_address

    monitoring_service_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_MONITORING_SERVICE])
    args[
        "monitoring_service_contract_address"] = monitoring_service_contract_address

    one_to_n_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_ONE_TO_N])
    args["one_to_n_contract_address"] = one_to_n_contract_address

    # Wait until the secret registry is confirmed, otherwise the App
    # inialization will fail, needed for the check
    # `check_ethereum_confirmed_block_is_not_pruned`.
    current_block = client.block_number()
    target_block_number = current_block + DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS
    while current_block < target_block_number:
        current_block = client.block_number()
        sleep(0.5)

    return {
        "args": args,
        "contract_addresses": contract_addresses,
        "token": token
    }