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
| @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,
)
|