Пример #1
0
    def deployments(self) -> Union["Deployments", Dict[None, None]]:
        """
        Returns a ``Deployments`` object containing all the deployment data and contract
        factories of a ``Package``'s `contract_types`. Automatically filters deployments
        to only expose those available on the current ``Package.w3`` instance.

        .. code:: python

           package.deployments.get_instance("ContractType")
        """
        if not check_for_deployments(self.manifest):
            return {}

        all_blockchain_uris = self.manifest["deployments"].keys()
        matching_uri = validate_single_matching_uri(all_blockchain_uris,
                                                    self.w3)

        deployments = self.manifest["deployments"][matching_uri]
        all_contract_factories = {
            deployment_data["contract_type"]:
            self.get_contract_factory(deployment_data["contract_type"])
            for deployment_data in deployments.values()
        }
        validate_deployments_tx_receipt(deployments,
                                        self.w3,
                                        allow_missing_data=True)
        linked_deployments = get_linked_deployments(deployments)
        if linked_deployments:
            for deployment_data in linked_deployments.values():
                on_chain_bytecode = self.w3.eth.getCode(
                    to_canonical_address(deployment_data["address"]))
                unresolved_linked_refs = normalize_linked_references(
                    deployment_data["runtime_bytecode"]["link_dependencies"])
                resolved_linked_refs = tuple(
                    self._resolve_linked_references(link_ref, deployments)
                    for link_ref in unresolved_linked_refs)
                for linked_ref in resolved_linked_refs:
                    validate_linked_references(linked_ref, on_chain_bytecode)

        return Deployments(deployments, all_contract_factories, self.w3)
Пример #2
0
def test_normalize_linked_references(link_data, expected):
    link_deps = normalize_linked_references(link_data)
    assert link_deps == expected