Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow assignment over contract functions #855

Merged
merged 1 commit into from
Nov 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down