Skip to content

test_bal_2935_selfdestruct_to_history_storage()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip2935.py::test_bal_2935_selfdestruct_to_history_storage@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip2935.py::test_bal_2935_selfdestruct_to_history_storage --fork Amsterdam

Ensure BAL captures SELFDESTRUCT to history storage address alongside system call storage writes.

Single block with pre-execution system call writing parent hash to storage, followed by transaction where contract selfdestructs sending funds to HISTORY_STORAGE_ADDRESS. Tests that same address can appear in BAL with different change types (storage_changes and balance_changes) at different transaction indices.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip2935.py
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def test_bal_2935_selfdestruct_to_history_storage(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
) -> None:
    """
    Ensure BAL captures SELFDESTRUCT to history storage address alongside
    system call storage writes.

    Single block with pre-execution system call writing parent hash to
    storage, followed by transaction where contract selfdestructs sending
    funds to HISTORY_STORAGE_ADDRESS. Tests that same address can appear in
    BAL with different change types (storage_changes and balance_changes)
    at different transaction indices.
    """
    alice = pre.fund_eoa()

    contract_balance = 100

    # Contract that selfdestructs to history storage address
    selfdestruct_code = Op.SELFDESTRUCT(HISTORY_STORAGE_ADDRESS)
    selfdestruct_contract = pre.deploy_contract(
        code=selfdestruct_code,
        balance=contract_balance,
    )

    tx = Transaction(
        sender=alice,
        to=selfdestruct_contract,
        gas_limit=fork.transaction_gas_limit_cap(),
    )

    account_expectations = block_hash_system_call_expectations(0)

    # Add balance change from selfdestruct to history storage address
    account_expectations[HISTORY_STORAGE_ADDRESS].balance_changes = [
        BalBalanceChange(block_access_index=1, post_balance=contract_balance)
    ]

    # Add transaction-specific expectations
    account_expectations[alice] = BalAccountExpectation(
        nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
    )
    account_expectations[selfdestruct_contract] = BalAccountExpectation(
        balance_changes=[
            BalBalanceChange(block_access_index=1, post_balance=0)
        ],
    )

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations=account_expectations
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            HISTORY_STORAGE_ADDRESS: Account(balance=contract_balance),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.