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@622620d8.

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
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
@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.