Skip to content

test_tx_intrinsic_gas()

Documentation for tests/berlin/eip2930_access_list/test_tx_intrinsic_gas.py::test_tx_intrinsic_gas@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/berlin/eip2930_access_list/test_tx_intrinsic_gas.py::test_tx_intrinsic_gas --fork Amsterdam

Transaction intrinsic gas calculation on EIP2930.

Source code in tests/berlin/eip2930_access_list/test_tx_intrinsic_gas.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
@pytest.mark.ported_from(
    [
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stEIP1559/intrinsicGen.js",
        "https://github.com/ethereum/tests/blob/v13.3/src/GeneralStateTestsFiller/stEIP1559/intrinsicFiller.yml",
    ],
    pr=["https://github.com/ethereum/execution-spec-tests/pull/1535"],
)
@pytest.mark.parametrize("data", tx_intrinsic_gas_data_vectors)
@pytest.mark.parametrize("access_list", tx_intrinsic_gas_access_list_vectors)
@pytest.mark.parametrize(
    "below_intrinsic",
    [
        pytest.param(False),
        pytest.param(True, marks=pytest.mark.exception_test),
    ],
)
@pytest.mark.with_all_tx_types(selector=lambda tx_type: tx_type in [1, 2])
@pytest.mark.slow()
def test_tx_intrinsic_gas(
    state_test: StateTestFiller,
    tx_type: int,
    pre: Alloc,
    fork: Fork,
    data: Bytes,
    access_list: List[AccessList],
    below_intrinsic: bool,
) -> None:
    """Transaction intrinsic gas calculation on EIP2930."""
    intrinsic_gas_cost_calculator = (
        fork.transaction_intrinsic_cost_calculator()
    )
    intrinsic_gas_cost = intrinsic_gas_cost_calculator(
        calldata=data, access_list=access_list
    )

    exception: List[TransactionException] | TransactionException | None = None
    if below_intrinsic:
        data_floor_gas_cost_calculator = (
            fork.transaction_data_floor_cost_calculator()
        )
        data_floor_gas_cost = data_floor_gas_cost_calculator(data=data)
        if data_floor_gas_cost > intrinsic_gas_cost:
            exception = TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST
        elif data_floor_gas_cost == intrinsic_gas_cost:
            # Depending on the implementation, client might raise either
            # exception.
            exception = [
                TransactionException.INTRINSIC_GAS_TOO_LOW,
                TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
            ]
        else:
            exception = TransactionException.INTRINSIC_GAS_TOO_LOW

    tx = Transaction(
        ty=tx_type,
        sender=pre.fund_eoa(),
        to=pre.deploy_contract(code=Op.SSTORE(0, Op.ADD(1, 1))),
        data=data,
        access_list=access_list,
        gas_limit=intrinsic_gas_cost + (-1 if below_intrinsic else 0),
        error=exception,
        protected=True,
    )

    state_test(env=Environment(), pre=pre, post={}, tx=tx)

Parametrized Test Cases

This test generates 504 parametrized test cases across 8 forks.