def token_contract(deploy_client, contract_manager): return deploy_token( deploy_client=deploy_client, contract_manager=contract_manager, initial_amount=10000, decimals=0, token_name='TKN', token_symbol='TKN', )
def token_contract(deploy_client, contract_manager): return deploy_token( deploy_client=deploy_client, contract_manager=contract_manager, initial_amount=10000, decimals=0, token_name='TKN', token_symbol='TKN', )
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 deploy_token_and_return_proxy(deploy_client, contract_manager): token_contract = deploy_token( deploy_client=deploy_client, contract_manager=contract_manager, initial_amount=10000, decimals=0, token_name="TKN", token_symbol="TKN", ) return Token( jsonrpc_client=deploy_client, token_address=to_canonical_address(token_contract.contract.address), contract_manager=contract_manager, )
def deploy_token_and_return_proxy(deploy_client: JSONRPCClient, contract_manager: ContractManager, token_contract_name: str) -> Token: token_contract = deploy_token( deploy_client=deploy_client, contract_manager=contract_manager, initial_amount=TokenAmount(1000 * 10**18), decimals=0, token_name="TKN", token_symbol="TKN", token_contract_name=token_contract_name, ) return Token( jsonrpc_client=deploy_client, token_address=TokenAddress(token_contract.contract_address), contract_manager=contract_manager, )
def setup_raiden( transport, matrix_server, print_step, contracts_version, testchain_setup, ): print_step('Deploying Raiden contracts') client = JSONRPCClient(testchain_setup['web3'], get_private_key(testchain_setup['keystore'])) contract_manager = ContractManager( contracts_precompiled_path(contracts_version), ) contract_addresses = deploy_smoketest_contracts( client=client, chain_id=NETWORKNAME_TO_ID['smoketest'], contract_manager=contract_manager, ) token = deploy_token( deploy_client=client, contract_manager=contract_manager, initial_amount=1000, decimals=0, token_name='TKN', token_symbol='TKN', ) registry = TokenNetworkRegistry( jsonrpc_client=client, registry_address=contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY], contract_manager=contract_manager, ) registry.add_token( token_address=to_canonical_address(token.contract.address), given_block_identifier='latest', ) 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], ) return { '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, }, 'contract_addresses': contract_addresses, 'ethereum': testchain_setup['processes_list'], 'token': token, }
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
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: 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, )
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 setup_testchain_and_raiden(transport, matrix_server, print_step): print_step('Starting Ethereum node') ensure_executable('geth') free_port = get_free_port('127.0.0.1', 27854) rpc_port = next(free_port) p2p_port = next(free_port) base_datadir = os.environ['RST_DATADIR'] description = GethNodeDescription( private_key=TEST_PRIVKEY, rpc_port=rpc_port, p2p_port=p2p_port, miner=True, ) eth_rpc_endpoint = f'http://127.0.0.1:{rpc_port}' web3 = Web3(HTTPProvider(endpoint_uri=eth_rpc_endpoint)) web3.middleware_stack.inject(geth_poa_middleware, layer=0) config = geth_node_config( description.private_key, description.p2p_port, description.rpc_port, ) config.update({ 'unlock': 0, 'mine': True, 'password': os.path.join(base_datadir, 'pw'), }) nodes_configuration = [config] geth_node_config_set_bootnodes(nodes_configuration) keystore = os.path.join(geth_node_to_datadir(config, base_datadir), 'keystore') logdir = os.path.join(base_datadir, 'logs') processes_list = geth_run_nodes( geth_nodes=[description], nodes_configuration=nodes_configuration, base_datadir=base_datadir, genesis_file=os.path.join(get_project_root(), 'smoketest_genesis.json'), chain_id=NETWORKNAME_TO_ID['smoketest'], verbosity=0, logdir=logdir, ) try: # the marker is hardcoded in the genesis file random_marker = remove_0x_prefix(encode_hex(b'raiden')) geth_wait_and_check(web3, [], random_marker) for process in processes_list: process.poll() if process.returncode is not None: raise ValueError( f'geth process failed with exit code {process.returncode}') except (ValueError, RuntimeError) as e: # If geth_wait_and_check or the above loop throw an exception make sure # we don't end up with a rogue geth process running in the background for process in processes_list: process.terminate() raise e print_step('Deploying Raiden contracts') client = JSONRPCClient(web3, get_private_key(keystore)) # for smoketest use the precompiled contracts contract_manager = ContractManager(contracts_precompiled_path()) contract_addresses = deploy_smoketest_contracts( client=client, chain_id=NETWORKNAME_TO_ID['smoketest'], contract_manager=contract_manager, ) token = deploy_token( deploy_client=client, contract_manager=contract_manager, initial_amount=1000, decimals=0, token_name='TKN', token_symbol='TKN', ) registry = TokenNetworkRegistry( jsonrpc_client=client, registry_address=contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY], contract_manager=contract_manager, ) registry.add_token(to_canonical_address(token.contract.address)) print_step('Setting up Raiden') if matrix_server == 'auto': matrix_server = 'http://localhost:8008' 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], ) return { 'args': { 'address': to_checksum_address(TEST_ACCOUNT_ADDRESS), 'datadir': keystore, 'endpoint_registry_contract_address': endpoint_registry_contract_address, '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, }, 'contract_addresses': contract_addresses, 'ethereum': processes_list, 'token': token, }
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)
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 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 }