Skip to content

test_repeated_address_acl()

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

Generate fixtures for these test cases for Amsterdam with:

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

Tests that slots are warmed correctly in an access list that has the same address repeated more than once, each time with different slots.

Difference with other ACL tests is that we actually try to access both slots at runtime. We also measure the gas cost of each access in order to make debugging easier.

Source code in tests/berlin/eip2930_access_list/test_acl.py
281
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
def test_repeated_address_acl(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Tests that slots are warmed correctly in an access list that has the same
    address repeated more than once, each time with different slots.

    Difference with other ACL tests is that we actually try to
    access both slots at runtime. We also measure the gas cost
    of each access in order to make debugging easier.
    """
    sender = pre.fund_eoa()

    # Cost of pushing SLOAD args
    sload_push_cost = (Op.PUSH1(0) * len(Op.SLOAD.kwargs)).gas_cost(fork)

    sload0_measure = CodeGasMeasure(
        code=Op.SLOAD(0),
        overhead_cost=sload_push_cost,
        extra_stack_items=1,  # SLOAD pushes 1 item to the stack
        sstore_key=0,
        stop=False,  # Because it's the first CodeGasMeasure
    )

    sload1_measure = CodeGasMeasure(
        code=Op.SLOAD(1),
        overhead_cost=sload_push_cost,
        extra_stack_items=1,  # SLOAD pushes 1 item to the stack
        sstore_key=1,
    )

    contract = pre.deploy_contract(sload0_measure + sload1_measure)

    tx = Transaction(
        gas_limit=500_000,
        to=contract,
        value=0,
        sender=sender,
        access_list=[
            AccessList(
                address=contract,
                storage_keys=[0],
            ),
            AccessList(
                address=contract,
                storage_keys=[1],
            ),
        ],
    )

    sload_cost = Op.SLOAD(key_warm=True).gas_cost(fork)

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            contract: Account(
                storage={0: sload_cost, 1: sload_cost},
            )
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 8 forks.