Skip to content

test_ext_code_on_self_delegating_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_ext_code_on_self_delegating_set_code@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_ext_code_on_self_delegating_set_code --fork Prague

Test different ext*code operations on a set-code address that delegates to itself.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
@pytest.mark.parametrize(
    "balance",
    [0, 1],
)
def test_ext_code_on_self_delegating_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    balance: int,
):
    """Test different ext*code operations on a set-code address that delegates to itself."""
    auth_signer = pre.fund_eoa(balance)

    slot = count(1)
    slot_ext_code_size_result = next(slot)
    slot_ext_code_hash_result = next(slot)
    slot_ext_code_copy_result = next(slot)
    slot_ext_balance_result = next(slot)

    callee_code = (
        Op.SSTORE(slot_ext_code_size_result, Op.EXTCODESIZE(auth_signer))
        + Op.SSTORE(slot_ext_code_hash_result, Op.EXTCODEHASH(auth_signer))
        + Op.EXTCODECOPY(auth_signer, 0, 0, Op.EXTCODESIZE(auth_signer))
        + Op.SSTORE(slot_ext_code_copy_result, Op.MLOAD(0))
        + Op.SSTORE(slot_ext_balance_result, Op.BALANCE(auth_signer))
        + Op.STOP
    )
    callee_address = pre.deploy_contract(callee_code)
    callee_storage = Storage()

    callee_storage[slot_ext_code_size_result] = len(Spec.delegation_designation(auth_signer))
    callee_storage[slot_ext_code_hash_result] = Spec.delegation_designation(
        auth_signer
    ).keccak256()
    callee_storage[slot_ext_code_copy_result] = Hash(
        Spec.delegation_designation(auth_signer), right_padding=True
    )
    callee_storage[slot_ext_balance_result] = balance

    tx = Transaction(
        gas_limit=10_000_000,
        to=callee_address,
        authorization_list=[
            AuthorizationTuple(
                address=auth_signer,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),  # TODO: Test with sender as auth_signer
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(
                nonce=1,
                code=Spec.delegation_designation(auth_signer),
                balance=balance,
            ),
            callee_address: Account(storage=callee_storage),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) balance
...fork_Prague-state_test-balance_0 0
...fork_Prague-state_test-balance_1 1
...fork_Prague-blockchain_test_from_state_test-balance_0 0
...fork_Prague-blockchain_test_from_state_test-balance_1 1
...fork_Osaka-state_test-balance_0 0
...fork_Osaka-state_test-balance_1 1
...fork_Osaka-blockchain_test_from_state_test-balance_0 0
...fork_Osaka-blockchain_test_from_state_test-balance_1 1