Skip to content

test_set_code_to_self_destruct()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_self_destruct@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_self_destruct --fork Prague

Test the executing self-destruct opcode in a set-code transaction.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
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
514
515
516
517
518
@pytest.mark.parametrize(
    "external_sendall_recipient",
    [False, True],
)
@pytest.mark.parametrize(
    "balance",
    [0, 1],
)
def test_set_code_to_self_destruct(
    state_test: StateTestFiller,
    pre: Alloc,
    external_sendall_recipient: bool,
    balance: int,
):
    """Test the executing self-destruct opcode in a set-code transaction."""
    auth_signer = pre.fund_eoa(balance)
    if external_sendall_recipient:
        recipient = pre.fund_eoa(0)
    else:
        recipient = auth_signer

    set_code_to_address = pre.deploy_contract(Op.SSTORE(1, 1) + Op.SELFDESTRUCT(recipient))

    tx = Transaction(
        gas_limit=10_000_000,
        to=auth_signer,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    post = {
        auth_signer: Account(
            nonce=1,
            code=Spec.delegation_designation(set_code_to_address),
            storage={1: 1},
            balance=balance if not external_sendall_recipient else 0,
        ),
    }

    if external_sendall_recipient and balance > 0:
        post[recipient] = Account(balance=balance)

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

Parametrized Test Cases

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

Test ID (Abbreviated) balance external_sendall_recipient
...fork_Prague-state_test-balance_0-external_sendall_recipient_False 0 False
...fork_Prague-state_test-balance_0-external_sendall_recipient_True 0 True
...fork_Prague-state_test-balance_1-external_sendall_recipient_False 1 False
...fork_Prague-state_test-balance_1-external_sendall_recipient_True 1 True
...fork_Prague-blockchain_test_from_state_test-balance_0-external_sendall_recipient_False 0 False
...fork_Prague-blockchain_test_from_state_test-balance_0-external_sendall_recipient_True 0 True
...fork_Prague-blockchain_test_from_state_test-balance_1-external_sendall_recipient_False 1 False
...fork_Prague-blockchain_test_from_state_test-balance_1-external_sendall_recipient_True 1 True
...fork_Osaka-state_test-balance_0-external_sendall_recipient_False 0 False
...fork_Osaka-state_test-balance_0-external_sendall_recipient_True 0 True
...fork_Osaka-state_test-balance_1-external_sendall_recipient_False 1 False
...fork_Osaka-state_test-balance_1-external_sendall_recipient_True 1 True
...fork_Osaka-blockchain_test_from_state_test-balance_0-external_sendall_recipient_False 0 False
...fork_Osaka-blockchain_test_from_state_test-balance_0-external_sendall_recipient_True 0 True
...fork_Osaka-blockchain_test_from_state_test-balance_1-external_sendall_recipient_False 1 False
...fork_Osaka-blockchain_test_from_state_test-balance_1-external_sendall_recipient_True 1 True