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

Caching fixes #1786

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions brownie/network/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading