Skip to content

test_ext_code_on_self_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_ext_code_on_self_set_code@14a7429a.

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_set_code --fork Prague

Test different ext*code operations on self set-code address.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
@pytest.mark.parametrize(
    "balance",
    [0, 1],
)
def test_ext_code_on_self_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    balance: int,
):
    """Test different ext*code operations on self set-code address."""
    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)

    set_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
    )
    set_code_address = pre.deploy_contract(set_code)

    set_code_storage = Storage()
    set_code_storage[slot_ext_code_size_result] = len(
        Spec.delegation_designation(set_code_address)
    )
    set_code_storage[slot_ext_code_hash_result] = Spec.delegation_designation(
        set_code_address
    ).keccak256()
    set_code_storage[slot_ext_code_copy_result] = Hash(
        Spec.delegation_designation(set_code_address), right_padding=True
    )
    set_code_storage[slot_ext_balance_result] = balance

    tx = Transaction(
        gas_limit=10_000_000,
        to=auth_signer,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            auth_signer: Account(storage=set_code_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