Skip to content

test_resurrection_via_withdrawal()

Documentation for tests/mpt/test_account_trie_structure.py::test_resurrection_via_withdrawal@02aafd78.

Generate fixtures for these test cases for Bogota with:

fill -v tests/mpt/test_account_trie_structure.py::test_resurrection_via_withdrawal --fork Bogota

Delete a leaf, then a withdrawal targets its address in the same block.

pre: .. -> branch@4 -> {survivor, doomed} post: the pre shape when the withdrawal credits the address, the collapsed leaf when it credits 0 Gwei Withdrawals apply after the transactions; a zero-amount one leaves no empty account behind.

Source code in tests/mpt/test_account_trie_structure.py
426
427
428
429
430
431
432
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
@pytest.mark.parametrize("amount", [1, 0], ids=["credited", "zero_amount"])
def test_resurrection_via_withdrawal(
    blockchain_test: BlockchainTestFiller, pre: Alloc, amount: int
) -> None:
    """
    Delete a leaf, then a withdrawal targets its address in the same block.

    pre:  .. -> branch@4 -> {survivor, doomed}
    post: the pre shape when the withdrawal credits the address, the
          collapsed leaf when it credits 0 Gwei
    Withdrawals apply after the transactions; a zero-amount one leaves no
    empty account behind.
    """
    survivor, doomed, sender = _fund_collapse_pair(pre)
    resurrected: Account | None
    if amount:
        resurrected = Account(balance=amount * GWEI)
        after = account_shape(_after_block(pre), survivor)
        assert node_at(after, 4) == ("branch", 2)
    else:
        resurrected = Account.NONEXISTENT
        after = account_shape(_after_block(pre, doomed), survivor)
        assert covering(after, 4)[1] == "leaf"

    blockchain_test(
        pre=pre,
        post={survivor: Account(balance=1), doomed: resurrected},
        blocks=[
            Block(
                txs=[_delete_tx(sender, COLLAPSE_SALT)],
                withdrawals=[
                    Withdrawal(
                        index=0,
                        validator_index=0,
                        address=doomed,
                        amount=amount,
                    )
                ],
            )
        ],
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 3 forks.