Skip to content

test_selfdestruct_to_self_fork_transition()

Documentation for tests/amsterdam/eip8246_selfdestruct_no_burn/test_fork_transition.py::test_selfdestruct_to_self_fork_transition@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8246_selfdestruct_no_burn/test_fork_transition.py::test_selfdestruct_to_self_fork_transition --fork Amsterdam

A contract created in the transaction self-destructs to itself. Before the fork its balance is burned and the account is deleted; from the fork block on the account stays behind holding that balance.

Source code in tests/amsterdam/eip8246_selfdestruct_no_burn/test_fork_transition.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@pytest.mark.valid_at_transition_to("EIP8246")
@EIPChecklist.Opcode.Test.ForkTransition.At()
def test_selfdestruct_to_self_fork_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """
    A contract created in the transaction self-destructs to itself. Before
    the fork its balance is burned and the account is deleted; from the fork
    block on the account stays behind holding that balance.
    """
    endowment = 5
    sender = pre.fund_eoa()
    initcode = Op.SELFDESTRUCT(Op.ADDRESS)
    factory = pre.deploy_contract(
        code=Om.MSTORE(initcode, 0)
        + Op.SSTORE(
            Op.CALLDATALOAD(0),
            Op.CREATE(value=Op.CALLVALUE, offset=0, size=len(initcode)),
        )
        + Op.STOP
    )
    before = compute_create_address(address=factory, nonce=1)
    at = compute_create_address(address=factory, nonce=2)
    after = compute_create_address(address=factory, nonce=3)

    def create_tx(index: int) -> Transaction:
        return Transaction(
            sender=sender, to=factory, value=endowment, data=Hash(index)
        )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(timestamp=14_999, txs=[create_tx(1)]),
            Block(timestamp=15_000, txs=[create_tx(2)]),
            Block(timestamp=15_001, txs=[create_tx(3)]),
        ],
        post={
            factory: Account(nonce=4, storage={1: before, 2: at, 3: after}),
            before: Account.NONEXISTENT,
            at: Account(balance=endowment, nonce=0, code=b"", storage={}),
            after: Account(balance=endowment, nonce=0, code=b"", storage={}),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.