Skip to content

test_create_preimage_layout_increment_nonce()

Documentation for tests/frontier/create/test_create_preimage_layout.py::test_create_preimage_layout_increment_nonce@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

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

Test CreatePreimageLayout.increment_nonce_op by computing addresses for nonces 1..DYNAMIC_NONCE_COUNT using a single layout with nonce incrementing in the EVM.

Source code in tests/frontier/create/test_create_preimage_layout.py
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@pytest.mark.valid_from("Osaka")
def test_create_preimage_layout_increment_nonce(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
) -> None:
    """
    Test `CreatePreimageLayout.increment_nonce_op` by computing
    addresses for nonces 1..DYNAMIC_NONCE_COUNT using a single
    layout with nonce incrementing in the EVM.
    """
    sender = pre.fund_eoa()
    sender_int = int.from_bytes(sender, "big")
    sender_address = sender_int.to_bytes(20, "big")

    layout = CreatePreimageLayout(
        sender_address=sender_int,
        nonce=Op.CALLDATALOAD(0),
    )
    # Initial setup + first address (nonce=1)
    code = layout + Op.SSTORE(0, layout.address_op())
    # Increment and compute for nonces 2..N
    for i in range(1, DYNAMIC_NONCE_COUNT):
        code += layout.increment_nonce_op()
        code += Op.SSTORE(i, layout.address_op())
    contract = pre.deploy_contract(code)

    tx = Transaction(
        sender=sender,
        to=contract,
        data=(1).to_bytes(32, "big"),
        gas_limit=5_000_000,
        protected=fork.supports_protected_txs(),
    )

    expected_storage = {
        i: int.from_bytes(
            compute_create_address(address=sender_address, nonce=i + 1),
            "big",
        )
        for i in range(DYNAMIC_NONCE_COUNT)
    }
    post = {contract: Account(storage=expected_storage)}

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

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.