Skip to content

test_fee_getter()

Documentation for tests/amsterdam/eip8282_builder_execution_requests/test_request_predeploys.py::test_fee_getter@52161d99.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8282_builder_execution_requests/test_request_predeploys.py::test_fee_getter --fork Amsterdam

A relay queues requests and then calls the predeploy with empty calldata, which returns the current fee; calling it again with value attached reverts.

Source code in tests/amsterdam/eip8282_builder_execution_requests/test_request_predeploys.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@pytest.mark.parametrize(
    "beyond_target",
    [
        pytest.param(False, id="nothing_queued"),
        pytest.param(True, id="queued_beyond_target"),
    ],
)
@EIPChecklist.SystemContract.Test.InputLengths.Zero()
def test_fee_getter(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    request_class: Type[FeeSystemContractRequest],
    beyond_target: bool,
) -> None:
    """
    A relay queues requests and then calls the predeploy with empty calldata,
    which returns the current fee; calling it again with value attached
    reverts.
    """
    predeploy = request_class.system_contract_address
    per_block = request_class.max_per_block
    if beyond_target:
        excess = request_class.get_n_fee_increments(1)[0]
        queued = request_class.target_per_block + excess
        sweep_changes = [
            BalStorageSlot(
                slot=request_class.excess_slot,
                slot_changes=[
                    BalStorageChange(block_access_index=2, post_value=excess)
                ],
            ),
            queued_count_changes(request_class, queued, 2),
        ]
        if queued > per_block:
            # The sweep takes a block's worth and moves the head past them.
            sweep_changes.append(
                BalStorageSlot(
                    slot=request_class.queue_head_slot,
                    slot_changes=[
                        BalStorageChange(
                            block_access_index=2, post_value=per_block
                        )
                    ],
                )
            )
            predeploy_bal = BalAccountExpectation(
                storage_changes=sweep_changes
            )
        else:
            predeploy_bal = BalAccountExpectation(
                storage_reads=[request_class.queue_head_slot],
                storage_changes=sweep_changes,
            )
    else:
        excess = 0
        queued = 0
        predeploy_bal = BalAccountExpectation(
            storage_reads=[
                request_class.excess_slot,
                request_class.count_slot,
                request_class.queue_head_slot,
                request_class.queue_tail_slot,
            ],
            storage_changes=[],
        )
    requests = [
        request_class.from_index(i).copy(fee=fee)
        for i, fee in enumerate(request_class.get_enqueue_fees(queued))
    ]
    queued_value = sum(request.value for request in requests)
    # Per-call pricing already counts the requests queued this block;
    # per-block pricing returns the minimum until the system call runs.
    if request_class.excess_fee_processing == "call":
        quoted_fee = request_class.get_fee(excess)
    elif request_class.excess_fee_processing == "block":
        quoted_fee = request_class.get_fee(0)
    else:
        raise ValueError(
            f"unhandled fee processing {request_class.excess_fee_processing}"
        )

    storage = Storage()
    fee_getter = (
        Op.SSTORE(
            storage.store_next(1, "getter_success"),
            Op.CALL(Op.GAS, predeploy, 0, 0, 0, 0, 32),
        )
        + Op.SSTORE(
            storage.store_next(32, "getter_return_size"), Op.RETURNDATASIZE
        )
        + Op.SSTORE(storage.store_next(quoted_fee, "fee"), Op.MLOAD(0))
        + Op.SSTORE(
            storage.store_next(0, "getter_with_value_success"),
            Op.CALL(Op.GAS, predeploy, 1, 0, 0, 0, 0),
        )
    )
    relay = pre.deploy_contract(
        relay_contract_code(
            requests, call_type=Op.CALL, extra_code=fee_getter
        ),
        balance=queued_value + 1,
    )
    tx = Transaction(
        sender=pre.fund_eoa(),
        to=relay,
        data=b"".join(request.calldata for request in requests),
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(
                    requests_hash=Requests(
                        *(
                            r.with_source_address(relay)
                            for r in requests[:per_block]
                        )
                    )
                ),
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        relay: BalAccountExpectation(
                            storage_changes=[
                                BalStorageSlot(
                                    slot=slot,
                                    slot_changes=[
                                        BalStorageChange(
                                            block_access_index=1,
                                            post_value=value,
                                        )
                                    ],
                                )
                                for slot, value in storage.root.items()
                                if value != 0
                            ],
                        ),
                        predeploy: predeploy_bal,
                    }
                ),
            )
        ],
        post={
            relay: Account(storage=storage, balance=1),
            predeploy: Account(balance=queued_value),
        },
    )

Parametrized Test Cases

This test generates 8 parametrized test cases across 1 fork.