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@5c024cbb.

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
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
@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()

    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)

    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.