Ejemplo n.º 1
0
def register_token_and_return_the_network_proxy(
    contract_manager,
    deploy_client,
    token_proxy,
    token_network_registry_address,
):
    registry_address = to_canonical_address(token_network_registry_address)

    token_network_registry_proxy = TokenNetworkRegistry(
        jsonrpc_client=deploy_client,
        registry_address=registry_address,
        contract_manager=contract_manager,
    )
    token_network_address = token_network_registry_proxy.add_token_with_limits(
        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,
    )

    return TokenNetwork(
        jsonrpc_client=deploy_client,
        token_network_address=token_network_address,
        contract_manager=contract_manager,
    )
Ejemplo n.º 2
0
    def __init__(
        self,
        config: RaidenConfig,
        rpc_client: JSONRPCClient,
        proxy_manager: ProxyManager,
        query_start_block: BlockNumber,
        default_registry: TokenNetworkRegistry,
        default_secret_registry: SecretRegistry,
        default_service_registry: Optional[ServiceRegistry],
        default_user_deposit: Optional[UserDeposit],
        default_one_to_n_address: Optional[OneToNAddress],
        default_msc_address: Optional[MonitoringServiceAddress],
        transport: MatrixTransport,
        raiden_event_handler: EventHandler,
        message_handler: MessageHandler,
        routing_mode: RoutingMode,
        api_server: APIServer = None,
    ):
        raiden = RaidenService(
            rpc_client=rpc_client,
            proxy_manager=proxy_manager,
            query_start_block=query_start_block,
            default_registry=default_registry,
            default_secret_registry=default_secret_registry,
            default_service_registry=default_service_registry,
            default_user_deposit=default_user_deposit,
            default_one_to_n_address=default_one_to_n_address,
            default_msc_address=default_msc_address,
            transport=transport,
            raiden_event_handler=raiden_event_handler,
            message_handler=message_handler,
            routing_mode=routing_mode,
            config=config,
            api_server=api_server,
        )

        # check that the settlement timeout fits the limits of the contract
        settlement_timeout_min = default_registry.settlement_timeout_min(BLOCK_ID_LATEST)
        settlement_timeout_max = default_registry.settlement_timeout_max(BLOCK_ID_LATEST)
        invalid_settle_timeout = (
            config.settle_timeout < settlement_timeout_min
            or config.settle_timeout > settlement_timeout_max
            or config.settle_timeout < config.reveal_timeout * 2
        )
        if invalid_settle_timeout:
            raise InvalidSettleTimeout(
                (
                    "Settlement timeout for Registry contract {} must "
                    "be in range [{}, {}], is {}"
                ).format(
                    to_checksum_address(default_registry.address),
                    settlement_timeout_min,
                    settlement_timeout_max,
                    config.settle_timeout,
                )
            )

        self.config = config
        self.raiden = raiden
Ejemplo n.º 3
0
    def __init__(
        self,
        config: typing.Dict,
        rpc_client: JSONRPCClient,
        proxy_manager: ProxyManager,
        query_start_block: typing.BlockNumber,
        default_registry: TokenNetworkRegistry,
        default_secret_registry: SecretRegistry,
        default_service_registry: typing.Optional[ServiceRegistry],
        default_one_to_n_address: typing.Optional[Address],
        default_msc_address: Address,
        transport: MatrixTransport,
        raiden_event_handler: EventHandler,
        message_handler: MessageHandler,
        routing_mode: RoutingMode,
        user_deposit: UserDeposit = None,
    ):
        raiden = RaidenService(
            rpc_client=rpc_client,
            proxy_manager=proxy_manager,
            query_start_block=query_start_block,
            default_registry=default_registry,
            default_one_to_n_address=default_one_to_n_address,
            default_secret_registry=default_secret_registry,
            default_service_registry=default_service_registry,
            default_msc_address=default_msc_address,
            transport=transport,
            raiden_event_handler=raiden_event_handler,
            message_handler=message_handler,
            routing_mode=routing_mode,
            config=config,
            user_deposit=user_deposit,
        )

        # check that the settlement timeout fits the limits of the contract
        settlement_timeout_min = default_registry.settlement_timeout_min("latest")
        settlement_timeout_max = default_registry.settlement_timeout_max("latest")
        invalid_settle_timeout = (
            config["settle_timeout"] < settlement_timeout_min
            or config["settle_timeout"] > settlement_timeout_max
            or config["settle_timeout"] < config["reveal_timeout"] * 2
        )
        if invalid_settle_timeout:
            raise InvalidSettleTimeout(
                (
                    "Settlement timeout for Registry contract {} must "
                    "be in range [{}, {}], is {}"
                ).format(
                    to_checksum_address(default_registry.address),
                    settlement_timeout_min,
                    settlement_timeout_max,
                    config["settle_timeout"],
                )
            )

        self.config = config
        self.user_deposit = user_deposit
        self.raiden = raiden
