Skip to content

test_create_preimage_layout_address()

Documentation for tests/frontier/create/test_create_preimage_layout.py::test_create_preimage_layout_address@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/frontier/create/test_create_preimage_layout.py::test_create_preimage_layout_address --fork Amsterdam

Test CreatePreimageLayout by executing the bytecode in the EVM and verifying the computed address matches compute_create_address.

The nonce is passed via calldata and RLP-encoded at EVM runtime using the CLZ-based branch-free path.

Source code in tests/frontier/create/test_create_preimage_layout.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@pytest.mark.parametrize(
    "nonce",
    [1, 2, 127, 128, 255, 256, 3515, 65535, 16777215],
)
@pytest.mark.valid_from("Osaka")
def test_create_preimage_layout_address(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
    nonce: int,
) -> None:
    """
    Test `CreatePreimageLayout` by executing the bytecode in the EVM
    and verifying the computed address matches `compute_create_address`.

    The nonce is passed via calldata and RLP-encoded at EVM runtime
    using the CLZ-based branch-free path.
    """
    sender = pre.fund_eoa()
    sender_int = int.from_bytes(sender, "big")

    layout = CreatePreimageLayout(
        sender_address=sender_int,
        nonce=Op.CALLDATALOAD(0),
    )

    code = layout + Op.SSTORE(0, layout.address_op())
    contract = pre.deploy_contract(code)

    tx = Transaction(
        sender=sender,
        to=contract,
        data=nonce.to_bytes(32, "big"),
        protected=fork.supports_protected_txs(),
    )

    expected_address = compute_create_address(address=sender, nonce=nonce)
    post = {
        contract: Account(storage={0: int.from_bytes(expected_address, "big")})
    }

    state_test(env=Environment(), pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 9 parametrized test cases across 2 forks.