Skip to content

Commit

Permalink
fix contract_path/contract_name API
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 25, 2024
1 parent 25f81b2 commit b6c61cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
3 changes: 2 additions & 1 deletion boa/contracts/vvm/vvm_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def constructor(self):
return ABIFunction(t, contract_name=self.filename)
return None

def deploy(self, *args, env=None, **kwargs):
def deploy(self, *args, contract_name=None, env=None, **kwargs):
encoded_args = b""
if self.constructor is not None:
encoded_args = self.constructor.prepare_calldata(*args)
Expand All @@ -66,6 +66,7 @@ def deploy(self, *args, env=None, **kwargs):

address, _ = env.deploy_code(bytecode=self.bytecode + encoded_args, **kwargs)

# TODO: pass thru contract_name
return self.at(address)

@cached_property
Expand Down
22 changes: 9 additions & 13 deletions boa/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ def get_module_fingerprint(


def compiler_data(
source_code: str, contract_name: str, filename: str | Path, deployer=None, **kwargs
source_code: str,
contract_name: str | None,
filename: str | Path,
deployer=None,
**kwargs,
) -> CompilerData:
global _disk_cache, _search_path

path = Path(contract_name)
path = Path(filename)
resolved_path = Path(filename).resolve(strict=False)

file_input = FileInput(
Expand Down Expand Up @@ -164,7 +168,7 @@ def get_compiler_data():

assert isinstance(deployer, type) or deployer is None
deployer_id = repr(deployer) # a unique str identifying the deployer class
cache_key = str((contract_name, fingerprint, kwargs, deployer_id))
cache_key = str((contract_name, filename, fingerprint, kwargs, deployer_id))
return _disk_cache.caching_lookup(cache_key, get_compiler_data)


Expand All @@ -188,9 +192,9 @@ def loads(
):
d = loads_partial(source_code, name, filename=filename, compiler_args=compiler_args)
if as_blueprint:
return d.deploy_as_blueprint(**kwargs)
return d.deploy_as_blueprint(contract_name=name, **kwargs)
else:
return d.deploy(*args, **kwargs)
return d.deploy(*args, contract_name=name, **kwargs)


def load_abi(filename: str, *args, name: str = None, **kwargs) -> ABIContractFactory:
Expand Down Expand Up @@ -242,14 +246,6 @@ def loads_partial(
if filename is None:
filename = "<unknown>"

if name is None:
if isinstance(filename, Path) or (
isinstance(filename, str) and filename != "<unknown>"
):
name = Path(filename).stem
else:
name = "VyperContract"

if dedent:
source_code = textwrap.dedent(source_code)

Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/contracts/vyper/test_vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ def foo() -> bool:

c = boa.loads(code, filename=None, name=None)

assert c.contract_name == "VyperContract"
assert c.contract_name == "<unknown>"
assert c.filename == "<unknown>"
8 changes: 4 additions & 4 deletions tests/unitary/utils/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def test_cache_contract_name():
x: constant(int128) = 1000
"""
assert _disk_cache is not None
test1 = compiler_data(code, "test1", __file__, VyperDeployer)
test2 = compiler_data(code, "test2", __file__, VyperDeployer)
test3 = compiler_data(code, "test1", __file__, VyperDeployer)
test1 = compiler_data(code, "test1", "test1.vy", VyperDeployer)
test2 = compiler_data(code, "test2", "test2.vy", VyperDeployer)
test3 = compiler_data(code, "test1", "test1.vy", VyperDeployer)
assert _to_dict(test1) == _to_dict(test3), "Should hit the cache"
assert _to_dict(test1) != _to_dict(test2), "Should be different objects"
assert str(test2.contract_path) == "test2"
assert str(test2.contract_path) == "test2.vy"


def test_cache_vvm():
Expand Down

0 comments on commit b6c61cb

Please sign in to comment.