Ejemplo n.º 4
0
    def __init__(
            self,
            config: typing.Dict,
            chain: BlockChainService,
            query_start_block: typing.BlockNumber,
            default_registry: TokenNetworkRegistry,
            default_secret_registry: SecretRegistry,
            default_service_registry: typing.Optional[ServiceRegistry],
            transport,
            raiden_event_handler,
            message_handler,
            discovery: Discovery = None,
            user_deposit: UserDeposit = None,
    ):
        raiden = RaidenService(
            chain=chain,
            query_start_block=query_start_block,
            default_registry=default_registry,
            default_secret_registry=default_secret_registry,
            default_service_registry=default_service_registry,
            transport=transport,
            raiden_event_handler=raiden_event_handler,
            message_handler=message_handler,
            config=config,
            discovery=discovery,
            user_deposit=user_deposit,
        )

        # check that the settlement timeout fits the limits of the contract
        invalid_settle_timeout = (
            config['settle_timeout'] < default_registry.settlement_timeout_min() or
            config['settle_timeout'] > default_registry.settlement_timeout_max() or
            config['settle_timeout'] < config['reveal_timeout'] * 2
        )
        if invalid_settle_timeout:
            raise InvalidSettleTimeout(
                (
                    'Settlement timeout for Registry contract {} must '
                    'be in range [{}, {}], is {}'
                ).format(
                    to_checksum_address(default_registry.address),
                    default_registry.settlement_timeout_min(),
                    default_registry.settlement_timeout_max(),
                    config['settle_timeout'],
                ),
            )

        self.config = config
        self.discovery = discovery
        self.user_deposit = user_deposit
        self.raiden = raiden
        self.start_console = self.config['console']

        # raiden.ui.console:Console assumes that a services
        # attribute is available for auto-registration
        self.services = dict()
Ejemplo n.º 5
0
    def token_network_registry(
            self,
            address: TokenNetworkRegistryAddress) -> TokenNetworkRegistry:

        with self._token_network_registry_creation_lock:
            if address not in self.address_to_token_network_registry:

                metadata = SmartContractMetadata(
                    deployed_at=self.metadata.
                    token_network_registry_deployed_at,
                    address=Address(address),
                    abi=self.contract_manager.get_contract_abi(
                        CONTRACT_TOKEN_NETWORK_REGISTRY),
                    runtime_bytecode=EVMBytecode(
                        decode_hex(
                            self.contract_manager.get_runtime_hexcode(
                                CONTRACT_TOKEN_NETWORK_REGISTRY))),
                    gas_measurements=gas_measurements(
                        self.contract_manager.contracts_version),
                    filters_start_at=self.metadata.filters_start_at,
                )

                self.address_to_token_network_registry[
                    address] = TokenNetworkRegistry(rpc_client=self.client,
                                                    metadata=metadata,
                                                    proxy_manager=self)

        return self.address_to_token_network_registry[address]
Ejemplo n.º 6
0
def maybe_create_token_network(
        token_network_proxy: TokenNetworkRegistry,
        token_proxy: CustomToken) -> TokenNetworkAddress:
    """ Make sure the token is registered with the node's network registry. """
    block_identifier = token_network_proxy.rpc_client.get_confirmed_blockhash()
    token_address = token_proxy.address

    token_network_address = token_network_proxy.get_token_network(
        token_address=token_address, block_identifier=block_identifier)

    if token_network_address is None:
        _, new_token_network_address = token_network_proxy.add_token(
            token_address=token_address,
            channel_participant_deposit_limit=TokenAmount(UINT256_MAX),
            token_network_deposit_limit=TokenAmount(UINT256_MAX),
            given_block_identifier=block_identifier,
        )
        return new_token_network_address
    else:
        return token_network_address
