Skip to content

test_multiple_withdrawals_same_address()

Documentation for tests/shanghai/eip4895_withdrawals/test_withdrawals.py::TestMultipleWithdrawalsSameAddress::test_multiple_withdrawals_same_address@verkle@v0.0.6.

Generate fixtures for these test cases for Shanghai with:

Shanghai only:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::TestMultipleWithdrawalsSameAddress::test_multiple_withdrawals_same_address --fork=Shanghai --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Shanghai:

fill -v tests/shanghai/eip4895_withdrawals/test_withdrawals.py::TestMultipleWithdrawalsSameAddress::test_multiple_withdrawals_same_address --until=Shanghai

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
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
317
318
319
320
@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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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.

Skipped Parameters

For more concise readability, the table below does not list the following parameter values: fork, blockchain_test, state_test, state_test_only, eof_test, eof_state_test.

Test ID test_case
test_case_single_block single_block
test_case_multiple_blocks multiple_blocks