Skip to content

test_bal_multiple_storage_writes_same_slot()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_multiple_storage_writes_same_slot@892e6d1e.

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

Test that BAL tracks multiple writes to the same storage slot across transactions in the same block.

Setup: - Deploy a contract that increments storage slot 1 on each call - Alice calls the contract 3 times in the same block - Each call increments slot 1: 0 -> 1 -> 2 -> 3

Expected BAL: - Contract should have 3 storage_changes for slot 1: * txIndex 1: postValue = 1 * txIndex 2: postValue = 2 * txIndex 3: postValue = 3

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
def test_bal_multiple_storage_writes_same_slot(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """
    Test that BAL tracks multiple writes to the same storage slot across
    transactions in the same block.

    Setup:
    - Deploy a contract that increments storage slot 1 on each call
    - Alice calls the contract 3 times in the same block
    - Each call increments slot 1: 0 -> 1 -> 2 -> 3

    Expected BAL:
    - Contract should have 3 storage_changes for slot 1:
      * txIndex 1: postValue = 1
      * txIndex 2: postValue = 2
      * txIndex 3: postValue = 3
    """
    alice = pre.fund_eoa(amount=10**18)

    increment_code = Op.SSTORE(1, Op.ADD(Op.SLOAD(1), 1))
    contract = pre.deploy_contract(code=increment_code)

    tx1 = Transaction(sender=alice, to=contract, gas_limit=200_000)
    tx2 = Transaction(sender=alice, to=contract, gas_limit=200_000)
    tx3 = Transaction(sender=alice, to=contract, gas_limit=200_000)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx1, tx2, tx3],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        alice: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1, post_nonce=1
                                ),
                                BalNonceChange(
                                    block_access_index=2, post_nonce=2
                                ),
                                BalNonceChange(
                                    block_access_index=3, post_nonce=3
                                ),
                            ],
                        ),
                        contract: BalAccountExpectation(
                            storage_changes=[
                                BalStorageSlot(
                                    slot=1,
                                    slot_changes=[
                                        BalStorageChange(
                                            block_access_index=1, post_value=1
                                        ),
                                        BalStorageChange(
                                            block_access_index=2, post_value=2
                                        ),
                                        BalStorageChange(
                                            block_access_index=3, post_value=3
                                        ),
                                    ],
                                ),
                            ],
                            storage_reads=[],
                            balance_changes=[],
                            code_changes=[],
                        ),
                    }
                ),
            )
        ],
        post={
            alice: Account(nonce=3),
            contract: Account(storage={1: 3}),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.