Skip to content

test_bal_delegated_storage_writes()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_delegated_storage_writes@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_delegated_storage_writes --fork Amsterdam

Ensure BAL captures delegated storage writes via DELEGATECALL and CALLCODE.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
@pytest.mark.parametrize(
    "delegated_opcode",
    [
        pytest.param(
            lambda target_addr: Op.DELEGATECALL(
                50000, target_addr, 0, 0, 0, 0
            ),
            id="delegatecall",
        ),
        pytest.param(
            lambda target_addr: Op.CALLCODE(50000, target_addr, 0, 0, 0, 0, 0),
            id="callcode",
        ),
    ],
)
def test_bal_delegated_storage_writes(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    delegated_opcode: Callable[[Address], Op],
) -> None:
    """
    Ensure BAL captures delegated storage writes via
    DELEGATECALL and CALLCODE.
    """
    alice = pre.fund_eoa()

    # TargetContract that writes 0x42 to slot 0x01
    target_code = Op.SSTORE(0x01, 0x42)
    target_contract = pre.deploy_contract(code=target_code)

    # Oracle contract that uses delegated opcode to execute
    # TargetContract's code
    oracle_code = delegated_opcode(target_contract)
    oracle_contract = pre.deploy_contract(code=oracle_code)

    tx = Transaction(
        sender=alice,
        to=oracle_contract,
        gas_limit=1_000_000,
    )

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                oracle_contract: BalAccountExpectation(
                    storage_changes=[
                        BalStorageSlot(
                            slot=0x01,
                            slot_changes=[
                                BalStorageChange(
                                    block_access_index=1, post_value=0x42
                                )
                            ],
                        )
                    ],
                ),
                target_contract: BalAccountExpectation.empty(),
            }
        ),
    )

    blockchain_test(pre=pre, blocks=[block], post={})

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.