Skip to content

test_bal_delegated_storage_reads()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_delegated_storage_reads@20373115.

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_reads --fork Amsterdam

Ensure BAL captures delegated storage reads via DELEGATECALL and CALLCODE.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
@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_reads(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    delegated_opcode: Callable[[Address], Op],
) -> None:
    """
    Ensure BAL captures delegated storage reads via
    DELEGATECALL and CALLCODE.
    """
    alice = pre.fund_eoa()

    # TargetContract that reads from slot 0x01
    target_code = Op.SLOAD(0x01) + Op.STOP
    target_contract = pre.deploy_contract(code=target_code)

    # Oracle contract with storage slot 0x01 = 0x42,
    # uses delegated opcode to execute TargetContract's code
    oracle_code = delegated_opcode(target_contract)
    oracle_contract = pre.deploy_contract(
        code=oracle_code, storage={0x01: 0x42}
    )

    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_reads=[0x01],
                ),
                target_contract: BalAccountExpectation.empty(),
            }
        ),
    )

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.