예제 #1
0
def initialize_data_dir(trinity_config: TrinityConfig) -> None:
    should_create_data_dir = (not trinity_config.data_dir.exists()
                              and is_under_path(
                                  trinity_config.trinity_root_dir,
                                  trinity_config.data_dir))
    if should_create_data_dir:
        trinity_config.data_dir.mkdir(parents=True, exist_ok=True)
    elif not trinity_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(
                trinity_config.data_dir, ), trinity_config.data_dir)

    # Logfile
    should_create_logdir = (not trinity_config.logdir_path.exists()
                            and is_under_path(trinity_config.trinity_root_dir,
                                              trinity_config.logdir_path))
    if should_create_logdir:
        trinity_config.logdir_path.mkdir(parents=True, exist_ok=True)
        trinity_config.logfile_path.touch()
    elif not trinity_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(
                trinity_config.logdir_path, ), trinity_config.logdir_path)

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

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

    assert not is_under_path(XDG_DATA_HOME, get_xdg_trinity_root())

    return str(dir_path)
예제 #3
0
def xdg_trinity_root(monkeypatch, tmpdir):
    """
    Ensure proper test isolation as well as protecting the real directories.
    """
    dir_path = tmpdir.mkdir('xdg_trinity_root')
    monkeypatch.setenv('XDG_TRINITY_ROOT', str(dir_path))

    assert not is_under_path(XDG_DATA_HOME, get_xdg_trinity_root())

    return str(dir_path)
예제 #4
0
def xdg_trinity_root(monkeypatch, tmpdir):
    """
    Ensure proper test isolation as well as protecting the real directories.
    """
    dir_path = tmpdir.mkdir('trinity')
    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))
예제 #5
0
def test_chain_config_computed_properties_custom_xdg(tmpdir, xdg_trinity_root):
    alt_xdg_root = tmpdir.mkdir('trinity-custom')
    assert not is_under_path(alt_xdg_root, xdg_trinity_root)

    data_dir = get_data_dir_for_network_id(1, alt_xdg_root)
    chain_config = TrinityConfig(trinity_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)
예제 #6
0
def test_is_under_path_not_strict(base_path, path, expected):
    actual = is_under_path(base_path, path, strict=False)
    assert actual is expected
예제 #7
0
def test_is_under_path(base_path, path, expected):
    actual = is_under_path(base_path, path)
    assert actual is expected