Ejemplo n.º 1
0
    def release_package(self, package_name: str, version: str,
                        manifest_uri: str) -> bytes:
        """
        Returns the release id generated by releasing a package on the current registry.
        Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount``
        to be the registry owner.

        * Parameters:
            * ``package_name``: Must be a valid package name, matching the given manifest.
            * ``version``: Must be a valid package version, matching the given manifest.
            * ``manifest_uri``: Must be a valid content-addressed URI. Currently, only IPFS
              and Github content-addressed URIs are supported.

        """
        validate_is_supported_manifest_uri(manifest_uri)
        raw_manifest = to_text(resolve_uri_contents(manifest_uri))
        validate_raw_manifest_format(raw_manifest)
        manifest = json.loads(raw_manifest)
        validate_manifest_against_schema(manifest)
        if package_name != manifest['package_name']:
            raise ManifestValidationError(
                f"Provided package name: {package_name} does not match the package name "
                f"found in the manifest: {manifest['package_name']}.")

        if version != manifest['version']:
            raise ManifestValidationError(
                f"Provided package version: {version} does not match the package version "
                f"found in the manifest: {manifest['version']}.")

        self._validate_set_registry()
        return self.registry._release(package_name, version, manifest_uri)
Ejemplo n.º 2
0
    def __init__(self, manifest: Dict[str, Any], w3: Web3 = None) -> None:
        """
        A package must be constructed with a valid manifest.
        """
        self.w3 = w3

        if not isinstance(manifest, dict):
            raise TypeError(
                "Package object must be initialized with a dictionary. "
                "Got {0}".format(type(manifest)))

        validate_manifest_against_schema(manifest)
        validate_manifest_deployments(manifest)
        check_for_build_dependencies(manifest)

        self.package_data = manifest
Ejemplo n.º 3
0
    def __init__(self, manifest: Dict[str, Any], w3: Web3) -> None:
        """
        A package should be created using one of the available
        classmethods and a valid w3 instance.
        """
        if not isinstance(manifest, dict):
            raise TypeError(
                "Package object must be initialized with a dictionary. "
                f"Got {type(manifest)}")

        validate_manifest_against_schema(manifest)
        validate_manifest_deployments(manifest)
        validate_w3_instance(w3)

        self.w3 = w3
        self.w3.eth.defaultContractFactory = LinkableContract
        self.manifest = manifest
def test_validate_manifest_invalidates(invalid_manifest):
    with pytest.raises(ValidationError):
        validate_manifest_against_schema(invalid_manifest)
def test_validate_manifest_against_all_manifest_types(all_manifests):
    assert validate_manifest_against_schema(all_manifests) is None
def test_validate_manifest_against_all_manifest_types(all_manifests):
    for pkg in all_manifests:
        assert validate_manifest_against_schema(pkg) is None
Ejemplo n.º 7
0
def validate(manifest: Manifest) -> Manifest:
    """
    Return a validated manifest against the V2-specification schema.
    """
    validate_manifest_against_schema(manifest)
    return manifest
def test_manifest_assets_are_valid(manifest):
    result = validate_manifest_against_schema(manifest)
    assert result is None