Skip to content

test_bal_intra_tx_multiple_sstores_same_slot()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_intra_tx_multiple_sstores_same_slot@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_intra_tx_multiple_sstores_same_slot --fork Bogota

Test that consecutive SSTOREs to the same slot within one tx produce a single storage change with the final post-value; intermediate writes (0xAA, 0xBB) must not appear in the BAL.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
@pytest.mark.parametrize(
    "pre_value",
    [
        pytest.param(0x00, id="slot_starts_empty"),
        pytest.param(0x11, id="slot_starts_nonzero"),
        pytest.param(0xBB, id="intermediate_equals_pre"),
    ],
)
def test_bal_intra_tx_multiple_sstores_same_slot(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    pre_value: int,
) -> None:
    """
    Test that consecutive SSTOREs to the same slot within one tx produce a
    single storage change with the final post-value; intermediate writes
    (0xAA, 0xBB) must not appear in the BAL.
    """
    alice = pre.fund_eoa()

    code = (
        Op.SSTORE(0x01, 0xAA) + Op.SSTORE(0x01, 0xBB) + Op.SSTORE(0x01, 0xCC)
    )
    contract = pre.deploy_contract(code=code, storage={0x01: pre_value})

    tx = Transaction(sender=alice, to=contract)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                ),
                            ],
                        ),
                        contract: BalAccountExpectation(
                            storage_changes=[
                                BalStorageSlot(
                                    slot=0x01,
                                    slot_changes=[
                                        BalStorageChange(
                                            block_access_index=1,
                                            post_value=0xCC,
                                        ),
                                    ],
                                ),
                            ],
                            storage_reads=[],
                            balance_changes=[],
                            code_changes=[],
                            absent_values=BalAccountAbsentValues(
                                storage_changes=[
                                    BalStorageSlot(
                                        slot=0x01,
                                        slot_changes=[
                                            BalStorageChange(
                                                block_access_index=1,
                                                post_value=0xAA,
                                            ),
                                            BalStorageChange(
                                                block_access_index=1,
                                                post_value=0xBB,
                                            ),
                                        ],
                                    ),
                                ],
                            ),
                        ),
                    }
                ),
            )
        ],
        post={
            alice: Account(nonce=1),
            contract: Account(storage={0x01: 0xCC}),
        },
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 2 forks.