Skip to content

test_multiple_withdrawals_same_address()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::TestMultipleWithdrawalsSameAddress::test_multiple_withdrawals_same_address@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::TestMultipleWithdrawalsSameAddress::test_multiple_withdrawals_same_address --fork Amsterdam

Test that multiple withdrawals can be sent to the same address.

  1. single_block: Test multiple withdrawals to the same address in a single block.

  2. multiple_blocks: Test multiple withdrawals to the same address across multiple blocks.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
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
@pytest.mark.parametrize("test_case", ["single_block", "multiple_blocks"])
class TestMultipleWithdrawalsSameAddress:
    """
    Test that multiple withdrawals can be sent to the same address.

    1. `single_block`: Test multiple withdrawals to the same address in a
    single block.

    2. `multiple_blocks`: Test multiple withdrawals to the same address across
    multiple blocks.
    """

    @pytest.fixture
    def addresses(self, fork: Fork) -> List[Address]:  # noqa: D102
        addresses = [Address(p) for p in fork.precompiles()]
        addresses.sort()
        return addresses + [Address(2**160 - 1)]

    @pytest.fixture
    def blocks(self, addresses: Address, test_case: str) -> List[Block]:  # noqa: D102
        if test_case == "single_block":
            # Many repeating withdrawals of the same accounts in the same
            # block.
            return [
                Block(
                    withdrawals=[
                        Withdrawal(
                            index=i,
                            validator_index=i,
                            address=addresses[i % len(addresses)],
                            amount=1,
                        )
                        for i in range(len(addresses) * 16)
                    ],
                ),
            ]
        if test_case == "multiple_blocks":
            # Similar test but now use multiple blocks each with multiple
            # withdrawals to the same withdrawal address.
            return [
                Block(
                    withdrawals=[
                        Withdrawal(
                            index=i * 16 + j,
                            validator_index=i,
                            address=addresses[i],
                            amount=1,
                        )
                        for j in range(16)
                    ],
                )
                for i in range(len(addresses))
            ]
        raise Exception("Invalid test case.")

    def test_multiple_withdrawals_same_address(
        self,
        blockchain_test: BlockchainTestFiller,
        pre: Alloc,
        addresses: List[Address],
        blocks: List[Block],
    ) -> None:
        """
        Test withdrawals to the same address multiple times in the same block.
        """
        # Expected post is the same for both test cases.
        post = {}
        for addr in addresses:
            post[addr] = Account(
                balance=16 * ONE_GWEI,
                storage={},
            )

        blockchain_test(pre=pre, post=post, blocks=blocks)

test_multiple_withdrawals_same_address(blockchain_test, pre, addresses, blocks)

Test withdrawals to the same address multiple times in the same block.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
def test_multiple_withdrawals_same_address(
    self,
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    addresses: List[Address],
    blocks: List[Block],
) -> None:
    """
    Test withdrawals to the same address multiple times in the same block.
    """
    # Expected post is the same for both test cases.
    post = {}
    for addr in addresses:
        post[addr] = Account(
            balance=16 * ONE_GWEI,
            storage={},
        )

    blockchain_test(pre=pre, post=post, blocks=blocks)

Parametrized Test Cases

This test generates 2 parametrized test cases across 5 forks.