Skip to content

test_slotnum_distinct_per_block()

Documentation for tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_distinct_per_block@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_distinct_per_block --fork Amsterdam

Test that SLOTNUM returns each block's own slot number.

Runs four consecutive blocks with deliberately non-monotonic slot numbers to disprove any caching or ordering assumption in the opcode implementation. Each block runs the same contract, which keys storage by block NUMBER so every block's outcome is independently visible in the final post-state.

Source code in tests/amsterdam/eip7843_slotnum/test_slotnum.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def test_slotnum_distinct_per_block(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """
    Test that SLOTNUM returns each block's own slot number.

    Runs four consecutive blocks with deliberately non-monotonic slot
    numbers to disprove any caching or ordering assumption in the opcode
    implementation. Each block runs the same contract, which keys storage
    by block ``NUMBER`` so every block's outcome is independently visible
    in the final post-state.
    """
    sender = pre.fund_eoa()
    contract = pre.deploy_contract(Op.SSTORE(Op.NUMBER, Op.SLOTNUM) + Op.STOP)

    # Non-monotonic on purpose: decrease, increase, jump to large value.
    slot_numbers = [100, 42, 7, 2**32]

    blocks = [
        Block(
            slot_number=slot,
            txs=[Transaction(sender=sender, to=contract)],
        )
        for slot in slot_numbers
    ]

    post = {
        contract: Account(
            storage={i + 1: slot for i, slot in enumerate(slot_numbers)},
        ),
    }

    blockchain_test(pre=pre, blocks=blocks, post=post)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.