Ejemplo n.º 7
0
    def token_network_registry(self, address: Address) -> TokenNetworkRegistry:
        if not is_binary_address(address):
            raise ValueError("address must be a valid address")

        with self._token_network_registry_creation_lock:
            if address not in self.address_to_token_network_registry:
                self.address_to_token_network_registry[
                    address] = TokenNetworkRegistry(
                        jsonrpc_client=self.client,
                        registry_address=PaymentNetworkID(address),
                        contract_manager=self.contract_manager,
                    )

        return self.address_to_token_network_registry[address]
Ejemplo n.º 8
0
    def add_token_network_registry_listener(
        self,
        token_network_registry_proxy: TokenNetworkRegistry,
        contract_manager: ContractManager,
        from_block: BlockNumber,
    ) -> None:
        token_new_filter = token_network_registry_proxy.tokenadded_filter(from_block=from_block)
        token_network_registry_address = token_network_registry_proxy.address

        self.add_event_listener(
            "TokenNetworkRegistry {}".format(to_checksum_address(token_network_registry_address)),
            token_new_filter,
            contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK_REGISTRY),
        )
def test_token_network_registry(
        deploy_client,
        contract_manager,
        token_network_registry_proxy: TokenNetworkRegistry,
):

    assert token_network_registry_proxy.settlement_timeout_min() == TEST_SETTLE_TIMEOUT_MIN
    assert token_network_registry_proxy.settlement_timeout_max() == TEST_SETTLE_TIMEOUT_MAX

    bad_token_address = make_address()
    # try to register non-existing token network
    with pytest.raises(RaidenUnrecoverableError):
        token_network_registry_proxy.add_token(bad_token_address)
    # create token network & register it
    test_token = deploy_token(
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        initial_amount=1000,
        decimals=0,
        token_name='TKN',
        token_symbol='TKN',
    )
    test_token_address = to_canonical_address(test_token.contract.address)
    event_filter = token_network_registry_proxy.tokenadded_filter()
    token_network_address = token_network_registry_proxy.add_token(
        test_token_address,
    )

    with pytest.raises(RaidenRecoverableError) as exc:
        token_network_address = token_network_registry_proxy.add_token(
            test_token_address,
        )

        assert 'Token already registered' in str(exc)

    logs = event_filter.get_all_entries()
    assert len(logs) == 1
    decoded_event = token_network_registry_proxy.proxy.decode_event(logs[0])
    assert is_same_address(decoded_event['args']['token_address'], test_token.contract.address)
    assert is_same_address(
        decoded_event['args']['token_network_address'],
        token_network_address,
    )
    # test other getters
    assert token_network_registry_proxy.get_token_network(bad_token_address) is None
    assert is_same_address(
        token_network_registry_proxy.get_token_network(test_token_address),
        token_network_address,
    )

    with pytest.raises(ValueError):
        assert token_network_registry_proxy.get_token_network(None) is None

    assert token_network_registry_proxy.get_token_network(bad_token_address) is None
    assert token_network_registry_proxy.get_token_network(token_network_address) is None
    assert token_network_registry_proxy.get_token_network(test_token_address) is not None
