Skip to content

test_resurrection_via_withdrawal()

Documentation for tests/mpt/test_account_trie_structure.py::test_resurrection_via_withdrawal@ffe48572.

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
@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.