From 48c43e5cbeef66622d0ed2044e9c9bd140a0c787 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Mon, 25 Sep 2023 11:31:42 -0400 Subject: [PATCH] Allow empty bytes parameter to be specified as a SPECIAL_VARIABLE. Handle the cases where the contract container is housed in a project dependency. --- scripts/deploy_lynx.py | 4 ++-- scripts/deployment.py | 44 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/scripts/deploy_lynx.py b/scripts/deploy_lynx.py index f77db1d5..b450ea40 100644 --- a/scripts/deploy_lynx.py +++ b/scripts/deploy_lynx.py @@ -49,7 +49,7 @@ def main(): ) root_application = deployer.deploy( - *params.get(project.LynxRootApplication), **params.get_kwargs() + *params.get(project.LynxMockRootApplication), **params.get_kwargs() ) child_application = deployer.deploy( @@ -80,7 +80,7 @@ def main(): ] registry_names = { - root_application.contract_type.name: "TACoApplication", + # TACoApplication will be available on Goerli (not on Mumbai) so no rename here child_application.contract_type.name: "TACoChildApplication", } diff --git a/scripts/deployment.py b/scripts/deployment.py index a04c22b1..1a410773 100644 --- a/scripts/deployment.py +++ b/scripts/deployment.py @@ -8,18 +8,17 @@ from ape.api import AccountAPI from ape.cli import get_user_selected_account from ape.contracts.base import ContractContainer -from web3.auto.gethdev import w3 - from scripts.constants import NULL_ADDRESS from scripts.utils import check_etherscan_plugin, check_infura_plugin, check_registry_filepath +from web3.auto.gethdev import w3 VARIABLE_PREFIX = "$" +SPECIAL_VARIABLES = {"EMPTY_BYTES": b""} + def prepare_deployment( - params_filepath: Path, - registry_filepath: Path, - publish: bool = False + params_filepath: Path, registry_filepath: Path, publish: bool = False ) -> typing.Tuple[AccountAPI, "ApeDeploymentParameters"]: """ Prepares the deployment by loading the deployment parameters @@ -54,8 +53,12 @@ def _resolve_param(value: Any) -> Any: """Resolves a single parameter value.""" if not _is_variable(value): return value # literally a value + variable = value.strip(VARIABLE_PREFIX) - contract_container = getattr(project, variable) + if variable in SPECIAL_VARIABLES: + return SPECIAL_VARIABLES[variable] + + contract_container = _get_contract_container(variable) contract_instances = contract_container.deployments if not contract_instances: return NULL_ADDRESS @@ -90,7 +93,7 @@ def _validate_constructor_param(param: Any, contracts: List[str]) -> None: if not _is_variable(param): return # literally a value variable = param.strip(VARIABLE_PREFIX) - if variable not in contracts: + if (variable not in contracts) and (variable not in SPECIAL_VARIABLES): raise ConstructorParameters.Invalid(f"Variable {param} is not resolvable") @@ -136,6 +139,30 @@ def _validate_constructor_abi_inputs( ) +def _get_dependency_contract_container(contract: str) -> ContractContainer: + for dependency_name, dependency_versions in project.dependencies.items(): + if len(dependency_versions) > 1: + raise ValueError(f"Ambiguous {dependency_name} dependency for {contract}") + try: + dependency_api = list(dependency_versions.values())[0] + contract_container = getattr(dependency_api, contract) + return contract_container + except AttributeError: + continue + + raise ValueError(f"No contract found for {contract}") + + +def _get_contract_container(contract: str) -> ContractContainer: + try: + contract_container = getattr(project, contract) + except AttributeError: + # not in root project; check dependencies + contract_container = _get_dependency_contract_container(contract) + + return contract_container + + def validate_constructor_parameters(config: typing.OrderedDict[str, Any]) -> None: """Validates the constructor parameters for all contracts in a single config.""" available_contracts = list(config.keys()) @@ -145,7 +172,8 @@ def validate_constructor_parameters(config: typing.OrderedDict[str, Any]) -> Non _validate_constructor_param_list(value, available_contracts) else: _validate_constructor_param(value, available_contracts) - contract_container = getattr(project, contract) + + contract_container = _get_contract_container(contract) _validate_constructor_abi_inputs( contract_name=contract, abi_inputs=contract_container.constructor.abi.inputs,