Skip to content

test_create_tx_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_tx_state_gas@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_tx_state_gas --fork Bogota

Test contract creation transaction charges top-frame state gas.

A create transaction charges the new account's state gas during top-frame preparation, separately from transaction intrinsic gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
@pytest.mark.valid_from("EIP8037")
def test_create_tx_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test contract creation transaction charges top-frame state gas.

    A create transaction charges the new account's state gas during
    top-frame preparation, separately from transaction intrinsic gas.
    """
    init_code = Op.STOP

    expected_top_frame_state = fork.transaction_top_frame_state_gas(
        contract_creation=True
    )
    expected_execution = fork.transaction_intrinsic_cost_calculator()(
        calldata=bytes(init_code), contract_creation=True
    ) + init_code.execution_cost(fork)

    assert expected_top_frame_state > expected_execution, (
        "requires top-frame state gas > execution gas"
    )

    sender = pre.fund_eoa()
    tx = Transaction(
        to=None,
        data=init_code,
        state_gas_reservoir=0,
        sender=sender,
    )

    created = compute_create_address(address=sender, nonce=0)
    state_test(
        pre=pre,
        post={created: Account(nonce=1, code=b"")},
        tx=tx,
        blockchain_test_header_verify=Header(
            gas_used=max(expected_execution, expected_top_frame_state)
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.