Ejemplo n.º 10
0
def test_token_network_registry(
    deploy_client,
    contract_manager,
    token_network_registry_proxy: TokenNetworkRegistry,
):

    assert token_network_registry_proxy.settlement_timeout_min(
    ) == TEST_SETTLE_TIMEOUT_MIN
    assert token_network_registry_proxy.settlement_timeout_max(
    ) == TEST_SETTLE_TIMEOUT_MAX

    bad_token_address = make_address()
    # try to register non-existing token network
    with pytest.raises(TransactionThrew):
        token_network_registry_proxy.add_token(bad_token_address)
    # create token network & register it
    test_token = deploy_token(
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        initial_amount=1000,
        decimals=0,
        token_name='TKN',
        token_symbol='TKN',
    )
    test_token_address = to_canonical_address(test_token.contract.address)
    event_filter = token_network_registry_proxy.tokenadded_filter()
    token_network_address = token_network_registry_proxy.add_token(
        test_token_address, )

    with pytest.raises(RaidenRecoverableError) as exc:
        token_network_address = token_network_registry_proxy.add_token(
            test_token_address, )

        assert 'Token already registered' in str(exc)

    logs = event_filter.get_all_entries()
    assert len(logs) == 1
    decoded_event = token_network_registry_proxy.proxy.decode_event(logs[0])
    assert is_same_address(decoded_event['args']['token_address'],
                           test_token.contract.address)
    assert is_same_address(
        decoded_event['args']['token_network_address'],
        token_network_address,
    )
    # test other getters
    assert token_network_registry_proxy.get_token_network(
        bad_token_address) is None
    assert is_same_address(
        token_network_registry_proxy.get_token_network(test_token_address),
        token_network_address,
    )

    with pytest.raises(ValueError):
        assert token_network_registry_proxy.get_token_network(None) is None

    assert token_network_registry_proxy.get_token_network(
        bad_token_address) is None
    assert token_network_registry_proxy.get_token_network(
        token_network_address) is None
    assert token_network_registry_proxy.get_token_network(
        test_token_address) is not None
Ejemplo n.º 11
0
def setup_raiden(
    transport,
    matrix_server,
    print_step,
    contracts_version,
    testchain_setup,
):
    print_step('Deploying Raiden contracts')

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

    token = deploy_token(
        deploy_client=client,
        contract_manager=contract_manager,
        initial_amount=1000,
        decimals=0,
        token_name='TKN',
        token_symbol='TKN',
    )
    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 = TokenNetworkRegistry(
        jsonrpc_client=client,
        registry_address=contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY],
        contract_manager=contract_manager,
    )

    if contracts_version == DEVELOPMENT_CONTRACT_VERSION:
        registry.add_token_with_limits(
            token_address=to_canonical_address(token.contract.address),
            channel_participant_deposit_limit=
            RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
            token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
        )
    else:
        registry.add_token_without_limits(token_address=to_canonical_address(
            token.contract.address), )

    print_step('Setting up Raiden')
    endpoint_registry_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_ENDPOINT_REGISTRY], )
    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':
        testchain_setup['keystore'],
        'endpoint_registry_contract_address':
        endpoint_registry_contract_address,
        'eth_rpc_endpoint':
        testchain_setup['eth_rpc_endpoint'],
        'gas_price':
        'fast',
        'keystore_path':
        testchain_setup['keystore'],
        'matrix_server':
        matrix_server,
        'network_id':
        str(NETWORKNAME_TO_ID['smoketest']),
        'password_file':
        click.File()(os.path.join(testchain_setup['base_datadir'], 'pw')),
        'tokennetwork_registry_contract_address':
        tokennetwork_registry_contract_address,
        'secret_registry_contract_address':
        secret_registry_contract_address,
        'sync_check':
        False,
        'transport':
        transport,
    }

    if contracts_version == DEVELOPMENT_CONTRACT_VERSION:
        service_registry_contract_address = to_checksum_address(
            contract_addresses[CONTRACT_SERVICE_REGISTRY], )
        args[
            'service_registry_contract_address'] = service_registry_contract_address

    return {
        'args': args,
        'contract_addresses': contract_addresses,
        'ethereum_nodes': testchain_setup['node_executors'],
        'token': token,
    }
