Skip to content

test_bal_cross_tx_storage_write()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_cross_tx_storage_write@87aba1a3.

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

Tx1's storage_change must be preserved regardless of tx2's write.

Regression for the blobhash scenario where back-to-pre writes were filtered as net-zero across tx boundaries. The same-value case additionally exercises the uniqueness rule: a slot in storage_changes MUST NOT also appear in storage_reads.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
@pytest.mark.parametrize(
    "tx2_value",
    [
        pytest.param(0x0, id="tx2_reverts_to_zero"),
        pytest.param(0xABCD, id="tx2_rewrites_same_value"),
    ],
)
def test_bal_cross_tx_storage_write(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    tx2_value: int,
) -> None:
    """
    Tx1's storage_change must be preserved regardless of tx2's write.

    Regression for the blobhash scenario where back-to-pre writes were
    filtered as net-zero across tx boundaries. The same-value case
    additionally exercises the uniqueness rule: a slot in storage_changes
    MUST NOT also appear in storage_reads.
    """
    alice = pre.fund_eoa()
    tx1_value = 0xABCD

    contract = pre.deploy_contract(code=Op.SSTORE(0, Op.CALLDATALOAD(0)))

    tx1 = Transaction(
        sender=alice,
        to=contract,
        data=Hash(tx1_value),
    )

    tx2 = Transaction(
        sender=alice,
        to=contract,
        data=Hash(tx2_value),
    )

    slot_changes = [
        BalStorageChange(block_access_index=1, post_value=tx1_value),
    ]
    if tx2_value != tx1_value:
        slot_changes.append(
            BalStorageChange(block_access_index=2, post_value=tx2_value)
        )

    account_expectations = {
        alice: BalAccountExpectation(
            nonce_changes=[
                BalNonceChange(block_access_index=1, post_nonce=1),
                BalNonceChange(block_access_index=2, post_nonce=2),
            ],
        ),
        contract: BalAccountExpectation(
            storage_changes=[
                BalStorageSlot(slot=0, slot_changes=slot_changes),
            ],
            storage_reads=[],
        ),
    }

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx1, tx2],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post={
            alice: Account(nonce=2),
            contract: Account(storage={0: tx2_value}),
        },
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.