def test_is_ropsten_chain(monkeypatch, platform, data_dir, should_be_ropsten): monkeypatch.setattr('sys.platform', platform) if platform == "win32": monkeypatch.setattr('os.path.sep', '\\') expanded_data_dir = os.path.expanduser(data_dir) relative_data_dir = os.path.relpath(expanded_data_dir) assert is_ropsten_chain(data_dir) is should_be_ropsten assert is_ropsten_chain(expanded_data_dir) is should_be_ropsten assert is_ropsten_chain(relative_data_dir) is should_be_ropsten
def __init__(self, config_root: str = None, overrides: dict = None, *args, **kwargs): log = Logger('nucypher-geth-devnet') if overrides is None: overrides = dict() # Validate invalid_override = f"You cannot specify `network_id` for a {self.__class__.__name__}" if 'data_dir' in overrides: raise ValueError(invalid_override) if 'network_id' in overrides: raise ValueError(invalid_override) # Set the data dir if config_root is None: base_dir = os.path.join(DEFAULT_CONFIG_ROOT, '.ethereum') else: base_dir = os.path.join(config_root, '.ethereum') self.data_dir = get_chain_data_dir(base_dir=base_dir, name=self._CHAIN_NAME) # Hardcoded Geth CLI args for devnet child process ("light client") ipc_path = os.path.join(self.data_dir, self.IPC_FILENAME) geth_kwargs = { 'network_id': str(self.__CHAIN_ID), 'port': str(self.P2P_PORT), 'verbosity': str(self.VERBOSITY), 'data_dir': self.data_dir, 'ipc_path': ipc_path, 'rpc_enabled': True, 'no_discover': True, } # Genesis & Blockchain Init self.genesis_filepath = os.path.join(self.data_dir, self.GENESIS_FILENAME) needs_init = all(( not os.path.exists(self.genesis_filepath), not is_live_chain(self.data_dir), not is_ropsten_chain(self.data_dir), )) if needs_init: log.debug("Local system needs geth blockchain initialization") self.initialized = False else: self.initialized = True self.__process = NOT_RUNNING super().__init__(geth_kwargs=geth_kwargs, *args, **kwargs) # Attaches self.geth_kwargs in super call self.command = [*self.command, '--syncmode', 'fast']
def __init__(self, config_root: str = None, overrides: dict = None, *args, **kwargs): if overrides is None: overrides = dict() # Validate invalid_override = f"You cannot specify `data_dir` or `network_id` for a {self.__class__.__name__}" if 'data_dir' in overrides: raise ValueError(invalid_override) if 'network_id' in overrides: raise ValueError(invalid_override) # Set the data dir if config_root is None: base_dir = os.path.join(DEFAULT_CONFIG_ROOT, '.ethereum') else: base_dir = os.path.join(config_root, '.ethereum') self.data_dir = get_chain_data_dir(base_dir=base_dir, name=self._CHAIN_NAME) # Hardcoded Geth CLI args for devnet child process ("light client") ipc_path = os.path.join(self.data_dir, self.IPC_FILENAME) geth_kwargs = { 'port': str(self.P2P_PORT), 'verbosity': str(self.VERBOSITY), 'data_dir': self.data_dir, 'ipc_path': ipc_path, 'rpc_enabled': True, 'no_discover': False, } # Genesis & Blockchain Init all_good = all((not is_ropsten_chain(self.data_dir), )) if not all_good: raise RuntimeError('Unintentional connection to Ropsten') self.__process = NOT_RUNNING super().__init__(geth_kwargs=geth_kwargs, *args, **kwargs) # Attaches self.geth_kwargs in super call self.command = [*self.command, '--syncmode', 'fast', '--goerli']
def __init__(self, chain_name, base_dir=None, overrides=None, genesis_data=None): if overrides is None: overrides = {} if genesis_data is None: genesis_data = {} if 'data_dir' in overrides: raise ValueError( "You cannot specify `data_dir` for a DevGethProcess") if base_dir is None: base_dir = get_default_base_dir() self.data_dir = get_chain_data_dir(base_dir, chain_name) geth_kwargs = construct_test_chain_kwargs(data_dir=self.data_dir, **overrides) # ensure that an account is present coinbase = ensure_account_exists(**geth_kwargs) # ensure that the chain is initialized genesis_file_path = get_genesis_file_path(self.data_dir) needs_init = all(( not os.path.exists(genesis_file_path), not is_live_chain(self.data_dir), not is_ropsten_chain(self.data_dir), )) if needs_init: genesis_data.setdefault( 'alloc', dict([ (coinbase, { "balance": "1000000000000000000000000000000" }), # 1 billion ether. ])) initialize_chain(genesis_data, **geth_kwargs) super(DevGethProcess, self).__init__(geth_kwargs)
def __init__(self, chain_name, base_dir=None, overrides=None, genesis_data=None): if overrides is None: overrides = {} if genesis_data is None: genesis_data = {} if 'data_dir' in overrides: raise ValueError("You cannot specify `data_dir` for a DevGethProcess") if base_dir is None: base_dir = get_default_base_dir() self.data_dir = get_chain_data_dir(base_dir, chain_name) geth_kwargs = construct_test_chain_kwargs( data_dir=self.data_dir, **overrides ) # ensure that an account is present coinbase = ensure_account_exists(**geth_kwargs) # ensure that the chain is initialized genesis_file_path = get_genesis_file_path(self.data_dir) needs_init = all(( not os.path.exists(genesis_file_path), not is_live_chain(self.data_dir), not is_ropsten_chain(self.data_dir), )) if needs_init: genesis_data.setdefault( 'alloc', dict([ (coinbase, {"balance": "1000000000000000000000000000000"}), # 1 billion ether. ]) ) initialize_chain(genesis_data, **geth_kwargs) super(DevGethProcess, self).__init__(geth_kwargs)