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@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_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
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
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.