def deployments(self) -> Union["Deployments", Dict[None, None]]: """ API to retrieve package deployments available on the current w3-connected chain. Cached property (self.deployments) gets busted everytime self.set_default_w3() is called. """ 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) 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)
def test_get_linked_deployments(escrow_package): escrow_manifest = escrow_package.manifest all_deployments = list(escrow_manifest["deployments"].values())[0] actual_linked_deployments = get_linked_deployments(all_deployments) assert actual_linked_deployments == {"Escrow": all_deployments["Escrow"]} # integration via package.deployments deployments = escrow_package.deployments assert len(deployments.contract_factories) is 2
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)
def test_get_linked_deployments_raises_exception_with_self_reference( deployments): with pytest.raises(BytecodeLinkingError): get_linked_deployments(deployments)