Skip to content

test_cross_frame_refund_with_reservoir_grant()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_cross_frame_refund_with_reservoir_grant@8acae1b0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py::test_cross_frame_refund_with_reservoir_grant --fork Amsterdam

Test the receipt is the same however much reservoir was bought.

The reservoir covers none, one or both of the parent's two sets and the rest spill. A delegated child clears both slots and a later set draws on whatever is left. The receipt is the same in every case, so buying reservoir up front costs the sender nothing and saves nothing. What the call and the set cost gas_left is measured in test_reservoir_grant_window_costs.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_cross_frame_refund.py
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
@pytest.mark.parametrize("reservoir_slots", [0, 1, 2])
@pytest.mark.valid_from("EIP8037")
def test_cross_frame_refund_with_reservoir_grant(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    reservoir_slots: int,
) -> None:
    """
    Test the receipt is the same however much reservoir was bought.

    The reservoir covers none, one or both of the parent's two sets
    and the rest spill. A delegated child clears both slots and a
    later set draws on whatever is left. The receipt is the same in
    every case, so buying reservoir up front costs the sender nothing
    and saves nothing. What the call and the set cost `gas_left` is
    measured in `test_reservoir_grant_window_costs`.
    """
    child_code = WARM_CLEAR(SLOT_X, 0) + WARM_CLEAR(SLOT_Y, 0)
    child = pre.deploy_contract(code=child_code)
    child_budget = budget_above_sstore_stipend(fork, child_code)

    code = (
        FRESH_SET(SLOT_X, 1)
        + FRESH_SET(SLOT_Y, 1)
        + Op.POP(
            Op.DELEGATECALL(
                gas=child_budget, address=child, address_warm=False
            )
        )
        + FRESH_SET(SLOT_PROBE, 1)
    )
    contract = pre.deploy_contract(code=code)

    gas_used = (
        fork.transaction_intrinsic_cost_calculator()()
        + code.gas_cost(fork)
        + child_code.gas_cost(fork)
        - child_code.state_refund(fork)
    )
    refund = child_code.refund(fork) - child_code.state_refund(fork)
    gas_used -= min(gas_used // fork.max_refund_quotient(), refund)

    tx = Transaction(
        to=contract,
        state_gas_reservoir=(
            reservoir_slots * Op.SSTORE(new_value=1).state_cost(fork)
        ),
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=gas_used),
    )

    post = {contract: Account(storage={SLOT_X: 0, SLOT_Y: 0, SLOT_PROBE: 1})}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.