Skip to content

test_set_code_to_precompile_not_enough_gas_for_precompile_execution()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_precompile_not_enough_gas_for_precompile_execution@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_precompile_not_enough_gas_for_precompile_execution --fork Amsterdam

Test set code to precompile and making direct call in same transaction with intrinsic gas only, no extra gas for precompile execution.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
@pytest.mark.with_all_precompiles
def test_set_code_to_precompile_not_enough_gas_for_precompile_execution(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    precompile: int,
) -> None:
    """
    Test set code to precompile and making direct call in same transaction with
    intrinsic gas only, no extra gas for precompile execution.
    """
    auth_signer = pre.fund_eoa(amount=1)
    auth = AuthorizationTuple(
        address=Address(precompile), nonce=0, signer=auth_signer
    )

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=[auth],
    )
    discount = min(
        Spec.AUTH_PER_EMPTY_ACCOUNT - Spec.REFUND_AUTH_PER_EXISTING_ACCOUNT,
        intrinsic_gas // 5,  # max discount EIP-3529
    )

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=auth_signer,
        gas_limit=intrinsic_gas,
        value=1,
        authorization_list=[auth],
        # explicitly check expected gas, no precompile code executed
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=intrinsic_gas - discount
        ),
    )

    state_test(
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                # implicitly checks no OOG, successful tx transfers ``value=1``
                balance=2,
                code=Spec.delegation_designation(Address(precompile)),
                nonce=1,
            ),
        },
    )

Parametrized Test Cases

This test generates 18 parametrized test cases across 3 forks.