Skip to content

test_bal_intra_tx_sstores_same_slot_net_zero()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_intra_tx_sstores_same_slot_net_zero@20373115.

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

Test that consecutive SSTOREs to the same slot within one tx with a net-zero result are filtered: the slot must appear in storage_reads (it was accessed) but must not appear in storage_changes.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
@pytest.mark.parametrize(
    "pre_value,writes",
    [
        pytest.param(
            0xCC, [0xAA, 0xBB, 0xCC], id="nonzero_pre_returns_to_pre"
        ),
        pytest.param(
            0x00, [0xAA, 0xBB, 0x00], id="empty_pre_ephemeral_writes"
        ),
    ],
)
def test_bal_intra_tx_sstores_same_slot_net_zero(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    pre_value: int,
    writes: list[int],
) -> None:
    """
    Test that consecutive SSTOREs to the same slot within one tx with a
    net-zero result are filtered: the slot must appear in storage_reads
    (it was accessed) but must not appear in storage_changes.
    """
    alice = pre.fund_eoa(amount=10**18)

    code = Op.SSTORE(0x01, writes[0])
    for v in writes[1:]:
        code += Op.SSTORE(0x01, v)
    contract = pre.deploy_contract(code=code, storage={0x01: pre_value})

    tx = Transaction(
        sender=alice,
        to=contract,
        gas_limit=200_000,
    )

    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_reads=[0x01],
                            storage_changes=[],
                            balance_changes=[],
                            code_changes=[],
                        ),
                    }
                ),
            )
        ],
        post={
            alice: Account(nonce=1),
            contract: Account(storage={0x01: pre_value}),
        },
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.