Skip to content

test_slotnum_call_contexts()

Documentation for tests/amsterdam/eip7843_slotnum/test_slotnum.py::test_slotnum_call_contexts@ca7cac5c.

Generate fixtures for these test cases for Amsterdam with:

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

Test that SLOTNUM returns the slot number in every call frame type.

The callee writes SLOTNUM to memory and returns it, so the check also holds inside STATICCALL frames where storage writes are banned. The caller stores the call's success flag and the returned value.

Source code in tests/amsterdam/eip7843_slotnum/test_slotnum.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
@EIPChecklist.Opcode.Test.ExecutionContext.Call()
@EIPChecklist.Opcode.Test.ExecutionContext.Callcode()
@EIPChecklist.Opcode.Test.ExecutionContext.Delegatecall()
@EIPChecklist.Opcode.Test.ExecutionContext.Staticcall()
@pytest.mark.with_all_call_opcodes
def test_slotnum_call_contexts(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
) -> None:
    """
    Test that SLOTNUM returns the slot number in every call frame type.

    The callee writes SLOTNUM to memory and returns it, so the check
    also holds inside STATICCALL frames where storage writes are banned.
    The caller stores the call's success flag and the returned value.
    """
    slot_number = 0xC0FFEE

    callee_code = Op.MSTORE(0, Op.SLOTNUM) + Op.RETURN(0, 32)
    callee_address = pre.deploy_contract(callee_code)

    caller_code = Op.SSTORE(
        0, call_opcode(address=callee_address, ret_offset=0, ret_size=32)
    ) + Op.SSTORE(1, Op.MLOAD(0))
    caller_address = pre.deploy_contract(caller_code)

    tx = Transaction(
        sender=pre.fund_eoa(),
        to=caller_address,
    )

    post = {
        caller_address: Account(
            storage={0: 1, 1: slot_number},
        ),
    }

    state_test(
        env=Environment(slot_number=slot_number),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.