Skip to content

test_multiple_withdrawals_same_address()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::TestMultipleWithdrawalsSameAddress::test_multiple_withdrawals_same_address@21fb11c8.

Generate fixtures for these test cases for Prague with:

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

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

  1. A single block.

  2. Multiple blocks.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
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
@pytest.mark.parametrize("test_case", ["single_block", "multiple_blocks"])
class TestMultipleWithdrawalsSameAddress:
    """
    Test that multiple withdrawals can be sent to the same address in.

    1. A single block.

    2. Multiple blocks.
    """

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

    @pytest.fixture
    def blocks(self, addresses: Address, test_case: str):  # 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,
        test_case: str,
        pre: Alloc,
        addresses: List[Address],
        blocks: List[Block],
    ):
        """
        Test Withdrawals can be done 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, tag=test_case)

test_multiple_withdrawals_same_address(blockchain_test, test_case, pre, addresses, blocks)

Test Withdrawals can be done to the same address multiple times in the same block.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
def test_multiple_withdrawals_same_address(
    self,
    blockchain_test: BlockchainTestFiller,
    test_case: str,
    pre: Alloc,
    addresses: List[Address],
    blocks: List[Block],
):
    """
    Test Withdrawals can be done 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, tag=test_case)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) test_case
...fork_Shanghai-blockchain_test-test_case_single_block single_block
...fork_Shanghai-blockchain_test-test_case_multiple_blocks multiple_blocks
...fork_Cancun-blockchain_test-test_case_single_block single_block
...fork_Cancun-blockchain_test-test_case_multiple_blocks multiple_blocks
...fork_Prague-blockchain_test-test_case_single_block single_block
...fork_Prague-blockchain_test-test_case_multiple_blocks multiple_blocks
...fork_Osaka-blockchain_test-test_case_single_block single_block
...fork_Osaka-blockchain_test-test_case_multiple_blocks multiple_blocks