Skip to content

test_bal_withdrawal_to_7702_delegation()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_withdrawal_to_7702_delegation@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_withdrawal_to_7702_delegation --fork Amsterdam

Test BAL with withdrawal to 7702 delegated account.

Tx1: Alice delegates to Oracle. Withdrawal: 10 gwei to Alice. Withdrawals credit balance without executing code.

Expected BAL: - Alice tx1: code_changes (delegation), nonce_changes - Alice tx2: balance_changes (+10 gwei) - Oracle: MUST NOT appear (withdrawals don't execute recipient code)

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
def test_bal_withdrawal_to_7702_delegation(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Test BAL with withdrawal to 7702 delegated account.

    Tx1: Alice delegates to Oracle. Withdrawal: 10 gwei to Alice.
    Withdrawals credit balance without executing code.

    Expected BAL:
    - Alice tx1: code_changes (delegation), nonce_changes
    - Alice tx2: balance_changes (+10 gwei)
    - Oracle: MUST NOT appear (withdrawals don't execute recipient code)
    """
    # Alice (EOA) will receive delegation then receive withdrawal
    alice_initial_balance = 10**18  # 1 ETH default
    alice = pre.fund_eoa(amount=alice_initial_balance)
    bob = pre.fund_eoa(amount=0)  # Recipient of tx value

    # Oracle contract that Alice will delegate to
    # If delegation were followed, this would write to storage
    oracle = pre.deploy_contract(code=Op.SSTORE(0x01, 0x42) + Op.STOP)

    # Relayer for the delegation tx
    relayer = pre.fund_eoa()

    withdrawal_amount_gwei = 10

    # Tx1: Alice authorizes delegation to Oracle
    tx1 = Transaction(
        sender=relayer,
        to=bob,
        value=10,
        authorization_list=[
            AuthorizationTuple(
                address=oracle,
                nonce=0,
                signer=alice,
            )
        ],
    )

    alice_final_balance = alice_initial_balance + (
        withdrawal_amount_gwei * GWEI
    )

    account_expectations = {
        alice: BalAccountExpectation(
            # tx1: nonce change for auth, code change for delegation
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
            code_changes=[
                BalCodeChange(
                    block_access_index=1,
                    new_code=Spec7702.delegation_designation(oracle),
                )
            ],
            # tx2 (withdrawal): balance change
            balance_changes=[
                BalBalanceChange(
                    block_access_index=2, post_balance=alice_final_balance
                )
            ],
        ),
        bob: BalAccountExpectation(
            balance_changes=[
                BalBalanceChange(block_access_index=1, post_balance=10)
            ]
        ),
        relayer: BalAccountExpectation(
            nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
        ),
        # Oracle MUST NOT appear - withdrawals don't execute recipient code,
        # so delegation target is never accessed
        oracle: None,
    }

    block = Block(
        txs=[tx1],
        withdrawals=[
            Withdrawal(
                index=0,
                validator_index=0,
                address=alice,
                amount=withdrawal_amount_gwei,
            )
        ],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=account_expectations
        ),
    )

    post = {
        alice: Account(
            nonce=1,
            code=Spec7702.delegation_designation(oracle),
            balance=alice_final_balance,
        ),
        bob: Account(balance=10),
        relayer: Account(nonce=1),
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.