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

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
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
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 1 fork.