Skip to content

Test Deposits Withdrawals Consolidations

Documentation for tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py --fork=Prague --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Prague:
fill -v tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

Tests EIP-7685: General purpose execution layer requests

Cross testing for withdrawal and deposit request for EIP-7685: General purpose execution layer requests

test_valid_deposit_withdrawal_consolidation_requests(blockchain_test, pre, blocks)

Test making a deposit to the beacon chain deposit contract and a withdrawal in the same block.

Source code in tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.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
@pytest.mark.parametrize(
    "requests",
    [
        *get_eoa_permutations(),
        *get_contract_permutations(),
        pytest.param(
            [
                single_deposit_from_eoa(0),
                single_withdrawal_from_eoa(0),
                single_deposit_from_contract(1),
            ],
            id="deposit_from_eoa+withdrawal_from_eoa+deposit_from_contract",
        ),
        pytest.param(
            [
                single_withdrawal_from_eoa(0),
                single_deposit_from_eoa(0),
                single_withdrawal_from_contract(1),
            ],
            id="withdrawal_from_eoa+deposit_from_eoa+withdrawal_from_contract",
        ),
        pytest.param(
            [
                single_deposit_from_eoa(0),
                single_consolidation_from_eoa(0),
                single_deposit_from_contract(1),
            ],
            id="deposit_from_eoa+consolidation_from_eoa+deposit_from_contract",
        ),
        pytest.param(
            [
                single_consolidation_from_eoa(0),
                single_deposit_from_eoa(0),
                single_consolidation_from_contract(1),
            ],
            marks=pytest.mark.skip("Only one consolidation request is allowed per block"),
            id="consolidation_from_eoa+deposit_from_eoa+consolidation_from_contract",
        ),
        pytest.param(
            [
                single_consolidation_from_eoa(0),
                single_withdrawal_from_eoa(0),
                single_consolidation_from_contract(1),
            ],
            marks=pytest.mark.skip("Only one consolidation request is allowed per block"),
            id="consolidation_from_eoa+withdrawal_from_eoa+consolidation_from_contract",
        ),
        pytest.param(
            [
                single_withdrawal_from_eoa(0),
                single_consolidation_from_eoa(0),
                single_withdrawal_from_contract(1),
            ],
            id="withdrawal_from_eoa+consolidation_from_eoa+withdrawal_from_contract",
        ),
    ],
)
def test_valid_deposit_withdrawal_consolidation_requests(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    blocks: List[Block],
):
    """
    Test making a deposit to the beacon chain deposit contract and a withdrawal in the same block.
    """
    blockchain_test(
        genesis_environment=Environment(),
        pre=pre,
        post={},
        blocks=blocks,
    )

test_valid_deposit_withdrawal_consolidation_request_from_same_tx(blockchain_test, pre, requests)

Test making a deposit to the beacon chain deposit contract and a withdrawal in the same tx.

Source code in tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
@pytest.mark.parametrize("requests", [*get_permutations()])
def test_valid_deposit_withdrawal_consolidation_request_from_same_tx(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    requests: List[DepositRequest | WithdrawalRequest | ConsolidationRequest],
):
    """
    Test making a deposit to the beacon chain deposit contract and a withdrawal in the same tx.
    """
    withdrawal_request_fee = 1
    consolidation_request_fee = 1

    calldata = b""
    contract_code = Bytecode()
    total_value = 0
    storage = Storage()

    for request in requests:
        calldata_start = len(calldata)
        current_calldata = request.calldata
        calldata += current_calldata

        contract_code += Op.CALLDATACOPY(0, calldata_start, len(current_calldata))

        call_contract_address = 0
        value = 0
        if isinstance(request, DepositRequest):
            call_contract_address = Spec_EIP6110.DEPOSIT_CONTRACT_ADDRESS
            value = request.value
        elif isinstance(request, WithdrawalRequest):
            call_contract_address = Spec_EIP7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS
            value = withdrawal_request_fee
        elif isinstance(request, ConsolidationRequest):
            call_contract_address = Spec_EIP7251.CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS
            value = consolidation_request_fee

        total_value += value

        contract_code += Op.SSTORE(
            storage.store_next(1),
            Op.CALL(
                address=call_contract_address,
                value=value,
                args_offset=0,
                args_size=len(current_calldata),
            ),
        )

    sender = pre.fund_eoa()
    contract_address = pre.deploy_contract(
        code=contract_code,
    )

    tx = Transaction(
        gas_limit=10_000_000,
        to=contract_address,
        value=total_value,
        data=calldata,
        sender=sender,
    )

    blockchain_test(
        genesis_environment=Environment(),
        pre=pre,
        post={
            contract_address: Account(
                storage=storage,
            )
        },
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(
                    requests_root=[
                        request.with_source_address(contract_address)
                        for request in sorted(requests, key=lambda r: r.type_byte())
                    ]
                ),
            )
        ],
    )

test_invalid_deposit_withdrawal_consolidation_requests(blockchain_test, pre, blocks)

Negative testing for deposits and withdrawals in the same block.

Source code in tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
@pytest.mark.parametrize(
    "requests,block_body_override_requests,exception",
    [
        pytest.param(
            [
                single_withdrawal_from_eoa(0),
                single_deposit_from_eoa(0),
            ],
            [
                single_withdrawal(0).with_source_address(TestAddress),
                single_deposit(0),
            ],
            # TODO: on the Engine API, the issue should be detected as an invalid block hash
            BlockException.INVALID_REQUESTS,
            id="single_withdrawal_single_deposit_incorrect_order",
        ),
        pytest.param(
            [
                single_consolidation_from_eoa(0),
                single_deposit_from_eoa(0),
            ],
            [
                single_consolidation(0).with_source_address(TestAddress),
                single_deposit(0),
            ],
            # TODO: on the Engine API, the issue should be detected as an invalid block hash
            BlockException.INVALID_REQUESTS,
            id="single_consolidation_single_deposit_incorrect_order",
        ),
        pytest.param(
            [
                single_consolidation_from_eoa(0),
                single_withdrawal_from_eoa(0),
            ],
            [
                single_consolidation(0).with_source_address(TestAddress),
                single_withdrawal(0).with_source_address(TestAddress2),
            ],
            # TODO: on the Engine API, the issue should be detected as an invalid block hash
            BlockException.INVALID_REQUESTS,
            id="single_consolidation_single_withdrawal_incorrect_order",
        ),
    ],
)
def test_invalid_deposit_withdrawal_consolidation_requests(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    blocks: List[Block],
):
    """
    Negative testing for deposits and withdrawals in the same block.
    """
    blockchain_test(
        genesis_environment=Environment(),
        pre=pre,
        post={},
        blocks=blocks,
    )