From 25f81b2d6d9662cb06a86c66088e8025b1e0bddd Mon Sep 17 00:00:00 2001 From: PatrickAlphaC <54278053+PatrickAlphaC@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:33:34 -0400 Subject: [PATCH] fix: try to have boa read the filename as the contract name --- boa/interpret.py | 12 ++++++++++-- tests/unitary/contracts/vyper/test_vyper_contract.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/boa/interpret.py b/boa/interpret.py index 17136d3c..dd57133c 100644 --- a/boa/interpret.py +++ b/boa/interpret.py @@ -239,8 +239,16 @@ def loads_partial( dedent: bool = True, compiler_args: dict = None, ) -> VyperDeployer: - name = name or "VyperContract" - filename = filename or "" + if filename is None: + filename = "" + + if name is None: + if isinstance(filename, Path) or ( + isinstance(filename, str) and filename != "" + ): + name = Path(filename).stem + else: + name = "VyperContract" if dedent: source_code = textwrap.dedent(source_code) diff --git a/tests/unitary/contracts/vyper/test_vyper_contract.py b/tests/unitary/contracts/vyper/test_vyper_contract.py index 93d43591..6734377d 100644 --- a/tests/unitary/contracts/vyper/test_vyper_contract.py +++ b/tests/unitary/contracts/vyper/test_vyper_contract.py @@ -87,5 +87,15 @@ def foo() -> bool: c = boa.loads(code, filename="a/b/return_one.vy") - assert c.contract_name == "VyperContract" + assert c.contract_name == "return_one" assert c.filename == "a/b/return_one.vy" + + c = boa.loads(code, filename=None, name="dummy_name") + + assert c.contract_name == "dummy_name" + assert c.filename == "" + + c = boa.loads(code, filename=None, name=None) + + assert c.contract_name == "VyperContract" + assert c.filename == ""