def test_token_network_registry(
    deploy_client,
    contract_manager,
    token_network_registry_address,
):
    registry_address = to_canonical_address(token_network_registry_address)

    token_network_registry_proxy = TokenNetworkRegistry(
        jsonrpc_client=deploy_client,
        registry_address=registry_address,
        contract_manager=contract_manager,
    )

    assert token_network_registry_proxy.settlement_timeout_min(
    ) == TEST_SETTLE_TIMEOUT_MIN
    assert token_network_registry_proxy.settlement_timeout_max(
    ) == TEST_SETTLE_TIMEOUT_MAX

    bad_token_address = make_address()
    # try to register non-existing token network
    with pytest.raises(AddressWithoutCode):
        token_network_registry_proxy.add_token_with_limits(
            token_address=bad_token_address,
            channel_participant_deposit_limit=
            RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
            token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
        )
    # create token network & register it
    test_token = deploy_token(
        deploy_client=deploy_client,
        contract_manager=contract_manager,
        initial_amount=1000,
        decimals=0,
        token_name='TKN',
        token_symbol='TKN',
    )

    test_token_address = to_canonical_address(test_token.contract.address)
    # try to register a token network not following ERC20 protocol

    with patch.object(Token, 'total_supply', return_value=''):
        with pytest.raises(InvalidToken):
            token_network_registry_proxy.add_token_with_limits(
                token_address=test_token_address,
                channel_participant_deposit_limit=
                RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
                token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
            )

    event_filter = token_network_registry_proxy.tokenadded_filter()
    token_network_address = token_network_registry_proxy.add_token_with_limits(
        token_address=test_token_address,
        channel_participant_deposit_limit=
        RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
        token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
    )

    with pytest.raises(RaidenRecoverableError) as exc:
        token_network_address = token_network_registry_proxy.add_token_with_limits(
            token_address=test_token_address,
            channel_participant_deposit_limit=
            RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
            token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
        )

        assert 'Token already registered' in str(exc)

    logs = event_filter.get_all_entries()
    assert len(logs) == 1
    decoded_event = token_network_registry_proxy.proxy.decode_event(logs[0])
    assert is_same_address(decoded_event['args']['token_address'],
                           test_token.contract.address)
    assert is_same_address(
        decoded_event['args']['token_network_address'],
        token_network_address,
    )
    # test other getters
    assert token_network_registry_proxy.get_token_network(
        bad_token_address) is None
    assert is_same_address(
        token_network_registry_proxy.get_token_network(test_token_address),
        token_network_address,
    )

    with pytest.raises(ValueError):
        assert token_network_registry_proxy.get_token_network(None) is None

    assert token_network_registry_proxy.get_token_network(
        bad_token_address) is None
    assert token_network_registry_proxy.get_token_network(
        token_network_address) is None
    assert token_network_registry_proxy.get_token_network(
        test_token_address) is not None
Ejemplo n.º 13
0
def test_network_registry(token_network_registry_proxy: TokenNetworkRegistry, deploy_token):

    assert token_network_registry_proxy.settlement_timeout_min() == TEST_SETTLE_TIMEOUT_MIN
    assert token_network_registry_proxy.settlement_timeout_max() == TEST_SETTLE_TIMEOUT_MAX

    bad_token_address = make_address()
    # try to register non-existing token network
    with pytest.raises(TransactionThrew):
        token_network_registry_proxy.add_token(bad_token_address)
    # create token network & register it
    test_token = deploy_token(1000, 0, 'TKN', 'TKN')
    test_token_address = to_canonical_address(test_token.contract.address)
    event_filter = token_network_registry_proxy.tokenadded_filter()
    token_network_address = token_network_registry_proxy.add_token(
        test_token_address,
    )
    logs = event_filter.get_all_entries()
    assert len(logs) == 1
    decoded_event = token_network_registry_proxy.proxy.decode_event(logs[0])
    assert is_same_address(decoded_event['args']['token_address'], test_token.contract.address)
    assert is_same_address(
        decoded_event['args']['token_network_address'],
        token_network_address,
    )
    # test other getters
    assert token_network_registry_proxy.get_token_network(bad_token_address) is None
    assert is_same_address(
        token_network_registry_proxy.get_token_network(test_token_address),
        token_network_address,
    )

    with pytest.raises(ValueError):
        assert token_network_registry_proxy.get_token_network(None) is None

    assert token_network_registry_proxy.get_token_network(bad_token_address) is None
    assert token_network_registry_proxy.get_token_network(token_network_address) is None
    assert token_network_registry_proxy.get_token_network(test_token_address) is not None
