Skip to content

test_clz_fork_transition()

Documentation for tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_fork_transition@0f7c73a7.

Generate fixtures for these test cases for Prague with:

fill -v tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py::test_clz_fork_transition --fork Prague

Test CLZ opcode behavior at fork transition.

Source code in tests/osaka/eip7939_count_leading_zeros/test_count_leading_zeros.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
@pytest.mark.valid_at_transition_to("Osaka", subsequent_forks=True)
def test_clz_fork_transition(blockchain_test: BlockchainTestFiller, pre: Alloc):
    """Test CLZ opcode behavior at fork transition."""
    sender = pre.fund_eoa()
    callee_address = pre.deploy_contract(
        code=Op.SSTORE(Op.TIMESTAMP, Op.CLZ(1 << 100)) + Op.STOP,
        storage={14_999: "0xdeadbeef"},
    )
    caller_address = pre.deploy_contract(
        code=Op.SSTORE(Op.TIMESTAMP, Op.CALL(gas=0xFFFF, address=callee_address)),
        storage={14_999: "0xdeadbeef"},
    )
    blocks = [
        Block(
            timestamp=14_999,
            txs=[
                Transaction(
                    to=caller_address,
                    sender=sender,
                    nonce=0,
                    gas_limit=200_000,
                )
            ],
        ),
        Block(
            timestamp=15_000,
            txs=[
                Transaction(
                    to=caller_address,
                    sender=sender,
                    nonce=1,
                    gas_limit=200_000,
                )
            ],
        ),
        Block(
            timestamp=15_001,
            txs=[
                Transaction(
                    to=caller_address,
                    sender=sender,
                    nonce=2,
                    gas_limit=200_000,
                )
            ],
        ),
    ]
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            caller_address: Account(
                storage={
                    14_999: 0,  # Call fails as opcode not valid before Osaka
                    15_000: 1,  # Call succeeds on fork transition block
                    15_001: 1,  # Call continues to succeed after transition
                }
            ),
            callee_address: Account(
                storage={
                    14_999: "0xdeadbeef",  # CLZ not valid before fork, storage unchanged
                    15_000: 155,  # CLZ valid on transition block, CLZ(1 << 100) = 155
                    15_001: 155,  # CLZ continues to be valid after transition
                }
            ),
        },
    )

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated)
...fork_PragueToOsakaAtTime15k-blockchain_test