Skip to content

test_self_destructing_account()

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

Generate fixtures for these test cases for Prague with:

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

Test withdrawals can be done to self-destructed accounts. Account 0x100 self-destructs and sends all its balance to 0x200. Then, a withdrawal is received at 0x100 with 99 wei.

Source code in tests/shanghai/eip4895_withdrawals/test_withdrawals.py
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
def test_self_destructing_account(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
):
    """
    Test withdrawals can be done to self-destructed accounts.
    Account `0x100` self-destructs and sends all its balance to `0x200`.
    Then, a withdrawal is received at `0x100` with 99 wei.
    """
    self_destruct_code = Op.SELFDESTRUCT(Op.CALLDATALOAD(0))
    sender = pre.fund_eoa()
    recipient = pre.fund_eoa(1)
    self_destruct_contract_address = pre.deploy_contract(
        self_destruct_code,
        balance=100 * ONE_GWEI,
    )

    tx_1 = Transaction(
        # Transaction sent from the `sender`, that calls a
        # self-destructing contract.
        sender=sender,
        gas_limit=100000,
        to=self_destruct_contract_address,
        data=Hash(recipient, left_padding=True),
    )

    withdrawal = Withdrawal(
        index=0,
        validator_index=0,
        address=self_destruct_contract_address,
        amount=(99),
    )

    block = Block(
        txs=[tx_1],
        withdrawals=[withdrawal],
    )

    post = {
        self_destruct_contract_address: Account(
            code=self_destruct_code if fork >= Cancun else b"",
            balance=(99 * ONE_GWEI),
        ),
        recipient: Account(
            code=b"",
            balance=(100 * ONE_GWEI) + 1,
        ),
    }

    blockchain_test(pre=pre, post=post, blocks=[block])

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated)
...fork_Shanghai-blockchain_test
...fork_Cancun-blockchain_test
...fork_Prague-blockchain_test
...fork_Osaka-blockchain_test