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()
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
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
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
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, ) 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
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
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
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(RaidenUnrecoverableError): token_network_registry_proxy.add_token(bad_token_address, 'latest') # 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( token_address=test_token_address, given_block_identifier='latest', ) with pytest.raises(RaidenRecoverableError) as exc: token_network_address = token_network_registry_proxy.add_token( token_address=test_token_address, given_block_identifier='latest', ) 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