Skip to content

Commit

Permalink
Merge pull request #47 from trocher/chore/raw_create_change_length_test
Browse files Browse the repository at this point in the history
Add a test
  • Loading branch information
charles-cooper authored Oct 25, 2024
2 parents b6a6079 + 96dc6a9 commit 12c1944
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/functional/builtins/codegen/test_create_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,3 +943,51 @@ def deploy() -> address:
res = deployer.deploy()

assert env.get_code(res) == runtime


@pytest.mark.xfail
@pytest.mark.parametrize("arg", [12, 257, 2**256 - 1])
@pytest.mark.parametrize("length_offset", [-32, -1, 0, 1, 32])
def test_raw_create_change_initcode_size(
get_contract, deploy_blueprint_for, env, arg, length_offset
):
to_deploy_code = """
foo: public(uint256)
@deploy
def __init__(arg: uint256):
self.foo = arg
"""

out = compile_code(to_deploy_code, output_formats=["bytecode", "bytecode_runtime"])
initcode = bytes.fromhex(out["bytecode"].removeprefix("0x"))
runtime = bytes.fromhex(out["bytecode_runtime"].removeprefix("0x"))

dummy_bytes = b"\x02" * (len(initcode) + length_offset)

deployer_code = f"""
x:DynArray[Bytes[1024],1]
@internal
def change_initcode_length(v: Bytes[1024]) -> uint256:
self.x.pop()
self.x.append({dummy_bytes})
return {arg}
@external
def deploy(s: Bytes[1024]) -> address:
self.x.append(s)
contract: address = raw_create(self.x[0], self.change_initcode_length(s))
return contract
"""

deployer = get_contract(deployer_code)

res = deployer.deploy(initcode)
assert env.get_code(res) == runtime

_, FooContract = deploy_blueprint_for(to_deploy_code)
res = FooContract(res)

assert res.foo() == arg

0 comments on commit 12c1944

Please sign in to comment.