Ejemplo n.º 1
0
def test_config_with_ethpm_dir_env_var(tmpdir, namespace, monkeypatch):
    ethpm_dir = Path(tmpdir) / ETHPM_PACKAGES_DIR
    monkeypatch.setenv(ETHPM_DIR_ENV_VAR, str(ethpm_dir))
    namespace.ethpm_dir = None
    config = Config(namespace)
    assert config.ethpm_dir == ethpm_dir
    assert isinstance(config.ethpm_dir, Path)
Ejemplo n.º 2
0
def release_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    release_package(args.package_name, args.package_version, args.manifest_uri, config)
    active_registry = get_active_registry(config.xdg_ethpmcli_root / REGISTRY_STORE)
    cli_logger.info(
        f"{args.package_name} v{args.package_version} @ {args.manifest_uri} "
        f"released to registry @ {active_registry.uri}."
    )
Ejemplo n.º 3
0
def auth_action(args: argparse.Namespace) -> None:
    Config(args)
    try:
        authorized_address = get_authorized_address()
        cli_logger.info(f"Keyfile stored for address: 0x{authorized_address}.")
    except AuthorizationError:
        cli_logger.info(
            "No valid keyfile found. Use `ethpm auth --keyfile-path <path_to_keyfile>` "
            "to set your keyfile for use with ethPM CLI.")
Ejemplo n.º 4
0
def registry_deploy_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    registry_address = deploy_registry(config, args.alias)
    chain_name = SUPPORTED_CHAIN_IDS[config.w3.eth.chainId]
    explorer_uri = f"http://explorer.ethpm.com/browse/{chain_name}/{registry_address}"
    cli_logger.info(
        f"Congrats on your new ethPM registry! Check it out @ {explorer_uri}.")
    cli_logger.info(
        "You can now release a package on your registry with `ethpm release`.")
Ejemplo n.º 5
0
def registry_add_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    add_registry(args.uri, args.alias, config)
    if args.alias:
        log_msg = (
            f"Registry @ {args.uri} (alias: {args.alias}) added to registry store."
        )
    else:
        log_msg = f"Registry @ {args.uri} added to registry store."
    cli_logger.info(log_msg)
Ejemplo n.º 6
0
def install_action(args: argparse.Namespace) -> None:
    validate_install_cli_args(args)
    config = Config(args)
    package = Package(args, config.ipfs_backend)
    install_package(package, config)
    cli_logger.info(
        "%s package sourced from %s installed to %s.",
        package.alias,
        args.uri,
        config.ethpm_dir,
    )
Ejemplo n.º 7
0
def create_wizard_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    if config.project_dir and not config.manifest_path:
        if not (config.project_dir / SOLC_OUTPUT).exists():
            compile_contracts(config.project_dir)
        generate_custom_manifest(args.project_dir)
    elif config.manifest_path and not config.project_dir:
        amend_manifest(args.manifest_path)
    else:
        raise ConfigurationError(
            "Invalid project directory and/org manifest path args detected. "
            "Please only provide a project directory (to create a new manifest) "
            "or a manifest path (to amend a manifest).")
Ejemplo n.º 8
0
def test_config_with_cli_ethpm_dir_overrides_env_var(tmpdir, namespace,
                                                     monkeypatch):
    env_dir = Path(tmpdir) / "env"
    cli_dir = Path(tmpdir) / "cli"
    env_dir.mkdir()
    cli_dir.mkdir()
    ethpm_dir_env = env_dir / ETHPM_PACKAGES_DIR
    ethpm_dir_cli = cli_dir / ETHPM_PACKAGES_DIR
    ethpm_dir_env.mkdir()
    ethpm_dir_cli.mkdir()
    monkeypatch.setenv(ETHPM_DIR_ENV_VAR, str(ethpm_dir_env))
    namespace.ethpm_dir = ethpm_dir_cli
    config = Config(namespace)
    assert config.ethpm_dir == ethpm_dir_cli
Ejemplo n.º 9
0
def create_basic_manifest_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    validate_config_has_project_dir_attr(config)
    validate_solc_output(args.project_dir)
    if not args.package_name:
        raise ValidationError(
            "To automatically generate a basic manifest, you must provide a --package-name."
        )

    if not args.package_version:
        raise ValidationError(
            "To automatically generate a basic manifest, you must provide a --package-version."
        )
    generate_basic_manifest(args.package_name, args.package_version, args.project_dir)
Ejemplo n.º 10
0
def config(tmpdir, monkeypatch):
    monkeypatch.chdir(tmpdir)

    # Create tmp xdg dir and set as env variable
    xdg_ethpm_dir = Path(tmpdir) / "xdg_ethpmcli_dir"
    monkeypatch.setenv("XDG_ETHPMCLI_ROOT", str(xdg_ethpm_dir))

    # Create tmp _ethpm_packages dir
    ethpm_dir = Path(tmpdir) / ETHPM_PACKAGES_DIR
    ethpm_dir.mkdir()

    # Create basic Config
    namespace = Namespace()
    namespace.local_ipfs = False
    namespace.install_uri = None
    namespace.alias = None
    namespace.ethpm_dir = ethpm_dir
    return Config(namespace)
