Skip to content

test_self_destructing_initcode_create_tx()

Documentation for tests/cancun/eip6780_selfdestruct/test_selfdestruct.py::test_self_destructing_initcode_create_tx@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/cancun/eip6780_selfdestruct/test_selfdestruct.py::test_self_destructing_initcode_create_tx --fork Osaka

Use a Create Transaction to execute a self-destructing initcode.

Behavior should be the same before and after EIP-6780.

Test using
  • Different initial balances for the self-destructing contract
  • Different transaction value amounts
Source code in tests/cancun/eip6780_selfdestruct/test_selfdestruct.py
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
@pytest.mark.parametrize("tx_value", [0, 100_000])
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 100_000])
@pytest.mark.valid_from("Shanghai")
def test_self_destructing_initcode_create_tx(
    state_test: StateTestFiller,
    pre: Alloc,
    sender: EOA,
    tx_value: int,
    selfdestruct_code: Bytecode,
    sendall_recipient_addresses: List[Address],
    selfdestruct_contract_initial_balance: int,
):
    """
    Use a Create Transaction to execute a self-destructing initcode.

    Behavior should be the same before and after EIP-6780.

    Test using:
        - Different initial balances for the self-destructing contract
        - Different transaction value amounts
    """
    tx = Transaction(
        sender=sender,
        value=tx_value,
        data=selfdestruct_code,
        to=None,
        gas_limit=500_000,
    )
    selfdestruct_contract_address = tx.created_contract
    pre.fund_address(selfdestruct_contract_address, selfdestruct_contract_initial_balance)

    # Our entry point is an initcode that in turn creates a self-destructing contract
    sendall_amount = selfdestruct_contract_initial_balance + tx_value

    post: Dict[Address, Account] = {
        selfdestruct_contract_address: Account.NONEXISTENT,  # type: ignore
        sendall_recipient_addresses[0]: Account(balance=sendall_amount, storage={0: 1}),
    }

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) selfdestruct_contract_initial_balance tx_value
...fork_Shanghai-state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Shanghai-state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Shanghai-state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Shanghai-state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Shanghai-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Shanghai-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Shanghai-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Shanghai-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Cancun-state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Cancun-state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Cancun-state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Cancun-state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Cancun-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Cancun-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Cancun-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Cancun-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Prague-state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Prague-state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Prague-state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Prague-state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Prague-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Prague-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Prague-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Prague-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Osaka-state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Osaka-state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Osaka-state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Osaka-state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000
...fork_Osaka-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_0 0 0
...fork_Osaka-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_0-tx_value_100000 0 100000
...fork_Osaka-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_0 100000 0
...fork_Osaka-blockchain_test_from_state_test-selfdestruct_contract_initial_balance_100000-tx_value_100000 100000 100000