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

Generate fixtures for these test cases for Amsterdam with:

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

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
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
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),
                    gas_limit=300_000,
                    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,
                    gas_limit=100_000,
                    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 1 fork.