From d443a9e1fb20ce3c9b6d1cae8f2ed8d2c2e55138 Mon Sep 17 00:00:00 2001 From: PatrickAlphaC <54278053+PatrickAlphaC@users.noreply.github.com> Date: Mon, 21 Oct 2024 00:13:45 -0400 Subject: [PATCH 1/8] wip --- boa/contracts/vyper/vyper_contract.py | 11 +++++++++-- boa/deployments.py | 2 ++ boa/environment.py | 1 + boa/network.py | 10 +++++++++- dev-requirements.txt | 1 + tests/integration/network/anvil/test_network_env.py | 4 +++- tests/integration/network/sepolia/test_sepolia_env.py | 4 +++- 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/boa/contracts/vyper/vyper_contract.py b/boa/contracts/vyper/vyper_contract.py index cdf409c8..e502a2e7 100644 --- a/boa/contracts/vyper/vyper_contract.py +++ b/boa/contracts/vyper/vyper_contract.py @@ -518,12 +518,14 @@ def __init__( created_from: Address = None, filename: str = None, gas=None, + nickname=None, ): super().__init__(compiler_data, env, filename) self.created_from = created_from self._computation = None self._source_map = None + self.nickname = nickname # add all exposed functions from the interface to the contract exposed_fns = { @@ -544,7 +546,11 @@ def __init__( addr = Address(override_address) else: addr = self._run_init( - *args, value=value, override_address=override_address, gas=gas + *args, + value=value, + override_address=override_address, + gas=gas, + nickname=nickname, ) self._address = addr @@ -569,7 +575,7 @@ def __init__( self.env.register_contract(self._address, self) - def _run_init(self, *args, value=0, override_address=None, gas=None): + def _run_init(self, *args, value=0, override_address=None, gas=None, nickname=None): encoded_args = b"" if self._ctor: encoded_args = self._ctor.prepare_calldata(*args) @@ -582,6 +588,7 @@ def _run_init(self, *args, value=0, override_address=None, gas=None): override_address=override_address, gas=gas, contract=self, + nickname=nickname, ) self._computation = computation diff --git a/boa/deployments.py b/boa/deployments.py index 03a3e2af..5f935e8d 100644 --- a/boa/deployments.py +++ b/boa/deployments.py @@ -39,6 +39,7 @@ class Deployment: tx_dict: dict # raw tx fields receipt_dict: dict # raw receipt fields source_code: Optional[Any] # optional source code or bundle + nickname: Optional[str] # An optional nickname for the contract abi: Optional[Any] session_id: str = field(default_factory=get_session_id) deployment_id: Optional[int] = None # the db-assigned id - primary key @@ -90,6 +91,7 @@ def from_sql_tuple(cls, values): session_id text, contract_address text, contract_name text, + nickname text, rpc text, deployer text, tx_hash text, diff --git a/boa/environment.py b/boa/environment.py index 52a729ec..805dd67e 100644 --- a/boa/environment.py +++ b/boa/environment.py @@ -212,6 +212,7 @@ def deploy( override_address: Optional[_AddressType] = None, # the calling vyper contract contract: Any = None, + nickname: Optional[str] = None, # TODO: This isn't used ): sender = self._get_sender(sender) diff --git a/boa/network.py b/boa/network.py index 23dd0dd1..6cfc99ce 100644 --- a/boa/network.py +++ b/boa/network.py @@ -361,7 +361,14 @@ def execute_code( # OVERRIDES def deploy( - self, sender=None, gas=None, value=0, bytecode=b"", contract=None, **kwargs + self, + sender=None, + gas=None, + value=0, + bytecode=b"", + contract=None, + nickname=None, + **kwargs, ): # reset to latest block for simulation self._reset_fork() @@ -425,6 +432,7 @@ def deploy( broadcast_ts, txdata, receipt, + nickname, source_bundle, abi, ) diff --git a/dev-requirements.txt b/dev-requirements.txt index 93d94bad..eeb2522a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -12,6 +12,7 @@ pytest pytest-xdist pytest-cov sphinx-rtd-theme +requests-cache # jupyter jupyter_server diff --git a/tests/integration/network/anvil/test_network_env.py b/tests/integration/network/anvil/test_network_env.py index 0bfbd397..aeb9314d 100644 --- a/tests/integration/network/anvil/test_network_env.py +++ b/tests/integration/network/anvil/test_network_env.py @@ -76,9 +76,10 @@ def test_failed_transaction(): def test_deployment_db(): with set_deployments_db(DeploymentsDB(":memory:")) as db: arg = 5 + nickname = "test_deployment" # contract is written to deployments db - contract = boa.loads(code, arg) + contract = boa.loads(code, arg, nickname=nickname) # test get_deployments() deployment = next(db.get_deployments()) @@ -92,6 +93,7 @@ def test_deployment_db(): assert deployment.rpc == boa.env._rpc.name assert deployment.source_code == contract.deployer.solc_json assert deployment.abi == contract.abi + assert deployment.nickname == nickname # some sanity checks on tx_dict and rx_dict fields assert to_bytes(deployment.tx_dict["data"]) == initcode diff --git a/tests/integration/network/sepolia/test_sepolia_env.py b/tests/integration/network/sepolia/test_sepolia_env.py index 0d00e631..73b0e98f 100644 --- a/tests/integration/network/sepolia/test_sepolia_env.py +++ b/tests/integration/network/sepolia/test_sepolia_env.py @@ -75,9 +75,10 @@ def test_raise_exception(simple_contract, amount): def test_deployment_db(): with set_deployments_db(DeploymentsDB(":memory:")) as db: arg = 5 + nickname = "test_deployment" # contract is written to deployments db - contract = boa.loads(code, arg) + contract = boa.loads(code, arg, nickname=nickname) # test get_deployments() deployment = next(db.get_deployments()) @@ -90,6 +91,7 @@ def test_deployment_db(): assert deployment.deployer == boa.env.eoa assert deployment.rpc == boa.env._rpc.name assert deployment.source_code == contract.deployer.solc_json + assert deployment.nickname == nickname # some sanity checks on tx_dict and rx_dict fields assert to_bytes(deployment.tx_dict["data"]) == initcode From 83bfb30e81f31b7a4f422d19b6774bd6b07b7be0 Mon Sep 17 00:00:00 2001 From: PatrickAlphaC <54278053+PatrickAlphaC@users.noreply.github.com> Date: Mon, 21 Oct 2024 00:26:33 -0400 Subject: [PATCH 2/8] feat: nicknamed contracts --- boa/deployments.py | 2 +- boa/network.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/boa/deployments.py b/boa/deployments.py index 5f935e8d..3d8a43c8 100644 --- a/boa/deployments.py +++ b/boa/deployments.py @@ -91,7 +91,6 @@ def from_sql_tuple(cls, values): session_id text, contract_address text, contract_name text, - nickname text, rpc text, deployer text, tx_hash text, @@ -99,6 +98,7 @@ def from_sql_tuple(cls, values): tx_dict text, receipt_dict text, source_code text, + nickname text, abi text ); """ diff --git a/boa/network.py b/boa/network.py index 6cfc99ce..189ceea6 100644 --- a/boa/network.py +++ b/boa/network.py @@ -432,8 +432,8 @@ def deploy( broadcast_ts, txdata, receipt, - nickname, source_bundle, + nickname, abi, ) deployments_db.insert_deployment(deployment_data) From 06a6335856cd7fb0861e00d106ebce221ce6f127 Mon Sep 17 00:00:00 2001 From: PatrickAlphaC <54278053+PatrickAlphaC@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:20:00 -0400 Subject: [PATCH 3/8] fix: made contract_name a parameter --- boa/contracts/vyper/vyper_contract.py | 18 ++++++---- boa/deployments.py | 2 -- boa/environment.py | 2 +- boa/network.py | 9 +++-- .../network/anvil/test_network_env.py | 36 ++++++++++++++++--- .../network/sepolia/test_sepolia_env.py | 6 ++-- 6 files changed, 53 insertions(+), 20 deletions(-) diff --git a/boa/contracts/vyper/vyper_contract.py b/boa/contracts/vyper/vyper_contract.py index e502a2e7..4a84c008 100644 --- a/boa/contracts/vyper/vyper_contract.py +++ b/boa/contracts/vyper/vyper_contract.py @@ -146,8 +146,11 @@ def __init__( compiler_data: CompilerData, env: Optional[Env] = None, filename: Optional[str] = None, + contract_name: Optional[str] = None, ): - contract_name = Path(compiler_data.contract_path).stem + contract_name = ( + contract_name if contract_name else Path(compiler_data.contract_path).stem + ) super().__init__(contract_name, env, filename) self.compiler_data = compiler_data @@ -518,14 +521,13 @@ def __init__( created_from: Address = None, filename: str = None, gas=None, - nickname=None, + contract_name=None, ): - super().__init__(compiler_data, env, filename) + super().__init__(compiler_data, env, filename, contract_name) self.created_from = created_from self._computation = None self._source_map = None - self.nickname = nickname # add all exposed functions from the interface to the contract exposed_fns = { @@ -550,7 +552,7 @@ def __init__( value=value, override_address=override_address, gas=gas, - nickname=nickname, + contract_name=contract_name, ) self._address = addr @@ -575,7 +577,9 @@ def __init__( self.env.register_contract(self._address, self) - def _run_init(self, *args, value=0, override_address=None, gas=None, nickname=None): + def _run_init( + self, *args, value=0, override_address=None, gas=None, contract_name=None + ): encoded_args = b"" if self._ctor: encoded_args = self._ctor.prepare_calldata(*args) @@ -588,7 +592,7 @@ def _run_init(self, *args, value=0, override_address=None, gas=None, nickname=No override_address=override_address, gas=gas, contract=self, - nickname=nickname, + contract_name=contract_name, ) self._computation = computation diff --git a/boa/deployments.py b/boa/deployments.py index 3d8a43c8..03a3e2af 100644 --- a/boa/deployments.py +++ b/boa/deployments.py @@ -39,7 +39,6 @@ class Deployment: tx_dict: dict # raw tx fields receipt_dict: dict # raw receipt fields source_code: Optional[Any] # optional source code or bundle - nickname: Optional[str] # An optional nickname for the contract abi: Optional[Any] session_id: str = field(default_factory=get_session_id) deployment_id: Optional[int] = None # the db-assigned id - primary key @@ -98,7 +97,6 @@ def from_sql_tuple(cls, values): tx_dict text, receipt_dict text, source_code text, - nickname text, abi text ); """ diff --git a/boa/environment.py b/boa/environment.py index 805dd67e..31402a7b 100644 --- a/boa/environment.py +++ b/boa/environment.py @@ -212,7 +212,7 @@ def deploy( override_address: Optional[_AddressType] = None, # the calling vyper contract contract: Any = None, - nickname: Optional[str] = None, # TODO: This isn't used + contract_name: Optional[str] = None, # TODO: This isn't used ): sender = self._get_sender(sender) diff --git a/boa/network.py b/boa/network.py index 189ceea6..e0cef6ef 100644 --- a/boa/network.py +++ b/boa/network.py @@ -367,7 +367,7 @@ def deploy( value=0, bytecode=b"", contract=None, - nickname=None, + contract_name=None, **kwargs, ): # reset to latest block for simulation @@ -409,7 +409,11 @@ def deploy( print(f"contract deployed at {create_address}") if (deployments_db := get_deployments_db()) is not None: - contract_name = getattr(contract, "contract_name", None) + contract_name = ( + contract_name + if contract_name + else getattr(contract, "contract_name", None) + ) try: source_bundle = get_verification_bundle(contract) except Exception as e: @@ -433,7 +437,6 @@ def deploy( txdata, receipt, source_bundle, - nickname, abi, ) deployments_db.insert_deployment(deployment_data) diff --git a/tests/integration/network/anvil/test_network_env.py b/tests/integration/network/anvil/test_network_env.py index aeb9314d..18f18b46 100644 --- a/tests/integration/network/anvil/test_network_env.py +++ b/tests/integration/network/anvil/test_network_env.py @@ -73,13 +73,13 @@ def test_failed_transaction(): # XXX: probably want to test deployment revert behavior -def test_deployment_db(): +def test_deployment_db_overriden_contract_name(): with set_deployments_db(DeploymentsDB(":memory:")) as db: arg = 5 - nickname = "test_deployment" + contract_name = "test_deployment" # contract is written to deployments db - contract = boa.loads(code, arg, nickname=nickname) + contract = boa.loads(code, arg, contract_name=contract_name) # test get_deployments() deployment = next(db.get_deployments()) @@ -89,11 +89,39 @@ def test_deployment_db(): # sanity check all the fields assert deployment.contract_address == contract.address assert deployment.contract_name == contract.contract_name + assert deployment.contract_name == contract_name + assert deployment.deployer == boa.env.eoa + assert deployment.rpc == boa.env._rpc.name + assert deployment.source_code == contract.deployer.solc_json + assert deployment.abi == contract.abi + + # some sanity checks on tx_dict and rx_dict fields + assert to_bytes(deployment.tx_dict["data"]) == initcode + assert deployment.tx_dict["chainId"] == hex(boa.env.get_chain_id()) + assert Address(deployment.receipt_dict["contractAddress"]) == contract.address + + +def test_deployment_db_no_overriden_name(): + with set_deployments_db(DeploymentsDB(":memory:")) as db: + arg = 5 + non_contract_name = "test_deployment" + + # contract is written to deployments db + contract = boa.loads(code, arg) + + # test get_deployments() + deployment = next(db.get_deployments()) + + initcode = contract.compiler_data.bytecode + arg.to_bytes(32, "big") + + # sanity check all the fields + assert deployment.contract_address == contract.address + assert deployment.contract_name == contract.contract_name + assert deployment.contract_name != non_contract_name assert deployment.deployer == boa.env.eoa assert deployment.rpc == boa.env._rpc.name assert deployment.source_code == contract.deployer.solc_json assert deployment.abi == contract.abi - assert deployment.nickname == nickname # some sanity checks on tx_dict and rx_dict fields assert to_bytes(deployment.tx_dict["data"]) == initcode diff --git a/tests/integration/network/sepolia/test_sepolia_env.py b/tests/integration/network/sepolia/test_sepolia_env.py index 73b0e98f..7801f99c 100644 --- a/tests/integration/network/sepolia/test_sepolia_env.py +++ b/tests/integration/network/sepolia/test_sepolia_env.py @@ -75,10 +75,10 @@ def test_raise_exception(simple_contract, amount): def test_deployment_db(): with set_deployments_db(DeploymentsDB(":memory:")) as db: arg = 5 - nickname = "test_deployment" + contract_name = "test_deployment" # contract is written to deployments db - contract = boa.loads(code, arg, nickname=nickname) + contract = boa.loads(code, arg, contract_name=contract_name) # test get_deployments() deployment = next(db.get_deployments()) @@ -88,10 +88,10 @@ def test_deployment_db(): # sanity check all the fields assert deployment.contract_address == contract.address assert deployment.contract_name == contract.contract_name + assert deployment.contract_name == contract_name assert deployment.deployer == boa.env.eoa assert deployment.rpc == boa.env._rpc.name assert deployment.source_code == contract.deployer.solc_json - assert deployment.nickname == nickname # some sanity checks on tx_dict and rx_dict fields assert to_bytes(deployment.tx_dict["data"]) == initcode From 2c84cba11fc971197b598ca28bcf5b71c24018d0 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Wed, 23 Oct 2024 19:36:05 -0400 Subject: [PATCH 4/8] polish, remove unneeded contract_name kwargs some other style things move around arg order --- boa/contracts/vyper/vyper_contract.py | 28 ++++++++++----------------- boa/environment.py | 1 - boa/network.py | 15 ++------------ 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/boa/contracts/vyper/vyper_contract.py b/boa/contracts/vyper/vyper_contract.py index 4a84c008..8f4a1fdc 100644 --- a/boa/contracts/vyper/vyper_contract.py +++ b/boa/contracts/vyper/vyper_contract.py @@ -144,13 +144,13 @@ class _BaseVyperContract(_BaseEVMContract): def __init__( self, compiler_data: CompilerData, + contract_name: Optional[str] = None, env: Optional[Env] = None, filename: Optional[str] = None, - contract_name: Optional[str] = None, ): - contract_name = ( - contract_name if contract_name else Path(compiler_data.contract_path).stem - ) + if contract_name is None: + contract_name = Path(compiler_data.contract_path).stem + super().__init__(contract_name, env, filename) self.compiler_data = compiler_data @@ -188,12 +188,11 @@ def __init__( env=None, override_address=None, blueprint_preamble=None, + contract_name=None, filename=None, gas=None, ): - # note slight code duplication with VyperContract ctor, - # maybe use common base class? - super().__init__(compiler_data, env, filename) + super().__init__(compiler_data, contract_name, env, filename) deploy_bytecode = generate_blueprint_bytecode( compiler_data.bytecode, blueprint_preamble @@ -519,11 +518,11 @@ def __init__( # whether to skip constructor skip_initcode=False, created_from: Address = None, + contract_name=None, filename: str = None, gas=None, - contract_name=None, ): - super().__init__(compiler_data, env, filename, contract_name) + super().__init__(compiler_data, contract_name, env, filename) self.created_from = created_from self._computation = None @@ -548,11 +547,7 @@ def __init__( addr = Address(override_address) else: addr = self._run_init( - *args, - value=value, - override_address=override_address, - gas=gas, - contract_name=contract_name, + *args, value=value, override_address=override_address, gas=gas ) self._address = addr @@ -577,9 +572,7 @@ def __init__( self.env.register_contract(self._address, self) - def _run_init( - self, *args, value=0, override_address=None, gas=None, contract_name=None - ): + def _run_init(self, *args, value=0, override_address=None, gas=None): encoded_args = b"" if self._ctor: encoded_args = self._ctor.prepare_calldata(*args) @@ -592,7 +585,6 @@ def _run_init( override_address=override_address, gas=gas, contract=self, - contract_name=contract_name, ) self._computation = computation diff --git a/boa/environment.py b/boa/environment.py index 31402a7b..52a729ec 100644 --- a/boa/environment.py +++ b/boa/environment.py @@ -212,7 +212,6 @@ def deploy( override_address: Optional[_AddressType] = None, # the calling vyper contract contract: Any = None, - contract_name: Optional[str] = None, # TODO: This isn't used ): sender = self._get_sender(sender) diff --git a/boa/network.py b/boa/network.py index e0cef6ef..23dd0dd1 100644 --- a/boa/network.py +++ b/boa/network.py @@ -361,14 +361,7 @@ def execute_code( # OVERRIDES def deploy( - self, - sender=None, - gas=None, - value=0, - bytecode=b"", - contract=None, - contract_name=None, - **kwargs, + self, sender=None, gas=None, value=0, bytecode=b"", contract=None, **kwargs ): # reset to latest block for simulation self._reset_fork() @@ -409,11 +402,7 @@ def deploy( print(f"contract deployed at {create_address}") if (deployments_db := get_deployments_db()) is not None: - contract_name = ( - contract_name - if contract_name - else getattr(contract, "contract_name", None) - ) + contract_name = getattr(contract, "contract_name", None) try: source_bundle = get_verification_bundle(contract) except Exception as e: From ec96cc3ab137161fda1cdbe2e9c43c0cd725799c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Wed, 23 Oct 2024 19:58:46 -0400 Subject: [PATCH 5/8] add a unit test --- .../contracts/vyper/test_vyper_contract.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unitary/contracts/vyper/test_vyper_contract.py b/tests/unitary/contracts/vyper/test_vyper_contract.py index b522e935..93d43591 100644 --- a/tests/unitary/contracts/vyper/test_vyper_contract.py +++ b/tests/unitary/contracts/vyper/test_vyper_contract.py @@ -72,3 +72,20 @@ def foo() -> bool: c = boa.loads(code) c.foo() + + +def test_contract_name(): + code = """ +@external +def foo() -> bool: + return True + """ + c = boa.loads(code, name="return_one", filename="return_one.vy") + + assert c.contract_name == "return_one" + assert c.filename == "return_one.vy" + + c = boa.loads(code, filename="a/b/return_one.vy") + + assert c.contract_name == "VyperContract" + assert c.filename == "a/b/return_one.vy" 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 6/8] 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 == "" From b6c61cb3cba49afe786f5a3a4d7c67fa99a9306a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 24 Oct 2024 21:00:44 -0400 Subject: [PATCH 7/8] fix contract_path/contract_name API --- boa/contracts/vvm/vvm_contract.py | 3 ++- boa/interpret.py | 22 ++++++++----------- .../contracts/vyper/test_vyper_contract.py | 2 +- tests/unitary/utils/test_cache.py | 8 +++---- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/boa/contracts/vvm/vvm_contract.py b/boa/contracts/vvm/vvm_contract.py index 6eedc2b8..87038a2d 100644 --- a/boa/contracts/vvm/vvm_contract.py +++ b/boa/contracts/vvm/vvm_contract.py @@ -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) @@ -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 diff --git a/boa/interpret.py b/boa/interpret.py index dd57133c..8870b168 100644 --- a/boa/interpret.py +++ b/boa/interpret.py @@ -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( @@ -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) @@ -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: @@ -242,14 +246,6 @@ def loads_partial( 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 6734377d..9e5e498d 100644 --- a/tests/unitary/contracts/vyper/test_vyper_contract.py +++ b/tests/unitary/contracts/vyper/test_vyper_contract.py @@ -97,5 +97,5 @@ def foo() -> bool: c = boa.loads(code, filename=None, name=None) - assert c.contract_name == "VyperContract" + assert c.contract_name == "" assert c.filename == "" diff --git a/tests/unitary/utils/test_cache.py b/tests/unitary/utils/test_cache.py index 64659821..ad58eec5 100644 --- a/tests/unitary/utils/test_cache.py +++ b/tests/unitary/utils/test_cache.py @@ -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(): From 91ea2ac53914dca764a40e03abc00606fece7e71 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 25 Oct 2024 13:16:01 -0400 Subject: [PATCH 8/8] lint --- tests/unitary/contracts/vyper/test_vyper_contract.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unitary/contracts/vyper/test_vyper_contract.py b/tests/unitary/contracts/vyper/test_vyper_contract.py index a7b4c36b..4fd8e70a 100644 --- a/tests/unitary/contracts/vyper/test_vyper_contract.py +++ b/tests/unitary/contracts/vyper/test_vyper_contract.py @@ -100,6 +100,7 @@ def foo() -> bool: assert c.contract_name == "" assert c.filename == "" + def test_stomp(): code1 = """ VAR: immutable(uint256)