Skip to content

test_selfdestruct_then_transfer_same_block()

Documentation for tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py::test_selfdestruct_then_transfer_same_block@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

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

Test transfer to address that selfdestructed earlier in the same block.

Tx1: Contract selfdestructs, sending balance to beneficiary. Tx2: Transfer to the contract triggers SELFDESTRUCT again (code not deleted per EIP-6780), sending the received value to beneficiary.

Expected logs: - Tx1: contract -> beneficiary (500) - Tx2: sender -> contract (100) + contract -> beneficiary (100)

Source code in tests/amsterdam/eip7708_eth_transfer_logs/test_transfer_logs.py
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
def test_selfdestruct_then_transfer_same_block(
    blockchain_test: BlockchainTestFiller, pre: Alloc, fork: Fork
) -> None:
    """
    Test transfer to address that selfdestructed earlier in the same block.

    Tx1: Contract selfdestructs, sending balance to beneficiary.
    Tx2: Transfer to the contract triggers SELFDESTRUCT again (code not deleted
         per EIP-6780), sending the received value to beneficiary.

    Expected logs:
    - Tx1: contract -> beneficiary (500)
    - Tx2: sender -> contract (100) + contract -> beneficiary (100)
    """
    sender = pre.fund_eoa()
    beneficiary = pre.nonexistent_account()

    contract_code = Op.SELFDESTRUCT(beneficiary)
    contract = pre.deploy_contract(contract_code, balance=500)

    blocks = [
        Block(
            txs=[
                Transaction(
                    to=contract,
                    sender=sender,
                    nonce=0,
                    value=0,
                    expected_receipt=TransactionReceipt(
                        logs=[transfer_log(contract, beneficiary, 500)]
                    ),
                ),
                Transaction(
                    to=contract,
                    sender=sender,
                    nonce=1,
                    value=100,
                    expected_receipt=TransactionReceipt(
                        logs=[
                            transfer_log(sender, contract, 100),
                            transfer_log(contract, beneficiary, 100),
                        ]
                    ),
                ),
            ],
        ),
    ]

    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            beneficiary: Account(balance=600),
            contract: Account(balance=0),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.