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@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_intra_tx_multiple_sstores_same_slot --fork Amsterdam

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
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
@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 1 fork.