Skip to content

test_bal_callcode_no_delegation_and_oog_before_target_access()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_callcode_no_delegation_and_oog_before_target_access@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_callcode_no_delegation_and_oog_before_target_access --fork Amsterdam

CALLCODE without 7702 delegation - test SUCCESS and OOG boundaries.

When target_is_warm=True, we use EIP-2930 tx access list to warm the target. Access list warming does NOT add to BAL - only EVM access does. CALLCODE has no balance transfer to target (runs in caller's context).

Memory expansion is parametrized independently for args and ret per #1910.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
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
@pytest.mark.parametrize(
    "oog_boundary",
    [OutOfGasBoundary.SUCCESS, OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS],
    ids=lambda x: x.value,
)
@pytest.mark.parametrize(
    "target_is_warm", [False, True], ids=["cold_target", "warm_target"]
)
@pytest.mark.parametrize("value", [0, 1], ids=["no_value", "with_value"])
@pytest.mark.parametrize(
    "args_size,ret_size",
    [
        pytest.param(0, 0, id="no_memory"),
        pytest.param(4096, 0, id="args_large"),
        pytest.param(0, 4096, id="ret_large"),
        pytest.param(32, 32, id="both_small"),
    ],
)
def test_bal_callcode_no_delegation_and_oog_before_target_access(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    oog_boundary: OutOfGasBoundary,
    target_is_warm: bool,
    value: int,
    args_size: int,
    ret_size: int,
) -> None:
    """
    CALLCODE without 7702 delegation - test SUCCESS and OOG boundaries.

    When target_is_warm=True, we use EIP-2930 tx access list to warm the
    target. Access list warming does NOT add to BAL - only EVM access does.
    CALLCODE has no balance transfer to target (runs in caller's context).

    Memory expansion is parametrized independently for args and ret per #1910.
    """
    alice = pre.fund_eoa()

    target = pre.deploy_contract(code=Op.STOP)

    new_memory_size = max(args_size, ret_size)

    callcode_code = Op.CALLCODE(
        gas=0,
        address=target,
        value=value,
        args_size=args_size,
        args_offset=0,
        ret_size=ret_size,
        ret_offset=0,
        address_warm=target_is_warm,
        value_transfer=value > 0,
        account_new=False,
        new_memory_size=new_memory_size,
    )
    caller = pre.deploy_contract(code=callcode_code, balance=value)

    access_list = (
        [AccessList(address=target, storage_keys=[])]
        if target_is_warm
        else None
    )

    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()(
        access_list=access_list
    )

    if oog_boundary == OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS:
        gas_limit = intrinsic_cost + callcode_code.gas_cost(fork) - 1
    else:  # SUCCESS
        gas_limit = intrinsic_cost + callcode_code.gas_cost(fork)

    tx = Transaction(
        sender=alice,
        to=caller,
        gas_limit=gas_limit,
        access_list=access_list,
    )

    # BAL expectations
    account_expectations: Dict[Address, BalAccountExpectation | None]
    if oog_boundary == OutOfGasBoundary.OOG_BEFORE_TARGET_ACCESS:
        # Target NOT in BAL - we OOG before state access
        account_expectations = {
            caller: BalAccountExpectation.empty(),
            target: None,
        }
    else:  # SUCCESS - target in BAL (no balance changes, CALLCODE no transfer)
        account_expectations = {
            caller: BalAccountExpectation.empty(),
            target: BalAccountExpectation.empty(),
        }

    # Post-state: CALLCODE runs in caller's context, so value transfer is
    # caller-to-caller (net-zero). Caller keeps its balance regardless.
    post_state: Dict[Address, Account] = {
        alice: Account(nonce=1),
        caller: Account(balance=value),
    }

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post=post_state,
    )

Parametrized Test Cases

This test generates 32 parametrized test cases across 1 fork.