Skip to content

test_gas_refunds_from_data_floor()

Documentation for tests/prague/eip7623_increase_calldata_cost/test_refunds.py::test_gas_refunds_from_data_floor@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7623_increase_calldata_cost/test_refunds.py::test_gas_refunds_from_data_floor --fork Amsterdam

Test gas refunds deducted from the execution gas cost and not the data floor.

Source code in tests/prague/eip7623_increase_calldata_cost/test_refunds.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
@pytest.mark.parametrize(
    "refund_test_type",
    [
        RefundTestType.EXECUTION_GAS_MINUS_REFUND_GREATER_THAN_DATA_FLOOR,
        RefundTestType.EXECUTION_GAS_MINUS_REFUND_LESS_THAN_DATA_FLOOR,
        RefundTestType.EXECUTION_GAS_MINUS_REFUND_EQUAL_TO_DATA_FLOOR,
    ],
)
@pytest.mark.parametrize(
    "refund_type",
    [
        RefundType.STORAGE_CLEAR,
        RefundType.STORAGE_CLEAR | RefundType.AUTHORIZATION_EXISTING_AUTHORITY,
        RefundType.AUTHORIZATION_EXISTING_AUTHORITY,
    ],
)
def test_gas_refunds_from_data_floor(
    state_test: StateTestFiller,
    pre: Alloc,
    tx: Transaction,
    tx_floor_data_cost: int,
    tx_intrinsic_gas_cost_before_execution: int,
    execution_gas_used: int,
    refund: int,
    refund_test_type: RefundTestType,
) -> None:
    """
    Test gas refunds deducted from the execution gas cost and not the data
    floor.
    """
    gas_used = (
        tx_intrinsic_gas_cost_before_execution + execution_gas_used - refund
    )
    if (
        refund_test_type
        == RefundTestType.EXECUTION_GAS_MINUS_REFUND_LESS_THAN_DATA_FLOOR
    ):
        assert gas_used < tx_floor_data_cost
    elif (
        refund_test_type
        == RefundTestType.EXECUTION_GAS_MINUS_REFUND_GREATER_THAN_DATA_FLOOR
    ):
        assert gas_used > tx_floor_data_cost
    elif (
        refund_test_type
        == RefundTestType.EXECUTION_GAS_MINUS_REFUND_EQUAL_TO_DATA_FLOOR
    ):
        assert gas_used == tx_floor_data_cost
    else:
        raise ValueError("Invalid refund test type")
    if gas_used < tx_floor_data_cost:
        gas_used = tx_floor_data_cost
    # This is the actual test verification:
    #   - During test filling, the receipt returned by the transition tool
    #     (t8n) is verified against the expected receipt.
    #   - During test consumption, this is reflected in the balance difference
    #     and the state root.
    tx.expected_receipt = TransactionReceipt(cumulative_gas_used=gas_used)
    state_test(
        pre=pre,
        post={
            tx.to: {
                # Verify that the storage was cleared (for storage clear
                # refund). See `code_storage` fixture for more details.
                "storage": {0: 0},
            }
        },
        tx=tx,
    )

Parametrized Test Cases

This test generates 9 parametrized test cases across 3 forks.