diff --git a/boa/util/eip5202.py b/boa/util/eip5202.py index e28586d5..2e6c6d31 100644 --- a/boa/util/eip5202.py +++ b/boa/util/eip5202.py @@ -1,11 +1,13 @@ -from typing import Optional, Any -import eth_typing -from vyper.utils import keccak256 +from typing import Any, Optional + from eth_utils import to_canonical_address, to_checksum_address +from vyper.utils import keccak256 # TODO replace return type with upcoming AddressType wrapper -def get_create2_address(blueprint_bytecode: bytes, deployer_address: Any, salt: bytes) -> str: +def get_create2_address( + blueprint_bytecode: bytes, deployer_address: Any, salt: bytes +) -> str: _, _, initcode = parse_erc5202(blueprint_bytecode) initcode_hash = keccak256(initcode) @@ -13,7 +15,7 @@ def get_create2_address(blueprint_bytecode: bytes, deployer_address: Any, salt: prefix = b"\xFF" addr = to_canonical_address(deployer_address) if len(salt) != 32: - raise ValueError(f"bad salt (must be bytes32): {salt}") + raise ValueError(f"bad salt (must be bytes32): {salt!r}") create2_hash = keccak256(prefix + addr + salt + initcode_hash) @@ -45,7 +47,9 @@ def parse_erc5202(blueprint_bytecode: bytes) -> tuple[int, Optional[bytes], byte if n_length_bytes == 0b11: raise ValueError("Reserved bits are set") - data_length = int.from_bytes(blueprint_bytecode[3 : 3 + n_length_bytes], byteorder="big") + data_length = int.from_bytes( + blueprint_bytecode[3 : 3 + n_length_bytes], byteorder="big" + ) if n_length_bytes == 0: preamble_data = None diff --git a/tests/unitary/test_blueprints.py b/tests/unitary/test_blueprints.py index 3219b968..ca6d9374 100644 --- a/tests/unitary/test_blueprints.py +++ b/tests/unitary/test_blueprints.py @@ -1,19 +1,21 @@ +from eth_utils import to_canonical_address + import boa from boa.util.eip5202 import get_create2_address -from eth_utils import to_canonical_address blueprint_code = """ @external def some_function() -> uint256: return 5 -""" - +""" + factory_code = """ -@external +@external def create_child(blueprint: address, salt: bytes32) -> address: return create_from_blueprint(blueprint, code_offset=3, salt=salt) -""" - +""" + + def test_create2_address(): blueprint = boa.loads_partial(blueprint_code).deploy_as_blueprint() factory = boa.loads(factory_code) @@ -23,5 +25,9 @@ def test_create2_address(): child_contract_address = factory.create_child(blueprint.address, salt) # TODO: make a util function on boa.env to get code - blueprint_bytecode = boa.env.vm.state.get_code(to_canonical_address(blueprint.address)) - assert child_contract_address == get_create2_address(blueprint_bytecode, factory.address, salt) + blueprint_bytecode = boa.env.vm.state.get_code( + to_canonical_address(blueprint.address) + ) + assert child_contract_address == get_create2_address( + blueprint_bytecode, factory.address, salt + ) diff --git a/tests/unitary/utils/test_parse_eip5202.py b/tests/unitary/utils/test_parse_eip5202.py index ba047448..c78ce56f 100644 --- a/tests/unitary/utils/test_parse_eip5202.py +++ b/tests/unitary/utils/test_parse_eip5202.py @@ -2,10 +2,12 @@ ERC5202_VERSION = 0 + def test_parse_erc5202(): blueprint_bytecode = b"\xFE\x71\x00abcd" assert parse_erc5202(blueprint_bytecode) == (ERC5202_VERSION, None, b"abcd") + def test_parse_erc5202_with_data(): blueprint_bytecode = b"\xFE\x71\x01\x04dataabcd" assert parse_erc5202(blueprint_bytecode) == (ERC5202_VERSION, b"data", b"abcd")