Ejemplo n.º 11
0
def scrape_action(args: argparse.Namespace) -> None:
    config = Config(args)
    xdg_ethpmcli_root = get_xdg_ethpmcli_root()
    chain_data_path = xdg_ethpmcli_root / IPFS_CHAIN_DATA
    validate_chain_data_store(chain_data_path, config.w3)
    cli_logger.info("Loading IPFS scraper...")
    start_block = args.start_block if args.start_block else 0
    last_scraped_block = scrape(config.w3, xdg_ethpmcli_root, start_block)
    last_scraped_block_hash = config.w3.eth.getBlock(last_scraped_block)["hash"]
    cli_logger.info(
        "All blocks scraped up to # %d: %s.",
        last_scraped_block,
        humanize_hash(last_scraped_block_hash),
    )
    cli_logger.debug(
        "All blocks scraped up to # %d: %s.",
        last_scraped_block,
        last_scraped_block_hash,
    )
Ejemplo n.º 12
0
def release_cmd(args: argparse.Namespace) -> None:
    config = Config(args)

    if args.manifest_path:
        (package_name, package_version,
         manifest_uri) = pin_local_manifest(args.manifest_path)
        cli_logger.info(
            f"Retrieving manifest info from local file @ {args.manifest_path} "
        )

        release_package(package_name, package_version, manifest_uri, config)
        cli_logger.info(f"{package_name} v{package_version} @ {manifest_uri} ")
    else:
        release_package(args.package_name, args.package_version,
                        args.manifest_uri, config)
        cli_logger.info(
            f"{args.package_name} v{args.package_version} @ {args.manifest_uri} "
        )

    active_registry = get_active_registry(config.xdg_ethpmcli_root /
                                          REGISTRY_STORE)
    cli_logger.info(f"released to registry @ {active_registry.uri}.")
Ejemplo n.º 13
0
def registry_activate_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    activate_registry(args.uri_or_alias, config)
    cli_logger.info(f"Registry @ {args.uri_or_alias} activated.")
Ejemplo n.º 14
0
def registry_list_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    list_registries(config)
Ejemplo n.º 15
0
def test_config_with_cli_ethpm_dir(tmpdir, namespace):
    ethpm_dir = Path(tmpdir) / ETHPM_PACKAGES_DIR
    namespace.ethpm_dir = ethpm_dir
    config = Config(namespace)
    assert config.ethpm_dir == ethpm_dir
Ejemplo n.º 16
0
def create_manifest_wizard_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    validate_config_has_project_dir_attr(config)
    validate_solc_output(args.project_dir)
    generate_custom_manifest(args.project_dir)
Ejemplo n.º 17
0
def uninstall_action(args: argparse.Namespace) -> None:
    validate_uninstall_cli_args(args)
    config = Config(args)
    uninstall_package(args.package, config)
    cli_logger.info("%s uninstalled from %s", args.package, config.ethpm_dir)
Ejemplo n.º 18
0
def registry_explore_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    cli_logger.info(f"Looking for packages @ {args.uri_or_alias}: \n")
    explore_registry(args.uri_or_alias, config)
Ejemplo n.º 19
0
def test_config_with_unsupported_chain_id_raises_exception(namespace):
    namespace.chain_id = 2
    with pytest.raises(Exception):
        Config(namespace)
Ejemplo n.º 20
0
def test_config_initializes_with_correct_w3_instance(namespace, chain_id,
                                                     expected):
    namespace.chain_id = chain_id
    config = Config(namespace)
    assert config.w3.net.version == expected
Ejemplo n.º 21
0
def registry_remove_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    remove_registry(args.uri_or_alias, config)
    cli_logger.info(
        f"Registry: {args.uri_or_alias} removed from registry store.")
Ejemplo n.º 22
0
def create_solc_input_cmd(args: argparse.Namespace) -> None:
    config = Config(args)
    validate_config_has_project_dir_attr(config)
    generate_solc_input(args.project_dir / "contracts")
Ejemplo n.º 23
0
def get_action(args: argparse.Namespace) -> None:
    config = Config(args)
    get_manifest(args, config)
Ejemplo n.º 24
0
def activate_action(args: argparse.Namespace) -> None:
    config = Config(args)
    activate_package(args, config)
Ejemplo n.º 25
0
def test_config_without_cli_ethpm_dir(namespace):
    namespace.ethpm_dir = None
    config = Config(namespace)
    assert config.ethpm_dir.is_dir()
    assert config.ethpm_dir.name == ETHPM_PACKAGES_DIR
Ejemplo n.º 26
0
def list_action(args: argparse.Namespace) -> None:
    config = Config(args)
    list_installed_packages(config)
Ejemplo n.º 27
0
def cat_action(args: argparse.Namespace) -> None:
    config = Config(args)
    cat_manifest(config.manifest_path)