Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Sep 27, 2024
1 parent 4e4be23 commit 9a800d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
16 changes: 10 additions & 6 deletions boa/contracts/vvm/vvm_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
31 changes: 22 additions & 9 deletions tests/unitary/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import boa
from boa.util.eip5202 import get_create2_address

blueprint_code = """
_blueprint_code = """
# pragma version {}
@external
def some_function() -> uint256:
return 5
"""

factory_code = """
_factory_code = """
# pragma version {}
@external
Expand All @@ -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

Expand All @@ -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"")
Expand Down

0 comments on commit 9a800d5

Please sign in to comment.