Skip to content

test_oversized_initcode_tx_no_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_oversized_initcode_tx_no_state_gas@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_oversized_initcode_tx_no_state_gas --fork Amsterdam

Verify a creation tx with oversized initcode is rejected before any state gas is charged.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
@pytest.mark.parametrize(
    "initcode_size_delta",
    [
        pytest.param(0, id="at_max"),
        pytest.param(1, id="over_max", marks=pytest.mark.exception_test),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_oversized_initcode_tx_no_state_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    initcode_size_delta: int,
) -> None:
    """
    Verify a creation tx with oversized initcode is rejected before
    any state gas is charged.
    """
    max_size = fork.max_initcode_size()
    size = max_size + initcode_size_delta
    initcode = Initcode(deploy_code=Op.STOP, initcode_length=size)

    sender = pre.fund_eoa()
    create_address = compute_create_address(address=sender, nonce=0)

    create_state_gas = fork.create_state_gas(code_size=len(Op.STOP))

    tx = Transaction(
        sender=sender,
        to=None,
        data=initcode,
        state_gas_reservoir=create_state_gas,
    )

    if initcode_size_delta > 0:
        tx.error = TransactionException.INITCODE_SIZE_EXCEEDED
        post: dict = {create_address: Account.NONEXISTENT}
    else:
        post = {create_address: Account(code=Op.STOP)}

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                exception=(
                    TransactionException.INITCODE_SIZE_EXCEEDED
                    if initcode_size_delta > 0
                    else None
                ),
            ),
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.