Skip to content

test_call_pointer_to_created_from_create_after_oog_call_again()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_call_pointer_to_created_from_create_after_oog_call_again@e9958ed2.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_call_pointer_to_created_from_create_after_oog_call_again --fork Osaka

Set pointer to account that we are about to create.

Pointer is set to create address that is yet not in the state.

During the call, address is created. pointer is called from init code to do nothing.

Then after account is created it is called again to run created code

Then revert / no revert.

Call pointer again from the upper level to ensure it does not call reverted code.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
@pytest.mark.valid_from("Prague")
@pytest.mark.parametrize("call_return", [Op.RETURN, Op.REVERT, Macros.OOG])
def test_call_pointer_to_created_from_create_after_oog_call_again(
    state_test: StateTestFiller, pre: Alloc, call_return: Op
) -> None:
    """
    Set pointer to account that we are about to create.

    Pointer is set to create address that is yet not in the state.

    During the call, address is created. pointer is called from init code
    to do nothing.

    Then after account is created it is called again to run created code

    Then revert / no revert.

    Call pointer again from the upper level to ensure it does not call reverted
    code.
    """
    env = Environment()

    storage_pointer = Storage()
    pointer = pre.fund_eoa()
    sender = pre.fund_eoa()

    storage_contract = Storage()
    slot_create_res = storage_contract.store_next(1, "create_result")
    contract = pre.deploy_contract(
        code=Op.MSTORE(0, Op.CALLDATALOAD(0))
        + Op.MSTORE(32, Op.CALLDATALOAD(32))
        + Op.SSTORE(slot_create_res, Op.CREATE(0, 0, Op.CALLDATASIZE()))
        + Op.CALL(address=pointer)
        + call_return(0, 32)
    )
    contract_main = pre.deploy_contract(
        code=Op.MSTORE(0, Op.CALLDATALOAD(0))
        + Op.MSTORE(32, Op.CALLDATALOAD(32))
        + Op.CALL(address=contract, args_size=Op.CALLDATASIZE())
        + Op.CALL(address=pointer)
    )
    contract_create = compute_create_address(address=contract, nonce=1)
    storage_contract[slot_create_res] = contract_create if call_return == Op.RETURN else 0

    slot_pointer_calls = storage_pointer.store_next(
        1 + 1 if call_return == Op.RETURN else 0, "pointer_calls"
    )
    deploy_code = Op.SSTORE(
        slot_pointer_calls,
        Op.ADD(1, Op.SLOAD(slot_pointer_calls)),
    )
    storage_create = Storage()
    tx = Transaction(
        to=contract_main,
        gas_limit=800_000,
        data=Op.SSTORE(storage_create.store_next(1, "create_init_code"), 1)
        + Op.SSTORE(
            storage_create.store_next(1, "call_pointer_from_init"), Op.CALL(address=pointer)
        )
        + Op.MSTORE(0, deploy_code.hex())
        + Op.RETURN(32 - len(deploy_code), len(deploy_code)),
        value=0,
        sender=sender,
        authorization_list=[
            AuthorizationTuple(
                address=contract_create,
                nonce=0,
                signer=pointer,
            )
        ],
    )
    post = {
        contract_create: Account(storage=storage_create) if call_return == Op.RETURN else None,
        contract: Account(storage=storage_contract),
        pointer: Account(storage=storage_pointer),
    }
    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) call_return
...fork_Prague-state_test-call_return_RETURN RETURN
...fork_Prague-state_test-call_return_REVERT REVERT
...fork_Prague-state_test-call_return_OOG OOG
...fork_Prague-blockchain_test_from_state_test-call_return_RETURN RETURN
...fork_Prague-blockchain_test_from_state_test-call_return_REVERT REVERT
...fork_Prague-blockchain_test_from_state_test-call_return_OOG OOG
...fork_Osaka-state_test-call_return_RETURN RETURN
...fork_Osaka-state_test-call_return_REVERT REVERT
...fork_Osaka-state_test-call_return_OOG OOG
...fork_Osaka-blockchain_test_from_state_test-call_return_RETURN RETURN
...fork_Osaka-blockchain_test_from_state_test-call_return_REVERT REVERT
...fork_Osaka-blockchain_test_from_state_test-call_return_OOG OOG