Skip to content

test_creation_tx_failure_preserves_intrinsic_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_creation_tx_failure_preserves_intrinsic_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_reservoir.py::test_creation_tx_failure_preserves_intrinsic_state_gas --fork Amsterdam

Regression test for the creation tx failure path.

A creation tx (to=None) whose initcode halts exercises both the intrinsic state gas for the new account and the top level failure refund of execution state gas. The test asserts the block header gas_used equals max(block_regular, intrinsic_state_gas), guarding that the failure path does not raise and that block accounting does not underflow when the refund is applied.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
@pytest.mark.valid_from("EIP8037")
def test_creation_tx_failure_preserves_intrinsic_state_gas(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Regression test for the creation tx failure path.

    A creation tx (to=None) whose initcode halts exercises both the
    intrinsic state gas for the new account and the top level failure
    refund of execution state gas. The test asserts the block header
    `gas_used` equals `max(block_regular, intrinsic_state_gas)`,
    guarding that the failure path does not raise and that block
    accounting does not underflow when the refund is applied.
    """
    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None

    create_intrinsic_state = fork.transaction_top_frame_state_gas(
        contract_creation=True,
    )
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    tx_gas = gas_limit_cap + create_intrinsic_state + sstore_state_gas

    tx = Transaction(
        to=None,
        data=Op.SSTORE(0, 1) + Op.INVALID,
        state_gas_reservoir=create_intrinsic_state + sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    block_regular = tx_gas - create_intrinsic_state - sstore_state_gas
    expected_gas_used = max(block_regular, create_intrinsic_state)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=expected_gas_used),
            ),
        ],
        post={},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.