Skip to content

test_contract_creation_with_access_list()

Documentation for tests/amsterdam/eip7981_increase_access_list_cost/test_transaction_validity.py::test_contract_creation_with_access_list@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7981_increase_access_list_cost/test_transaction_validity.py::test_contract_creation_with_access_list --fork Amsterdam

Test the intrinsic boundary of a contract-creating transaction with an access list.

The EIP-7981 access list data cost stacks on top of the creation intrinsic (creation access and init code charges). The created account's state charge is applied at the top frame, after intrinsic validation, so the exact-gas arm funds it separately while the off-by-one arm pins the intrinsic requirement alone.

Source code in tests/amsterdam/eip7981_increase_access_list_cost/test_transaction_validity.py
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@pytest.mark.with_all_tx_types(selector=lambda tx_type: tx_type in (1, 2))
@pytest.mark.parametrize(
    "valid",
    [
        pytest.param(True, id="exact_gas"),
        pytest.param(
            False,
            id="insufficient_gas_by_one",
            marks=pytest.mark.exception_test,
        ),
    ],
)
def test_contract_creation_with_access_list(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    tx_type: int,
    valid: bool,
) -> None:
    """
    Test the intrinsic boundary of a contract-creating transaction with
    an access list.

    The EIP-7981 access list data cost stacks on top of the creation
    intrinsic (creation access and init code charges). The created
    account's state charge is applied at the top frame, after intrinsic
    validation, so the exact-gas arm funds it separately while the
    off-by-one arm pins the intrinsic requirement alone.
    """
    access_list = [
        AccessList(address=Address(1), storage_keys=[Hash(0), Hash(1)])
    ]
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        contract_creation=True,
        access_list=access_list,
        return_cost_deducted_prior_execution=True,
    )
    floor_gas = fork.transaction_data_floor_cost_calculator()(
        data=b"", access_list=access_list, contract_creation=True
    )
    assert floor_gas <= intrinsic_gas

    sender = pre.fund_eoa()
    post: dict = {}
    if valid:
        gas_limit = intrinsic_gas + fork.transaction_top_frame_state_gas(
            contract_creation=True
        )
        error = None
        created = compute_create_address(address=sender, nonce=sender.nonce)
        post[created] = Account(nonce=1, code=b"")
    else:
        gas_limit = intrinsic_gas - 1
        error = TransactionException.INTRINSIC_GAS_TOO_LOW

    tx = Transaction(
        ty=tx_type,
        sender=sender,
        to=None,
        access_list=access_list,
        gas_limit=gas_limit,
        error=error,
    )

    state_test(
        pre=pre,
        post=post,
        tx=tx,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.