Skip to content

test_selfdestruct_to_self_cross_tx_no_log()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_selfdestruct_to_self_cross_tx_no_log@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_selfdestruct_to_self_cross_tx_no_log --fork Bogota

Test that selfdestruct-to-self in a cross-tx context emits no log.

A contract created in Tx1 is not in created_accounts during Tx2. Selfdestruct-to-self in Tx2 emits no log per EIP-7708: no Burn log (not same-tx) and no Transfer log (not a different account).

Contract creation tx (to=None) deploying SELFDESTRUCT(ADDRESS),

value=2000. Logs: [transfer_log(sender, created, 2000)]

Tx2: Call created contract directly, value=0. Logs: [] Post: contract keeps balance (not deleted, not in created_accounts in Tx2)

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
def test_selfdestruct_to_self_cross_tx_no_log(
    blockchain_test: BlockchainTestFiller, pre: Alloc
) -> None:
    """
    Test that selfdestruct-to-self in a cross-tx context emits no log.

    A contract created in Tx1 is not in created_accounts during Tx2.
    Selfdestruct-to-self in Tx2 emits no log per EIP-7708: no Burn
    log (not same-tx) and no Transfer log (not a different account).

    Tx1: Contract creation tx (to=None) deploying SELFDESTRUCT(ADDRESS),
         value=2000. Logs: [transfer_log(sender, created, 2000)]
    Tx2: Call created contract directly, value=0. Logs: []
    Post: contract keeps balance (not deleted, not in created_accounts in Tx2)
    """
    contract_balance = 2000
    sender = pre.fund_eoa()

    runtime_code = Op.SELFDESTRUCT(Op.ADDRESS)
    initcode = Initcode(deploy_code=runtime_code)

    # Calculate the address that will be created by the first tx
    created_address = compute_create_address(address=sender, nonce=0)

    blocks = [
        Block(
            txs=[
                # Tx1: Create the contract directly via contract creation tx
                Transaction(
                    to=None,
                    sender=sender,
                    nonce=0,
                    value=contract_balance,
                    data=bytes(initcode),
                    expected_receipt=TransactionReceipt(
                        logs=[
                            transfer_log(
                                sender, created_address, contract_balance
                            ),
                        ]
                    ),
                ),
                # Tx2: Call the created contract directly (cross-tx)
                Transaction(
                    to=created_address,
                    sender=sender,
                    nonce=1,
                    value=0,
                    expected_receipt=TransactionReceipt(logs=[]),
                ),
            ],
        ),
    ]

    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            # Contract keeps balance: not deleted since not in
            # created_accounts during Tx2
            created_address: Account(balance=contract_balance),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.