Skip to content

test_selfdestruct_not_created_in_same_tx_with_revert()

Documentation for tests/cancun/eip6780_selfdestruct/test_selfdestruct_revert.py::test_selfdestruct_not_created_in_same_tx_with_revert@0f7c73a7.

Generate fixtures for these test cases for Prague with:

fill -v tests/cancun/eip6780_selfdestruct/test_selfdestruct_revert.py::test_selfdestruct_not_created_in_same_tx_with_revert --fork Prague

Same test as selfdestruct_created_in_same_tx_with_revert except selfdestructable contract is pre-existing.

Source code in tests/cancun/eip6780_selfdestruct/test_selfdestruct_revert.py
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
@pytest.mark.parametrize(
    "recursive_revert_contract_address_init_balance",
    [2],
    ids=["init_balance_2"],
)
@pytest.mark.parametrize(
    "same_tx",
    [False],
    ids=["not_same_tx"],
)
@pytest.mark.parametrize(
    "selfdestruct_on_outer_call",
    [0, 1, 2],
    ids=[
        "no_outer_selfdestruct",
        "outer_selfdestruct_before_inner_call",
        "outer_selfdestruct_after_inner_call",
    ],
)
@pytest.mark.valid_from("Cancun")
def test_selfdestruct_not_created_in_same_tx_with_revert(
    state_test: StateTestFiller,
    sender: EOA,
    env: Environment,
    entry_code_address: Address,
    pre: Alloc,
    selfdestruct_on_outer_call: int,
    selfdestruct_with_transfer_contract_code: Bytecode,
    selfdestruct_with_transfer_contract_address: Address,
    selfdestruct_recipient_address: Address,
    recursive_revert_contract_address: Address,
    recursive_revert_contract_code: Bytecode,
):
    """
    Same test as selfdestruct_created_in_same_tx_with_revert except selfdestructable contract
    is pre-existing.
    """
    entry_code = Op.CALL(
        Op.GASLIMIT(),
        recursive_revert_contract_address,
        0,  # value
        0,  # arg offset
        0,  # arg length
        0,  # ret offset
        0,  # ret length
    )

    post: Dict[Address, Account] = {
        entry_code_address: Account(code="0x"),
    }

    if selfdestruct_on_outer_call > 0:
        post[selfdestruct_with_transfer_contract_address] = Account(
            balance=1 if selfdestruct_on_outer_call == 1 else 0,
            code=selfdestruct_with_transfer_contract_code,
            storage=Storage(
                {
                    # 2 value transfers: 1 in outer call, 1 in reverted inner call
                    0: 1,  # type: ignore
                    # 1 selfdestruct in reverted inner call
                    1: 1,  # type: ignore
                }
            ),
        )
        post[selfdestruct_recipient_address] = Account(
            balance=1 if selfdestruct_on_outer_call == 1 else 2
        )
    else:
        post[selfdestruct_with_transfer_contract_address] = Account(
            balance=1,
            code=selfdestruct_with_transfer_contract_code,
            storage=Storage(
                {
                    # 2 value transfers: 1 in outer call, 1 in reverted inner call
                    0: 1,  # type: ignore
                    # 2 selfdestructs: 1 in outer call, 1 in reverted inner call # noqa SC100
                    1: 0,  # type: ignore
                }
            ),
        )
        post[selfdestruct_recipient_address] = Account.NONEXISTENT  # type: ignore

    tx = Transaction(
        value=0,
        data=entry_code,
        sender=sender,
        to=None,
        gas_limit=20_000_000,
    )

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

Parametrized Test Cases

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

Test ID (Abbreviated) selfdestruct_on_outer_call same_tx recursive_revert_contract_address_init_balance
...fork_Cancun-state_test-no_outer_selfdestruct-not_same_tx-init_balance_2 0 False 2
...fork_Cancun-state_test-outer_selfdestruct_before_inner_call-not_same_tx-init_balance_2 1 False 2
...fork_Cancun-state_test-outer_selfdestruct_after_inner_call-not_same_tx-init_balance_2 2 False 2
...fork_Cancun-blockchain_test_from_state_test-no_outer_selfdestruct-not_same_tx-init_balance_2 0 False 2
...fork_Cancun-blockchain_test_from_state_test-outer_selfdestruct_before_inner_call-not_same_tx-init_balance_2 1 False 2
...fork_Cancun-blockchain_test_from_state_test-outer_selfdestruct_after_inner_call-not_same_tx-init_balance_2 2 False 2
...fork_Prague-state_test-no_outer_selfdestruct-not_same_tx-init_balance_2 0 False 2
...fork_Prague-state_test-outer_selfdestruct_before_inner_call-not_same_tx-init_balance_2 1 False 2
...fork_Prague-state_test-outer_selfdestruct_after_inner_call-not_same_tx-init_balance_2 2 False 2
...fork_Prague-blockchain_test_from_state_test-no_outer_selfdestruct-not_same_tx-init_balance_2 0 False 2
...fork_Prague-blockchain_test_from_state_test-outer_selfdestruct_before_inner_call-not_same_tx-init_balance_2 1 False 2
...fork_Prague-blockchain_test_from_state_test-outer_selfdestruct_after_inner_call-not_same_tx-init_balance_2 2 False 2
...fork_Osaka-state_test-no_outer_selfdestruct-not_same_tx-init_balance_2 0 False 2
...fork_Osaka-state_test-outer_selfdestruct_before_inner_call-not_same_tx-init_balance_2 1 False 2
...fork_Osaka-state_test-outer_selfdestruct_after_inner_call-not_same_tx-init_balance_2 2 False 2
...fork_Osaka-blockchain_test_from_state_test-no_outer_selfdestruct-not_same_tx-init_balance_2 0 False 2
...fork_Osaka-blockchain_test_from_state_test-outer_selfdestruct_before_inner_call-not_same_tx-init_balance_2 1 False 2
...fork_Osaka-blockchain_test_from_state_test-outer_selfdestruct_after_inner_call-not_same_tx-init_balance_2 2 False 2