Skip to content

test_stack_access_initcode_create()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_execution_contexts.py::test_stack_access_initcode_create@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_initcode_create --fork Amsterdam

Test DUPN, SWAPN and EXCHANGE inside initcode executed via CREATE and CREATE2.

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_execution_contexts.py
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
@EIPChecklist.Opcode.Test.ExecutionContext.Initcode.Behavior()
@EIPChecklist.Opcode.Test.ExecutionContext.Initcode.Behavior.Opcode()
@pytest.mark.parametrize("opcode", [Op.CREATE, Op.CREATE2])
def test_stack_access_initcode_create(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Op,
) -> None:
    """
    Test DUPN, SWAPN and EXCHANGE inside initcode executed via CREATE
    and CREATE2.
    """
    init_code = stack_access_storage_code()

    factory_code = (
        Op.CALLDATACOPY(offset=0, size=len(init_code))
        + opcode(offset=0, size=len(init_code))
        + Op.STOP
    )
    factory_address = pre.deploy_contract(factory_code)

    created_contract_address = compute_create_address(
        address=factory_address,
        nonce=1,
        initcode=init_code,
        opcode=opcode,
    )

    tx = Transaction(
        to=factory_address,
        data=init_code,
        sender=pre.fund_eoa(),
    )

    post = {
        created_contract_address: Account(storage=EXPECTED_STORAGE),
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.