Skip to content

test_bal_withdrawal_and_selfdestruct()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_and_selfdestruct@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py::test_bal_withdrawal_and_selfdestruct --fork Amsterdam

Ensure BAL captures withdrawal to self-destructed contract address.

Oracle contract starts with 100 gwei balance. Alice triggers Oracle to self-destruct, sending balance to Bob. Oracle receives withdrawal of 50 gwei after self-destructing. Oracle ends with 50 gwei (funded by withdrawal).

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip4895.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
def test_bal_withdrawal_and_selfdestruct(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Ensure BAL captures withdrawal to self-destructed contract address.

    Oracle contract starts with 100 gwei balance.
    Alice triggers Oracle to self-destruct, sending balance to Bob.
    Oracle receives withdrawal of 50 gwei after self-destructing.
    Oracle ends with 50 gwei (funded by withdrawal).
    """
    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)
    oracle = pre.deploy_contract(
        balance=100 * GWEI,
        code=Op.SELFDESTRUCT(bob),
    )

    tx = Transaction(
        sender=alice,
        to=oracle,
        gas_limit=1_000_000,
        gas_price=0xA,
    )

    block = Block(
        txs=[tx],
        withdrawals=[
            Withdrawal(
                index=0,
                validator_index=0,
                address=oracle,
                amount=50,
            )
        ],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                bob: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1, post_balance=100 * GWEI
                        )
                    ],
                ),
                oracle: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(block_access_index=1, post_balance=0),
                        BalBalanceChange(
                            block_access_index=2, post_balance=50 * GWEI
                        ),
                    ],
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
            bob: Account(balance=100 * GWEI),
            oracle: Account(balance=50 * GWEI),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.