diff --git a/brownie/network/contract.py b/brownie/network/contract.py index b2208f861..3671374c4 100644 --- a/brownie/network/contract.py +++ b/brownie/network/contract.py @@ -352,6 +352,7 @@ class _DeployedContractBase(_ContractBase): tx: TransactionReceipt of the of the tx that deployed the contract.""" _reverted = False + _initialized = False def __init__( self, address: str, owner: Optional[AccountsType] = None, tx: TransactionReceiptType = None @@ -384,6 +385,8 @@ def __init__( self._check_and_set(abi["name"], overloaded) getattr(self, abi["name"])._add_fn(abi, natspec) + self._initialized = True + def _check_and_set(self, name: str, obj: Any) -> None: if name == "balance": warnings.warn( @@ -426,6 +429,14 @@ def __getattribute__(self, name: str) -> Any: except AttributeError: raise AttributeError(f"Contract '{self._name}' object has no attribute '{name}'") + def __setattr__(self, name: str, value: Any) -> None: + if self._initialized and hasattr(self, name): + if isinstance(getattr(self, name), _ContractMethod): + raise AttributeError( + f"{self._name}.{name} is a contract function, it cannot be assigned to" + ) + super().__setattr__(name, value) + def get_method_object(self, calldata: str) -> Optional["_ContractMethod"]: """ Given a calldata hex string, returns a `ContractMethod` object.