Beispiel #1
0
def test_from_file_fails_with_missing_filepath(tmpdir):
    path = os.path.join(
        str(tmpdir.mkdir('invalid')),
        'package.json',
    )

    assert not os.path.exists(path)
    with pytest.raises(FileNotFoundError):
        Package.from_file(path)
Beispiel #2
0
    def load(self, contract_factory: str, package: Path, version: str = ""):
        """
        Load an installed package.
        """
        package_path = self.packages_dir / Path(package)
        versions = list(map(lambda p: p.name, package_path.iterdir()))
        if not version:
            version = self.find_max_version(versions)
        manifest_path = package_path / Path(version) / Path("manifest.json")

        self._initialize_w3()

        self.package = Package.from_file(manifest_path, self.w3)
        factory = self.package.get_contract_factory(contract_factory)

        factory.web3 = self.w3

        return factory
Beispiel #3
0
    def install(self, uri: str):
        """
        Install packages from chain or files and put it in packages directory.
        """
        self._create_ethpm_packages_dir()
        self._initialize_w3()

        is_file = True
        for prefix in ("ipfs://", "https://", "ethpm://", "erc1319://"):
            if uri.startswith(prefix):
                is_file = False
                break

        if is_file:
            package = Package.from_file(Path(uri), self.w3)
        else:
            package = Package.from_uri(uri, self.w3)

        self._write_manifests_to_filesystem(package.name, package.version, package.manifest)
        self.package = package
Beispiel #4
0
def test_from_file_raises_type_error_with_invalid_param_type():
    with pytest.raises(TypeError):
        Package.from_file(1)
Beispiel #5
0
def test_from_file_succeeds_with_valid_package(valid_package_from_path):
    assert Package.from_file(valid_package_from_path)
Beispiel #6
0
def test_from_file_fails_with_invalid_package(invalid_package_from_path):
    with pytest.raises(ValidationError):
        Package.from_file(invalid_package_from_path)
Beispiel #7
0
def test_from_file_fails_with_non_json(non_json_package):
    with pytest.raises(json.JSONDecodeError):
        Package.from_file(non_json_package)
def test_from_file_succeeds_with_valid_manifest(valid_manifest_from_path, w3):
    assert Package.from_file(valid_manifest_from_path, w3)
def test_from_file_fails_with_missing_filepath(tmpdir, w3):
    path = os.path.join(str(tmpdir.mkdir("invalid")), "manifest.json")

    assert not os.path.exists(path)
    with pytest.raises(FileNotFoundError):
        Package.from_file(Path(path), w3)
def test_from_file_fails_with_invalid_manifest(invalid_manifest_from_path, w3):
    with pytest.raises(EthPMValidationError):
        Package.from_file(invalid_manifest_from_path, w3)
Beispiel #11
0
 def get_package(self, path: str) -> Package:
     pkg = Package.from_file(path, self.web3)
     return pkg