Skip to content

test_block_gas_used_create_tx()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_gas_used_create_tx@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_block_gas_used_create_tx --fork Amsterdam

Verify block.gas_used includes intrinsic state gas from CREATE txs.

Contract creation charges GAS_NEW_ACCOUNT as intrinsic state gas. Combined with a STOP tx, verify the 2D max is correct.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
@pytest.mark.valid_from("EIP8037")
def test_block_gas_used_create_tx(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify block.gas_used includes intrinsic state gas from CREATE txs.

    Contract creation charges GAS_NEW_ACCOUNT as intrinsic state gas.
    Combined with a STOP tx, verify the 2D max is correct.
    """
    intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
    init_code = bytes(Op.STOP)

    create_execution = intrinsic_calc(
        calldata=init_code,
        contract_creation=True,
    ) + fork.transaction_top_frame_execution_gas(contract_creation=True)
    create_state = fork.transaction_top_frame_state_gas(contract_creation=True)
    stop_execution = intrinsic_calc()

    assert create_state > create_execution + stop_execution, (
        "create state should dominate"
    )

    sender = pre.fund_eoa()
    txs = [
        Transaction(
            to=None,
            data=init_code,
            state_gas_reservoir=create_state,
            sender=sender,
        ),
    ] + stop_txs(pre, fork, 1)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=txs,
                header_verify=Header(gas_used=create_state),
            )
        ],
        post={
            compute_create_address(address=sender, nonce=0): Account(
                nonce=1, code=b""
            )
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.