Skip to content

Commit

Permalink
fix: try to have boa read the filename as the contract name
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Oct 24, 2024
1 parent ec96cc3 commit 25f81b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions boa/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,16 @@ def loads_partial(
dedent: bool = True,
compiler_args: dict = None,
) -> VyperDeployer:
name = name or "VyperContract"
filename = filename or "<unknown>"
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
12 changes: 11 additions & 1 deletion tests/unitary/contracts/vyper/test_vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<unknown>"

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

assert c.contract_name == "VyperContract"
assert c.filename == "<unknown>"

0 comments on commit 25f81b2

Please sign in to comment.