From 9a800d5c81fd149bc4e196dc36d2ef0b94684781 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Fri, 27 Sep 2024 16:03:35 +0200 Subject: [PATCH] Review comments --- boa/contracts/vvm/vvm_contract.py | 16 ++++++++++------ tests/unitary/test_blueprints.py | 31 ++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/boa/contracts/vvm/vvm_contract.py b/boa/contracts/vvm/vvm_contract.py index 762d6e9e..38446240 100644 --- a/boa/contracts/vvm/vvm_contract.py +++ b/boa/contracts/vvm/vvm_contract.py @@ -57,16 +57,17 @@ def constructor(self): return ABIFunction(t, contract_name=self.filename) return None - def deploy(self, *args, env=None, override_bytecode=None, **kwargs): + def deploy(self, *args, env=None): encoded_args = b"" - if len(args) > 0: + if self.constructor is not None: encoded_args = self.constructor.prepare_calldata(*args) + elif len(args) > 0: + raise ValueError(f"No constructor, but args were provided: {args}") if env is None: env = Env.get_singleton() - bytecode = self.bytecode if override_bytecode is None else override_bytecode - address, _ = env.deploy_code(bytecode=bytecode + encoded_args, **kwargs) + address, _ = env.deploy_code(bytecode=self.bytecode + encoded_args) return self.at(address) @@ -80,8 +81,11 @@ def deploy_as_blueprint( :param kwargs: Keyword arguments to pass to the environment `deploy_code` method. :returns: A contract instance. """ - bytecode = generate_blueprint_bytecode(self.bytecode, blueprint_preamble) - return self.deploy(env=env, override_bytecode=bytecode, **kwargs) + if env is None: + env = Env.get_singleton() + bytecode = generate_blueprint_bytecode(self.bytecode) + address, _ = env.deploy_code(bytecode=bytecode) + return ABIContractFactory.from_abi_dict([]).at(address) def __call__(self, *args, **kwargs): return self.deploy(*args, **kwargs) diff --git a/tests/unitary/test_blueprints.py b/tests/unitary/test_blueprints.py index 38401074..3a5b3451 100644 --- a/tests/unitary/test_blueprints.py +++ b/tests/unitary/test_blueprints.py @@ -5,7 +5,7 @@ import boa from boa.util.eip5202 import get_create2_address -blueprint_code = """ +_blueprint_code = """ # pragma version {} @external @@ -13,7 +13,7 @@ def some_function() -> uint256: return 5 """ -factory_code = """ +_factory_code = """ # pragma version {} @external @@ -24,10 +24,24 @@ def create_child(blueprint: address, salt: bytes32) -> address: VERSIONS = [vyper.__version__, "0.3.10"] -@pytest.mark.parametrize("version", VERSIONS) -def test_create2_address(version): - blueprint = boa.loads_partial(blueprint_code.format(version)).deploy_as_blueprint() - factory = boa.loads(factory_code.format(version)) +@pytest.fixture(params=VERSIONS) +def version(request): + return request.param + + +@pytest.fixture +def blueprint_code(version): + return _blueprint_code.format(version) + + +@pytest.fixture +def factory_code(version): + return _factory_code.format(version) + + +def test_create2_address(blueprint_code, factory_code): + blueprint = boa.loads_partial(blueprint_code).deploy_as_blueprint() + factory = boa.loads(factory_code) salt = b"\x01" * 32 @@ -39,9 +53,8 @@ def test_create2_address(version): ) -@pytest.mark.parametrize("version", VERSIONS) -def test_create2_address_bad_salt(version): - blueprint = boa.loads_partial(blueprint_code.format(version)).deploy_as_blueprint() +def test_create2_address_bad_salt(blueprint_code): + blueprint = boa.loads_partial(blueprint_code).deploy_as_blueprint() blueprint_bytecode = boa.env.get_code(to_canonical_address(blueprint.address)) with pytest.raises(ValueError) as e: get_create2_address(blueprint_bytecode, blueprint.address, salt=b"")