Ejemplo n.º 14
0
def setup_raiden(transport, matrix_server, print_step, contracts_version,
                 testchain_setup):
    print_step("Deploying Raiden contracts")

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

    token = deploy_token(
        deploy_client=client,
        contract_manager=contract_manager,
        initial_amount=1000,
        decimals=0,
        token_name="TKN",
        token_symbol="TKN",
    )
    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 = TokenNetworkRegistry(
        jsonrpc_client=client,
        registry_address=contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY],
        contract_manager=contract_manager,
    )

    if contracts_version == DEVELOPMENT_CONTRACT_VERSION:
        registry.add_token_with_limits(
            token_address=to_canonical_address(token.contract.address),
            channel_participant_deposit_limit=
            RED_EYES_PER_CHANNEL_PARTICIPANT_LIMIT,
            token_network_deposit_limit=RED_EYES_PER_TOKEN_NETWORK_LIMIT,
        )
    else:
        registry.add_token_without_limits(
            token_address=to_canonical_address(token.contract.address))

    print_step("Setting up Raiden")
    endpoint_registry_contract_address = to_checksum_address(
        contract_addresses[CONTRACT_ENDPOINT_REGISTRY])
    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":
        testchain_setup["keystore"],
        "endpoint_registry_contract_address":
        endpoint_registry_contract_address,
        "eth_rpc_endpoint":
        testchain_setup["eth_rpc_endpoint"],
        "gas_price":
        "fast",
        "keystore_path":
        testchain_setup["keystore"],
        "matrix_server":
        matrix_server,
        "network_id":
        str(NETWORKNAME_TO_ID["smoketest"]),
        "password_file":
        click.File()(os.path.join(testchain_setup["base_datadir"], "pw")),
        "tokennetwork_registry_contract_address":
        tokennetwork_registry_contract_address,
        "secret_registry_contract_address":
        secret_registry_contract_address,
        "sync_check":
        False,
        "transport":
        transport,
    }

    if contracts_version == DEVELOPMENT_CONTRACT_VERSION:
        service_registry_contract_address = to_checksum_address(
            contract_addresses[CONTRACT_SERVICE_REGISTRY])
        args[
            "service_registry_contract_address"] = service_registry_contract_address

    return {
        "args": args,
        "contract_addresses": contract_addresses,
        "ethereum_nodes": testchain_setup["node_executors"],
        "token": token,
    }
Ejemplo n.º 15
0
def test_network_registry(token_network_registry_proxy: TokenNetworkRegistry,
                          deploy_token):

    assert token_network_registry_proxy.settlement_timeout_min(
    ) == TEST_SETTLE_TIMEOUT_MIN
    assert token_network_registry_proxy.settlement_timeout_max(
    ) == TEST_SETTLE_TIMEOUT_MAX

    bad_token_address = make_address()
    # try to register non-existing token network
    with pytest.raises(TransactionThrew):
        token_network_registry_proxy.add_token(bad_token_address)
    # create token network & register it
    test_token = deploy_token(1000, 0, 'TKN', 'TKN')
    test_token_address = to_canonical_address(test_token.contract.address)
    event_filter = token_network_registry_proxy.tokenadded_filter()
    token_network_address = token_network_registry_proxy.add_token(
        test_token_address, )
    logs = event_filter.get_all_entries()
    assert len(logs) == 1
    decoded_event = token_network_registry_proxy.proxy.decode_event(logs[0])
    assert is_same_address(decoded_event['args']['token_address'],
                           test_token.contract.address)
    assert is_same_address(
        decoded_event['args']['token_network_address'],
        token_network_address,
    )
    # test other getters
    assert token_network_registry_proxy.get_token_network(
        bad_token_address) is None
    assert is_same_address(
        token_network_registry_proxy.get_token_network(test_token_address),
        token_network_address,
    )

    with pytest.raises(AddressWithoutCode):
        token_network_registry_proxy.token_network_by_token(bad_token_address)
    with pytest.raises(InvalidAddress):
        token_network_registry_proxy.token_network_by_token(None)
    with pytest.raises(NoTokenManager):
        token_network_registry_proxy.token_network_by_token(
            token_network_address)
    token_manager = token_network_registry_proxy.token_network_by_token(
        test_token_address, )
    assert token_manager is not None