Exemplo n.º 1
0
def initialize_data_dir(chain_config: ChainConfig) -> None:
    should_create_data_dir = (not chain_config.data_dir.exists()
                              and is_under_path(chain_config.helios_root_dir,
                                                chain_config.data_dir))
    if should_create_data_dir:
        chain_config.data_dir.mkdir(parents=True, exist_ok=True)
    elif not chain_config.data_dir.exists():
        # we don't lazily create the base dir for non-default base directories.
        raise MissingPath(
            "The base chain directory provided does not exist: `{0}`".format(
                chain_config.data_dir, ), chain_config.data_dir)

    # Logfile
    should_create_logdir = (not chain_config.logdir_path.exists()
                            and is_under_path(chain_config.helios_root_dir,
                                              chain_config.logdir_path))
    if should_create_logdir:
        chain_config.logdir_path.mkdir(parents=True, exist_ok=True)
        chain_config.logfile_path.touch()
    elif not chain_config.logdir_path.exists():
        # we don't lazily create the base dir for non-default base directories.
        raise MissingPath(
            "The base logging directory provided does not exist: `{0}`".format(
                chain_config.logdir_path, ), chain_config.logdir_path)

    # Chain data-dir
    os.makedirs(chain_config.database_dir, exist_ok=True)

    # Nodekey
    if chain_config.nodekey is None:
        nodekey = ecies.generate_privkey()
        with open(chain_config.nodekey_path, 'wb') as nodekey_file:
            nodekey_file.write(nodekey.to_bytes())
Exemplo n.º 2
0
def xdg_trinity_root(monkeypatch, tmpdir):
    """
    Ensure proper test isolation as well as protecting the real directories.
    """
    dir_path = tmpdir.mkdir('helios')
    monkeypatch.setenv('XDG_TRINITY_ROOT', str(dir_path))

    assert not is_under_path(os.path.expandvars('$HOME'), get_xdg_trinity_root())

    return Path(str(dir_path))
def test_chain_config_computed_properties_custom_xdg(tmpdir, xdg_helios_root):
    alt_xdg_root = tmpdir.mkdir('helios-custom')
    assert not is_under_path(alt_xdg_root, xdg_helios_root)

    data_dir = get_data_dir_for_network_id(1, alt_xdg_root)
    chain_config = ChainConfig(helios_root_dir=alt_xdg_root, network_id=1)

    assert chain_config.network_id == 1
    assert chain_config.data_dir == data_dir
    assert chain_config.database_dir == data_dir / DATABASE_DIR_NAME / "full"
    assert chain_config.nodekey_path == get_nodekey_path(data_dir)
def test_is_under_path(base_path, path, expected):
    actual = is_under_path(base_path, path)
    assert actual is expected