def mk_genesis(accounts, initial_alloc=denoms.ether * 100000000): """ Create a genesis-block dict with allocation for all `accounts`. :param accounts: list of account addresses (hex) :param initial_alloc: the amount to allocate for the `accounts` :return: genesis dict """ genesis = GENESIS_STUB.copy() genesis['extraData'] = CLUSTER_NAME genesis['alloc'] = { account: { 'balance': str(initial_alloc) } for account in accounts } # add the one-privatekey account ("1" * 64) for convenience genesis['alloc']['19e7e376e7c213b7e7e7e46cc70a5dd086daff2a'] = dict(balance=str(initial_alloc)) return genesis
def mk_genesis(accounts, initial_alloc=denoms.ether * 100000000): """ Create a genesis-block dict with allocation for all `accounts`. :param accounts: list of account addresses (hex) :param initial_alloc: the amount to allocate for the `accounts` :return: genesis dict """ genesis = GENESIS_STUB.copy() genesis['extraData'] = '0x' + hexlify(CLUSTER_NAME) genesis['alloc'].update( {account: { 'balance': str(initial_alloc), } for account in accounts}) # add the one-privatekey account ("1" * 64) for convenience genesis['alloc']['19e7e376e7c213b7e7e7e46cc70a5dd086daff2a'] = dict( balance=str(initial_alloc)) return genesis
def cached_genesis(request, blockchain_type): """ Deploy all contracts that are required by the fixtures into a tester and then serialize the accounts into a genesis block. Returns: dict: A dictionary representing the genesis block. """ if not request.config.option.blockchain_cache: return # cannot cache for mock blockchain if blockchain_type == 'mock': return # this will create the tester _and_ deploy the Registry deploy_key = request.getfixturevalue('deploy_key') private_keys = request.getfixturevalue('private_keys') deploy_service, blockchain_services = _tester_services( deploy_key, private_keys, request.getfixturevalue('tester_blockgas_limit'), ) # create_network only registers the tokens, # the contracts must be deployed previously register = True token_contract_addresses = _token_addresses( request.getfixturevalue('token_amount'), request.getfixturevalue('number_of_tokens'), deploy_service, blockchain_services, register) raiden_apps = create_apps( blockchain_services, request.getfixturevalue('raiden_udp_ports'), DummyTransport, # Do not use a UDP server to avoid port reuse in MacOSX request.config.option.verbose, request.getfixturevalue('send_ping_time'), request.getfixturevalue('max_unresponsive_time'), request.getfixturevalue('reveal_timeout'), request.getfixturevalue('settle_timeout'), ) if 'raiden_network' in request.fixturenames: create_network_channels( raiden_apps, token_contract_addresses, request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) elif 'raiden_chain' in request.fixturenames: create_sequential_channels( raiden_apps, token_contract_addresses[0], request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) # else: a test that is not creating channels for app in raiden_apps: app.stop() # save the state from the last block into a genesis dict tester = blockchain_services[0].tester_state tester.mine() registry_address = blockchain_services[0].default_registry.address genesis_alloc = dict() for account_address in tester.block.state.to_dict(): account_alloc = tester.block.account_to_dict(account_address) # Both keys and values of the account storage associative array # must now be encoded with 64 hex digits if account_alloc['storage']: new_storage = dict() for key, val in account_alloc['storage'].iteritems(): # account_to_dict() from pyethereum can return 0x for a storage # position. That is an invalid way of representing 0x0, which we # have to take care of here. new_key = '0x%064x' % int(key if key != '0x' else '0x0', 16) new_val = '0x%064x' % int(val, 16) new_storage[new_key] = new_val account_alloc['storage'] = new_storage # code must be hex encoded with 0x prefix account_alloc['code'] = account_alloc.get('code', '') # account_to_dict returns accounts with nonce=0 and the nonce must # be encoded with 16 hex digits account_alloc['nonce'] = '0x%016x' % tester.block.get_nonce( account_address) genesis_alloc[account_address] = account_alloc account_addresses = [ privatekey_to_address(key) for key in set(private_keys) ] for address in account_addresses: genesis_alloc[address]['balance'] = DEFAULT_BALANCE_BIN alloc = { address_encoder(address_maybe_bin): data for address_maybe_bin, data in genesis_alloc.iteritems() } genesis = GENESIS_STUB.copy() genesis['alloc'] = alloc genesis['config']['defaultRegistryAddress'] = address_encoder( registry_address) genesis['config']['tokenAddresses'] = [ address_encoder(token_address) for token_address in token_contract_addresses ] return genesis
def cached_genesis(request, blockchain_type): """ Deploy all contracts that are required by the fixtures into a tester and then serialize the accounts into a genesis block. Returns: dict: A dictionary representing the genesis block. """ if not request.config.option.blockchain_cache: return if blockchain_type != 'geth': return # this will create the tester _and_ deploy the Registry deploy_key = request.getfixturevalue('deploy_key') private_keys = request.getfixturevalue('private_keys') deploy_service, blockchain_services = _tester_services( deploy_key, private_keys, request.getfixturevalue('tester_blockgas_limit'), ) # create_network only registers the tokens, # the contracts must be deployed previously register = True participants = [privatekey_to_address(privatekey) for privatekey in private_keys] token_contract_addresses = _token_addresses( request.getfixturevalue('token_amount'), request.getfixturevalue('number_of_tokens'), deploy_service, participants, register ) endpoint_discovery_address = deploy_service.deploy_contract( 'EndpointRegistry', 'EndpointRegistry.sol', ) endpoint_discovery_services = [ ContractDiscovery( chain.node_address, chain.discovery(endpoint_discovery_address), ) for chain in blockchain_services ] raiden_apps = create_apps( blockchain_services, endpoint_discovery_services, request.getfixturevalue('raiden_udp_ports'), DummyTransport, # Do not use a UDP server to avoid port reuse in MacOSX request.getfixturevalue('reveal_timeout'), request.getfixturevalue('settle_timeout'), request.getfixturevalue('database_paths'), request.getfixturevalue('retry_interval'), request.getfixturevalue('retries_before_backoff'), request.getfixturevalue('throttle_capacity'), request.getfixturevalue('throttle_fill_rate'), request.getfixturevalue('nat_invitation_timeout'), request.getfixturevalue('nat_keepalive_retries'), request.getfixturevalue('nat_keepalive_timeout'), ) if 'raiden_network' in request.fixturenames: create_network_channels( raiden_apps, token_contract_addresses, request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) elif 'raiden_chain' in request.fixturenames: create_sequential_channels( raiden_apps, token_contract_addresses[0], request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) # else: a test that is not creating channels for app in raiden_apps: app.stop(leave_channels=False) # save the state from the last block into a genesis dict tester = blockchain_services[0].tester_state tester.mine() registry_address = blockchain_services[0].default_registry.address genesis_alloc = dict() for account_address in tester.block.state.to_dict(): account_alloc = tester.block.account_to_dict(account_address) # Both keys and values of the account storage associative array # must now be encoded with 64 hex digits if account_alloc['storage']: account_alloc['storage'] = fix_tester_storage(account_alloc['storage']) # code must be hex encoded with 0x prefix account_alloc['code'] = account_alloc.get('code', '') # account_to_dict returns accounts with nonce=0 and the nonce must # be encoded with 16 hex digits account_alloc['nonce'] = '0x%016x' % tester.block.get_nonce(account_address) genesis_alloc[account_address] = account_alloc all_keys = set(private_keys) all_keys.add(deploy_key) all_keys = sorted(all_keys) account_addresses = [ privatekey_to_address(key) for key in all_keys ] for address in account_addresses: genesis_alloc[address]['balance'] = DEFAULT_BALANCE_BIN alloc = { address_encoder(address_maybe_bin): data for address_maybe_bin, data in genesis_alloc.iteritems() } genesis = GENESIS_STUB.copy() genesis['config']['clique'] = {'period': 1, 'epoch': 30000} random_marker = request.getfixturevalue('random_marker') genesis['extraData'] = clique_extradata( random_marker, address_encoder(account_addresses[0])[2:], ) genesis['alloc'] = alloc genesis['config']['defaultDiscoveryAddress'] = address_encoder(endpoint_discovery_address) genesis['config']['defaultRegistryAddress'] = address_encoder(registry_address) genesis['config']['tokenAddresses'] = [ address_encoder(token_address) for token_address in token_contract_addresses ] return genesis
def cached_genesis(request, blockchain_type): """ Deploy all contracts that are required by the fixtures into a tester and then serialize the accounts into a genesis block. Returns: dict: A dictionary representing the genesis block. """ if not request.config.option.blockchain_cache: return # cannot cache for mock blockchain if blockchain_type == 'mock': return # this will create the tester _and_ deploy the Registry deploy_key = request.getfixturevalue('deploy_key') private_keys = request.getfixturevalue('private_keys') deploy_service, blockchain_services = _tester_services( deploy_key, private_keys, request.getfixturevalue('tester_blockgas_limit'), ) # create_network only registers the tokens, # the contracts must be deployed previously token_contract_addresses = _tokens_addresses( request.getfixturevalue('token_amount'), request.getfixturevalue('number_of_tokens'), deploy_service, blockchain_services, ) raiden_apps = create_apps( blockchain_services, request.getfixturevalue('raiden_udp_ports'), DummyTransport, # Do not use a UDP server to avoid port reuse in MacOSX request.config.option.verbose, request.getfixturevalue('send_ping_time'), request.getfixturevalue('max_unresponsive_time'), request.getfixturevalue('reveal_timeout'), ) if 'raiden_network' in request.fixturenames: create_network_channels( raiden_apps, token_contract_addresses, request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) elif 'raiden_chain' in request.fixturenames: create_sequential_channels( raiden_apps, token_contract_addresses[0], request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) # else: a test that is not creating channels for app in raiden_apps: app.stop() # save the state from the last block into a genesis dict tester = blockchain_services[0].tester_state tester.mine() registry_address = blockchain_services[0].default_registry.address genesis_alloc = dict() for account_address in tester.block.state.to_dict(): account_alloc = tester.block.account_to_dict(account_address) # code must be hex encoded without 0x prefix account_alloc['code'] = safe_lstrip_hex(account_alloc.get('code', '')) # account_to_dict returns accounts with nonce=0 account_alloc['nonce'] = tester.block.get_nonce(account_address) genesis_alloc[account_address] = account_alloc account_addresses = [ privatekey_to_address(key) for key in set(private_keys) ] for address in account_addresses: genesis_alloc[address]['balance'] = DEFAULT_BALANCE_BIN alloc = { safe_lstrip_hex(address_encoder(address_maybe_bin)): data for address_maybe_bin, data in genesis_alloc.iteritems() } genesis = GENESIS_STUB.copy() genesis['alloc'] = alloc genesis['config']['defaultRegistryAddress'] = address_encoder( registry_address) genesis['config']['tokenAddresses'] = [ address_encoder(token_address) for token_address in token_contract_addresses ] return genesis
def cached_genesis(request, blockchain_type): """ Deploy all contracts that are required by the fixtures into a tester and then serialize the accounts into a genesis block. Returns: dict: A dictionary representing the genesis block. """ if not request.config.option.blockchain_cache: return # cannot cache for mock blockchain if blockchain_type == 'mock': return # this will create the tester _and_ deploy the Registry deploy_key = request.getfixturevalue('deploy_key') private_keys = request.getfixturevalue('private_keys') deploy_service, blockchain_services = _tester_services( deploy_key, private_keys, request.getfixturevalue('tester_blockgas_limit'), ) # create_network only register the assets, the contracts must be deployed # previously asset_contract_addresses = _assets_addresses( request.getfixturevalue('asset_amount'), request.getfixturevalue('number_of_assets'), deploy_service, blockchain_services, ) raiden_apps = create_apps( blockchain_services, request.getfixturevalue('transport_class'), request.config.option.verbose, request.getfixturevalue('send_ping_time'), request.getfixturevalue('max_unresponsive_time'), ) if 'raiden_network' in request.fixturenames: create_network_channels( raiden_apps, asset_contract_addresses, request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) elif 'raiden_chain' in request.fixturenames: create_sequential_channels( raiden_apps, asset_contract_addresses[0], request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) # else: a test that is not creating channels for app in raiden_apps: app.stop() # save the state from the last block into a genesis dict tester = blockchain_services[0].tester_state tester.mine() registry_address = blockchain_services[0].default_registry.address genesis_alloc = dict() for account_address in tester.block.state.to_dict(): account_alloc = tester.block.account_to_dict(account_address) # code must be hex encoded without 0x prefix account_alloc['code'] = safe_lstrip_hex(account_alloc.get('code', '')) # account_to_dict returns accounts with nonce=0 account_alloc['nonce'] = tester.block.get_nonce(account_address) genesis_alloc[account_address] = account_alloc account_addresses = [ privatekey_to_address(key) for key in set(private_keys) ] for address in account_addresses: genesis_alloc[address]['balance'] = DEFAULT_BALANCE_BIN alloc = { safe_lstrip_hex(address_encoder(address_maybe_bin)): data for address_maybe_bin, data in genesis_alloc.iteritems() } genesis = GENESIS_STUB.copy() genesis['alloc'] = alloc genesis['config']['defaultRegistryAddress'] = address_encoder(registry_address) genesis['config']['assetAddresses'] = [ address_encoder(asset_address) for asset_address in asset_contract_addresses ] return genesis
def cached_genesis(request): """ Deploy all contracts that are required by the fixtures into a tester and then serialize the accounts into a genesis block. Returns: dict: A dictionary representing the genesis block. """ if not request.config.option.blockchain_cache: return # this will create the tester _and_ deploy the Registry deploy_key = request.getfixturevalue('deploy_key') private_keys = request.getfixturevalue('private_keys') registry, deploy_service, blockchain_services = _tester_services( deploy_key, private_keys, request.getfixturevalue('tester_blockgas_limit'), ) registry_address = registry.address # create_network only registers the tokens, # the contracts must be deployed previously register = True participants = [privatekey_to_address(privatekey) for privatekey in private_keys] token_contract_addresses = _token_addresses( request.getfixturevalue('token_amount'), request.getfixturevalue('number_of_tokens'), deploy_service, registry, participants, register ) endpoint_discovery_address = deploy_service.deploy_contract( 'EndpointRegistry', get_contract_path('EndpointRegistry.sol'), ) endpoint_discovery_services = [ ContractDiscovery( chain.node_address, chain.discovery(endpoint_discovery_address), ) for chain in blockchain_services ] raiden_apps = create_apps( blockchain_services, endpoint_discovery_services, registry_address, request.getfixturevalue('raiden_udp_ports'), DummyTransport, # Do not use a UDP server to avoid port reuse in MacOSX request.getfixturevalue('reveal_timeout'), request.getfixturevalue('settle_timeout'), request.getfixturevalue('database_paths'), request.getfixturevalue('retry_interval'), request.getfixturevalue('retries_before_backoff'), request.getfixturevalue('throttle_capacity'), request.getfixturevalue('throttle_fill_rate'), request.getfixturevalue('nat_invitation_timeout'), request.getfixturevalue('nat_keepalive_retries'), request.getfixturevalue('nat_keepalive_timeout'), ) if 'raiden_network' in request.fixturenames: create_network_channels( raiden_apps, token_contract_addresses, request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) elif 'raiden_chain' in request.fixturenames: create_sequential_channels( raiden_apps, token_contract_addresses[0], request.getfixturevalue('channels_per_node'), request.getfixturevalue('deposit'), request.getfixturevalue('settle_timeout'), ) # else: a test that is not creating channels for app in raiden_apps: app.stop(leave_channels=False) # save the state from the last block into a genesis dict tester = blockchain_services[0].tester_chain tester.mine() genesis_alloc = dict() for account_address in tester.head_state.to_dict(): account_alloc = tester.head_state.account_to_dict(account_address) # Both keys and values of the account storage associative array # must now be encoded with 64 hex digits if account_alloc['storage']: account_alloc['storage'] = fix_tester_storage(account_alloc['storage']) # code must be hex encoded with 0x prefix account_alloc['code'] = account_alloc.get('code', '') # account_to_dict returns accounts with nonce=0 and the nonce must # be encoded with 16 hex digits account_alloc['nonce'] = '0x%016x' % tester.head_state.get_nonce(account_address) genesis_alloc[account_address] = account_alloc all_keys = set(private_keys) all_keys.add(deploy_key) all_keys = sorted(all_keys) account_addresses = [ privatekey_to_address(key) for key in all_keys ] for address in account_addresses: address_hex = hexlify(address).decode() genesis_alloc[address_hex]['balance'] = DEFAULT_BALANCE_BIN genesis = GENESIS_STUB.copy() genesis['config']['clique'] = {'period': 1, 'epoch': 30000} random_marker = request.getfixturevalue('random_marker') genesis['extraData'] = clique_extradata( random_marker, address_encoder(account_addresses[0])[2:], ) genesis['alloc'] = genesis_alloc genesis['config']['defaultDiscoveryAddress'] = address_encoder(endpoint_discovery_address) genesis['config']['defaultRegistryAddress'] = address_encoder(registry_address) genesis['config']['tokenAddresses'] = [ address_encoder(token_address) for token_address in token_contract_addresses ] return genesis