From 353440ac3ca440584292ed40631ee5d322231fb1 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 3 Jul 2024 17:42:36 +0000 Subject: [PATCH 1/2] fix: do not replace full contract artifacts with abi-only --- brownie/network/state.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brownie/network/state.py b/brownie/network/state.py index e73f8b0a4..fde7951a8 100644 --- a/brownie/network/state.py +++ b/brownie/network/state.py @@ -632,6 +632,12 @@ def _add_deployment(contract: Any, alias: Optional[str] = None) -> None: f"(address UNIQUE, alias UNIQUE, paths, {', '.join(DEPLOYMENT_KEYS)})" ) + if "compiler" not in contract._build: + # do not replace full contract artifacts with ABI-only ones + row = cur.fetchone(f"SELECT compiler FROM {name} WHERE address=?", (address,)) + if row and row[0]: + return + all_sources = {} for key, path in contract._build.get("allSourcePaths", {}).items(): source = contract._sources.get(path) From 690da0c7c6dfb71a984ccee1acfa805f2a5e3547 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 3 Jul 2024 17:43:17 +0000 Subject: [PATCH 2/2] fix: use cached deployedBytecode where possible --- brownie/network/contract.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/brownie/network/contract.py b/brownie/network/contract.py index bc27021b6..c6f996b72 100644 --- a/brownie/network/contract.py +++ b/brownie/network/contract.py @@ -708,7 +708,9 @@ def __init__( self, address: str, owner: Optional[AccountsType] = None, tx: TransactionReceiptType = None ) -> None: address = _resolve_address(address) - self.bytecode = web3.eth.get_code(address).hex()[2:] + self.bytecode = ( + self._build.get("deployedBytecode", None) or web3.eth.get_code(address).hex()[2:] + ) if not self.bytecode: raise ContractNotFound(f"No contract deployed at {address}") self._owner = owner @@ -948,7 +950,13 @@ def from_abi( will be performed using this account. """ address = _resolve_address(address) - build = {"abi": abi, "address": address, "contractName": name, "type": "contract"} + build = { + "abi": abi, + "address": address, + "contractName": name, + "type": "contract", + "deployedBytecode": web3.eth.get_code(address).hex()[2:], + } self = cls.__new__(cls) _ContractBase.__init__(self, None, build, {}) # type: ignore