Skip to content

test_stack_access_call_contexts()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_execution_contexts.py::test_stack_access_call_contexts@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_execution_contexts.py::test_stack_access_call_contexts --fork Amsterdam

Test DUPN, SWAPN and EXCHANGE in every call frame type.

The callee returns each opcode's result through memory, so the check also holds inside STATICCALL frames where storage writes are banned. The caller stores the call's success flag and the returned markers.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_execution_contexts.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@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_stack_access_call_contexts(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
) -> None:
    """
    Test DUPN, SWAPN and EXCHANGE in every call frame type.

    The callee returns each opcode's result through memory, so the check
    also holds inside STATICCALL frames where storage writes are banned.
    The caller stores the call's success flag and the returned markers.
    """
    callee_address = pre.deploy_contract(stack_access_memory_code())

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

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

    post = {
        caller_address: Account(
            storage={
                0: 1,
                1: DUPN_MARKER,
                2: SWAPN_MARKER,
                3: EXCHANGE_MARKER,
            },
        ),
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.