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@e9958ed2.

Generate fixtures for these test cases for Osaka with:

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

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
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
@pytest.mark.parametrize(
    "balance",
    [0, 1],
)
def test_ext_code_on_self_delegating_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    balance: int,
) -> None:
    """
    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