Skip to content

test_bal_call_no_delegation_and_oog_before_target_access()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_call_no_delegation_and_oog_before_target_access@892e6d1e.

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_call_no_delegation_and_oog_before_target_access --fork Amsterdam

CALL without 7702 delegation - test SUCCESS and OOG before target access.

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.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
@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(
    "target_is_empty", [False, True], ids=["existing_target", "empty_target"]
)
@pytest.mark.parametrize("value", [0, 1], ids=["no_value", "with_value"])
@pytest.mark.parametrize(
    "memory_expansion", [False, True], ids=["no_memory", "with_memory"]
)
def test_bal_call_no_delegation_and_oog_before_target_access(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    oog_boundary: OutOfGasBoundary,
    target_is_warm: bool,
    target_is_empty: bool,
    value: int,
    memory_expansion: bool,
) -> None:
    """
    CALL without 7702 delegation - test SUCCESS and OOG before target access.

    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.
    """
    alice = pre.fund_eoa()

    target = (
        pre.nonexistent_account()
        if target_is_empty
        else pre.deploy_contract(code=Op.STOP)
    )

    ret_size = 32 if memory_expansion else 0

    # Full gas metadata: includes create_cost when applicable
    call_code = Op.CALL(
        gas=0,
        address=target,
        value=value,
        ret_size=ret_size,
        ret_offset=0,
        address_warm=target_is_warm,
        value_transfer=value > 0,
        account_new=value > 0 and target_is_empty,
        new_memory_size=ret_size,
    )
    caller = pre.deploy_contract(code=call_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:
        # Static gas (before state access): no create_cost
        call_static = Op.CALL(
            gas=0,
            address=target,
            value=value,
            ret_size=ret_size,
            ret_offset=0,
            address_warm=target_is_warm,
            value_transfer=value > 0,
            account_new=False,
            new_memory_size=ret_size,
        )
        gas_limit = intrinsic_cost + call_static.gas_cost(fork) - 1
    else:  # SUCCESS
        gas_limit = intrinsic_cost + call_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,
        }
    elif value > 0:
        account_expectations = {
            caller: BalAccountExpectation(
                balance_changes=[
                    BalBalanceChange(block_access_index=1, post_balance=0)
                ]
            ),
            target: BalAccountExpectation(
                balance_changes=[
                    BalBalanceChange(block_access_index=1, post_balance=value)
                ]
            ),
        }
    else:
        account_expectations = {
            caller: BalAccountExpectation.empty(),
            target: BalAccountExpectation.empty(),
        }

    value_transferred = value > 0 and oog_boundary == OutOfGasBoundary.SUCCESS

    post_state: Dict[Address, Account | None] = {alice: Account(nonce=1)}

    if value_transferred:
        post_state[target] = Account(balance=value)
        post_state[caller] = Account(balance=0)
    else:
        post_state[caller] = Account(balance=value)
        post_state[target] = (
            Account.NONEXISTENT
            if target_is_empty
            else Account(balance=0, code=Op.STOP)
        )

    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.