Skip to content

test_authorization_exact_state_gas_boundary()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_authorization_exact_state_gas_boundary@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_authorization_exact_state_gas_boundary --fork Amsterdam

Test exact intrinsic gas boundary including auth state gas.

The intrinsic cost includes regular gas (G_TRANSACTION + G_AUTHORIZATION per auth) and state gas ((STATE_BYTES_PER_NEW_ACCOUNT + STATE_BYTES_PER_AUTH_BASE) * cpsb per auth). With gas_delta=0 the tx has exactly enough and succeeds. With gas_delta=-1 the tx is 1 gas short and is rejected as intrinsic-gas-too-low.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
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
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
@pytest.mark.parametrize(
    "gas_delta",
    [
        pytest.param(0, id="exact_gas"),
        pytest.param(
            -1,
            id="one_short",
            marks=pytest.mark.exception_test,
        ),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_authorization_exact_state_gas_boundary(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_delta: int,
) -> None:
    """
    Test exact intrinsic gas boundary including auth state gas.

    The intrinsic cost includes regular gas (G_TRANSACTION + G_AUTHORIZATION
    per auth) and state gas
    ((STATE_BYTES_PER_NEW_ACCOUNT + STATE_BYTES_PER_AUTH_BASE) * cpsb
    per auth). With gas_delta=0 the tx has exactly enough and succeeds.
    With gas_delta=-1 the tx is 1 gas short and is rejected as
    intrinsic-gas-too-low.
    """
    contract = pre.deploy_contract(code=Op.STOP)

    signer = pre.fund_eoa()
    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=signer,
        ),
    ]

    intrinsic_cost_calculator = fork.transaction_intrinsic_cost_calculator()
    intrinsic_cost = intrinsic_cost_calculator(
        authorization_list_or_count=authorization_list,
    )

    is_oog = gas_delta < 0
    sender = pre.fund_eoa()
    tx = Transaction(
        to=contract,
        gas_limit=intrinsic_cost + gas_delta,
        authorization_list=authorization_list,
        sender=sender,
        error=TransactionException.INTRINSIC_GAS_TOO_LOW if is_oog else None,
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                exception=(
                    TransactionException.INTRINSIC_GAS_TOO_LOW
                    if is_oog
                    else None
                ),
            )
        ],
        post={},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.