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@892e6d1e.

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
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
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,
        gas_limit=1_000_000,
        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.