Skip to content

test_bal_withdrawal_and_state_access_same_account()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_and_state_access_same_account@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_and_state_access_same_account --fork Amsterdam

Ensure BAL captures both state access and withdrawal to same address.

Oracle contract starts with 0 balance and storage slot 0x01 = 0x42. Alice calls Oracle (reads slot 0x01, writes 0x99 to slot 0x02). Oracle receives withdrawal of 10 gwei. Both state access and withdrawal are captured in BAL.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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
def test_bal_withdrawal_and_state_access_same_account(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Ensure BAL captures both state access and withdrawal to same address.

    Oracle contract starts with 0 balance and storage slot 0x01 = 0x42.
    Alice calls Oracle (reads slot 0x01, writes 0x99 to slot 0x02).
    Oracle receives withdrawal of 10 gwei.
    Both state access and withdrawal are captured in BAL.
    """
    alice = pre.fund_eoa()
    oracle = pre.deploy_contract(
        code=Op.SLOAD(0x01) + Op.SSTORE(0x02, 0x99),
        storage={0x01: 0x42},
    )

    tx = Transaction(
        sender=alice,
        to=oracle,
        gas_limit=1_000_000,
        gas_price=0xA,
    )

    block = Block(
        txs=[tx],
        withdrawals=[
            Withdrawal(
                index=0,
                validator_index=0,
                address=oracle,
                amount=10,
            )
        ],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                oracle: BalAccountExpectation(
                    storage_reads=[0x01],
                    storage_changes=[
                        BalStorageSlot(
                            slot=0x02,
                            slot_changes=[
                                BalStorageChange(
                                    block_access_index=1, post_value=0x99
                                )
                            ],
                        )
                    ],
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=2, post_balance=10 * GWEI
                        )
                    ],
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            oracle: Account(
                balance=10 * GWEI,
                storage={0x01: 0x42, 0x02: 0x99},
            ),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.