Skip to content

test_bal_7002_clean_sweep()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7002.py::test_bal_7002_clean_sweep@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7002.py::test_bal_7002_clean_sweep --fork Amsterdam

Ensure BAL correctly tracks "clean sweep" where all withdrawal requests are dequeued in same block (requests ≤ MAX).

Tests combinations of: - pubkey with first 32 bytes zero / non-zero - amount zero / non-zero

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7002.py
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
@pytest.mark.parametrize(
    "pubkey",
    # Use different pubkey based on parameter
    # 0x01 has first 32 bytes all zero
    # Full 48-byte pubkey with non-zero first word
    [0x01, b"key" * 16],
    ids=["pubkey_first_word_zero", "pubkey_first_word_nonzero"],
)
@pytest.mark.parametrize(
    "amount",
    [0, 1000],
    ids=["amount_zero", "amount_nonzero"],
)
def test_bal_7002_clean_sweep(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    pubkey: bytes,
    amount: int,
) -> None:
    """
    Ensure BAL correctly tracks "clean sweep" where all withdrawal requests
    are dequeued in same block (requests ≤ MAX).

    Tests combinations of:
    - pubkey with first 32 bytes zero / non-zero
    - amount zero / non-zero
    """
    alice = pre.fund_eoa()

    withdrawal_request = WithdrawalRequest(
        validator_pubkey=pubkey,
        amount=amount,
        fee=Spec7002.get_fee(0),
    )

    # Transaction to system contract
    tx = Transaction(
        sender=alice,
        to=Address(Spec7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS),
        value=withdrawal_request.fee,
        data=withdrawal_request.calldata,
        gas_limit=200_000,
    )

    # Build queue writes and reads based on pubkey
    queue_writes, queue_reads = _build_queue_storage_slots(
        [alice], [withdrawal_request]
    )

    # Base storage reads that always happen
    base_storage_reads = [
        # Excess is read-only if while dequeuing queue doesn't overflow
        Spec7002.EXCESS_WITHDRAWAL_REQUESTS_STORAGE_SLOT,
        # Head slot is read while dequeuing
        Spec7002.WITHDRAWAL_REQUEST_QUEUE_HEAD_STORAGE_SLOT,
    ]

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                Spec7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS: BalAccountExpectation(  # noqa: E501
                    balance_changes=[
                        # Fee is collected.
                        BalBalanceChange(
                            block_access_index=1,
                            post_balance=withdrawal_request.fee,
                        )
                    ],
                    storage_reads=base_storage_reads + queue_reads,
                    storage_changes=[
                        BalStorageSlot(
                            slot=Spec7002.WITHDRAWAL_REQUEST_COUNT_STORAGE_SLOT,
                            # Count goes by number of request.
                            # Invariant 1: Post-execution ALWAYS resets count.
                            slot_changes=_build_incremental_changes(
                                1,
                                BalStorageChange,
                                "post_value",
                                lambda i: i,
                                reset_to=0,
                            ),
                        ),
                        BalStorageSlot(
                            slot=Spec7002.WITHDRAWAL_REQUEST_QUEUE_TAIL_STORAGE_SLOT,
                            # Tail index goes up by number of requests.
                            # Invariant 2: resets if clean sweep.
                            slot_changes=_build_incremental_changes(
                                1,
                                BalStorageChange,
                                "post_value",
                                lambda i: i,
                                reset_to=0,
                            ),
                        ),
                    ]
                    + queue_writes,
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            Spec7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS: Account(
                balance=withdrawal_request.fee,
                storage=_extract_post_storage_from_queue_writes(queue_writes),
            ),
        },
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.