def test_list(ipfs_mock, tp_path, mocker): mocker.spy(ethpm, "get_installed_packages") cli_ethpm._list(tp_path) assert ethpm.get_installed_packages.call_count == 1 ethpm.install_package(tp_path, "ipfs://testipfs-math") cli_ethpm._list(tp_path) assert ethpm.get_installed_packages.call_count == 2
def test_remove(ipfs_mock, tp_path, mocker): ethpm.install_package(tp_path, "ipfs://testipfs-math") mocker.spy(ethpm, "remove_package") cli_ethpm._remove(tp_path, "math") assert ethpm.remove_package.call_count == 1 assert not tp_path.joinpath("contracts/math").exists() cli_ethpm._remove(tp_path, "math") assert ethpm.remove_package.call_count == 2 assert not tp_path.joinpath("contracts/math").exists()
def test_install_and_remove_with_deps(np_path): ethpm.install_package(np_path, "ipfs://testipfs-complex") assert np_path.joinpath("contracts/math/Math.sol").exists() assert ethpm.get_installed_packages(np_path) == ([("complex", "1.0.0")], []) ethpm.install_package(np_path, "ipfs://testipfs-math") assert ethpm.get_installed_packages(np_path) == ([("complex", "1.0.0"), ("math", "1.0.0")], []) ethpm.remove_package(np_path, "complex", True) assert np_path.joinpath("contracts/math/Math.sol").exists() assert not np_path.joinpath("contracts/complex/Complex.sol").exists() assert ethpm.get_installed_packages(np_path) == ([("math", "1.0.0")], [])
def test_delete_files(np_path): ethpm.install_package(np_path, "ipfs://testipfs-utils") np_path.joinpath("contracts/utils/ReentrancyGuard.sol").unlink() assert ethpm.get_installed_packages(np_path) == ([], [("utils", "1.0.0")]) np_path.joinpath("contracts/utils/Arrays.sol").unlink() np_path.joinpath("contracts/utils/Address.sol").unlink() np_path.joinpath("contracts/math/Math.sol").unlink() assert ethpm.get_installed_packages(np_path) == ([], []) assert not np_path.joinpath("contracts/utils").exists() assert not np_path.joinpath("contracts/math").exists()
def _install(project_path, uri, replace=False): if replace: if replace.lower() not in ("true", "false"): raise ValueError("Invalid command for 'overwrite', must be True or False") replace = eval(replace.capitalize()) print(f'Attempting to install package at "{color("bright magenta")}{uri}{color}"...') name = ethpm.install_package(project_path, uri, replace) notify("SUCCESS", f'The "{color("bright magenta")}{name}{color}" package was installed.')
def _install_from_ethpm(uri: str) -> str: manifest = get_manifest(uri) org = manifest["meta_brownie"]["registry_address"] repo = manifest["package_name"] version = manifest["version"] install_path = _get_data_folder().joinpath(f"packages/{org}") install_path.mkdir(exist_ok=True) install_path = install_path.joinpath(f"{repo}@{version}") if install_path.exists(): raise FileExistsError("Package is aleady installed") try: new(str(install_path), ignore_existing=True) ethpm.install_package(install_path, uri) project = load(install_path) project.close() except Exception as e: shutil.rmtree(install_path) raise e return f"{org}/{repo}@{version}"
def test_modified_overwrite(np_path): ethpm.install_package(np_path, "ipfs://testipfs-math") with np_path.joinpath("contracts/math/Math.sol").open("a") as fp: fp.write(" ") with pytest.raises(FileExistsError): ethpm.install_package(np_path, "ipfs://testipfs-complex") assert ethpm.get_installed_packages(np_path) == ([], [("math", "1.0.0")]) ethpm.install_package(np_path, "ipfs://testipfs-complex", replace_existing=True) assert ethpm.get_installed_packages(np_path) == ([("complex", "1.0.0"), ("math", "1.0.0")], [])
def test_vyper_package_json_interface(newproject): ethpm.install_package(newproject._path, "ipfs://testipfs-vyper") newproject.load() assert newproject._path.joinpath("interfaces/Bar.json").exists()
def test_install_package(np_path): assert ethpm.get_installed_packages(np_path) == ([], []) ethpm.install_package(np_path, "ipfs://testipfs-math") assert np_path.joinpath("contracts/math/Math.sol").exists() assert ethpm.get_installed_packages(np_path) == ([("math", "1.0.0")], [])
def test_modified(np_path): ethpm.install_package(np_path, "ipfs://testipfs-math") with np_path.joinpath("contracts/math/Math.sol").open("a") as fp: fp.write(" ") assert ethpm.get_installed_packages(np_path) == ([], [("math", "1.0.0")])
def test_remove_no_delete_re_add(np_path): ethpm.install_package(np_path, "ipfs://testipfs-math") ethpm.remove_package(np_path, "math", False) ethpm.install_package(np_path, "ipfs://testipfs-math") assert np_path.joinpath("contracts/math/Math.sol").exists() assert ethpm.get_installed_packages(np_path) == ([("math", "1.0.0")], [])
def test_remove_package(np_path): ethpm.install_package(np_path, "ipfs://testipfs-math") ethpm.remove_package(np_path, "math", True) assert ethpm.get_installed_packages(np_path) == ([], []) assert not np_path.joinpath("contracts/math/Math.sol").exists()
def test_all(tp_path): cli_ethpm._all(tp_path) ethpm.install_package(tp_path, ERC1319_URI) cli_ethpm._all(tp_path)
def test_remove_no_delete(tp_path): ethpm.install_package(tp_path, "ipfs://testipfs-math") ethpm.remove_package(tp_path, "math", False) assert ethpm.get_installed_packages(tp_path) == ([], []) assert tp_path.joinpath("contracts/math/Math.sol").exists()
def dep_project(testproject): # this bit of hackiness is needed to trigger a recompile of the project ethpm.install_package(testproject._path, "ipfs://testipfs-utils") testproject.close() yield project.load(testproject._path)