Skip to content

test_bal_delegatecall_no_delegation_and_oog_before_target_access()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_opcodes.py::test_bal_delegatecall_no_delegation_and_oog_before_target_access@c74f1a67.

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

DELEGATECALL 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.

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
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
@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(
    "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_delegatecall_no_delegation_and_oog_before_target_access(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    fork: Fork,
    oog_boundary: OutOfGasBoundary,
    target_is_warm: bool,
    args_size: int,
    ret_size: int,
) -> None:
    """
    DELEGATECALL 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.

    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)

    delegatecall_code = Op.DELEGATECALL(
        address=target,
        gas=0,
        args_size=args_size,
        args_offset=0,
        ret_size=ret_size,
        ret_offset=0,
        address_warm=target_is_warm,
        new_memory_size=new_memory_size,
    )

    caller = pre.deploy_contract(code=delegatecall_code)

    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 + delegatecall_code.gas_cost(fork) - 1
    else:  # SUCCESS
        gas_limit = intrinsic_cost + delegatecall_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
        account_expectations = {
            caller: BalAccountExpectation.empty(),
            target: BalAccountExpectation.empty(),
        }

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations=account_expectations
                ),
            )
        ],
        post={alice: Account(nonce=1)},
    )

Parametrized Test Cases

This test generates 16 parametrized test cases across 1 fork.