Skip to content

test_set_code_to_self_destructing_account_deployed_in_same_tx()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_self_destructing_account_deployed_in_same_tx@49a16fac.

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_destructing_account_deployed_in_same_tx --fork Prague

Test setting the code of an account to an account that contains the SELFDESTRUCT opcode and was deployed in the same transaction, and test calling the set-code address and the deployed in both sequence orders.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
@pytest.mark.parametrize(
    "external_sendall_recipient",
    [False, True],
)
@pytest.mark.parametrize(
    "balance",
    [0, 1],
)
@pytest.mark.parametrize("call_set_code_first", [False, True])
@pytest.mark.parametrize(
    "create_opcode", [Op.CREATE, Op.CREATE2]
)  # EOF code does not support SELFDESTRUCT
def test_set_code_to_self_destructing_account_deployed_in_same_tx(
    state_test: StateTestFiller,
    pre: Alloc,
    create_opcode: Op,
    call_set_code_first: bool,
    external_sendall_recipient: bool,
    balance: int,
):
    """
    Test setting the code of an account to an account that contains the SELFDESTRUCT opcode and
    was deployed in the same transaction, and test calling the set-code address and the deployed
    in both sequence orders.
    """
    auth_signer = pre.fund_eoa(balance)
    if external_sendall_recipient:
        recipient = pre.fund_eoa(0)
    else:
        recipient = auth_signer

    success_slot = 1

    deployed_code = Op.SSTORE(success_slot, 1) + Op.SELFDESTRUCT(recipient)
    initcode = Initcode(deploy_code=deployed_code)

    deployed_contract_address_slot = 1
    signer_call_return_code_slot = 2
    deployed_contract_call_return_code_slot = 3

    salt = 0
    call_opcode = Op.CALL

    contract_creator_code: Bytecode = Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE) + Op.SSTORE(
        deployed_contract_address_slot,
        create_opcode(offset=0, salt=salt, size=Op.CALLDATASIZE),
    )
    if call_set_code_first:
        contract_creator_code += Op.SSTORE(
            signer_call_return_code_slot, call_opcode(address=auth_signer)
        ) + Op.SSTORE(
            deployed_contract_call_return_code_slot,
            call_opcode(address=Op.SLOAD(deployed_contract_address_slot)),
        )
    else:
        contract_creator_code += Op.SSTORE(
            deployed_contract_call_return_code_slot,
            call_opcode(address=Op.SLOAD(deployed_contract_address_slot)),
        ) + Op.SSTORE(signer_call_return_code_slot, call_opcode(address=auth_signer))

    contract_creator_code += Op.STOP

    contract_creator_address = pre.deploy_contract(contract_creator_code)

    deployed_contract_address = compute_create_address(
        address=contract_creator_address,
        nonce=1,
        salt=salt,
        initcode=initcode,
        opcode=create_opcode,
    )

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

    post = {
        deployed_contract_address: Account.NONEXISTENT,
        auth_signer: Account(
            nonce=1,
            code=Spec.delegation_designation(deployed_contract_address),
            storage={success_slot: 1},
            balance=balance if not external_sendall_recipient else 0,
        ),
        contract_creator_address: Account(
            storage={
                deployed_contract_address_slot: deployed_contract_address,
                signer_call_return_code_slot: 1,
                deployed_contract_call_return_code_slot: 1,
            }
        ),
    }

    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) create_opcode call_set_code_first balance external_sendall_recipient
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE False 0 False
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE False 0 True
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE False 1 False
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE False 1 True
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE True 0 False
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE True 0 True
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE True 1 False
...fork_Prague-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE True 1 True
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE2 False 0 False
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE2 False 0 True
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE2 False 1 False
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE2 False 1 True
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE2 True 0 False
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE2 True 0 True
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE2 True 1 False
...fork_Prague-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE2 True 1 True
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE False 0 False
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE False 0 True
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE False 1 False
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE False 1 True
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE True 0 False
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE True 0 True
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE True 1 False
...fork_Prague-state_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE True 1 True
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE2 False 0 False
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE2 False 0 True
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE2 False 1 False
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE2 False 1 True
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE2 True 0 False
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE2 True 0 True
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE2 True 1 False
...fork_Prague-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE2 True 1 True
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE False 0 False
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE False 0 True
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE False 1 False
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE False 1 True
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE True 0 False
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE True 0 True
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE True 1 False
...fork_Osaka-blockchain_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE True 1 True
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE2 False 0 False
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE2 False 0 True
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE2 False 1 False
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE2 False 1 True
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE2 True 0 False
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE2 True 0 True
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE2 True 1 False
...fork_Osaka-blockchain_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE2 True 1 True
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE False 0 False
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE False 0 True
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE False 1 False
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE False 1 True
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE True 0 False
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE True 0 True
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE True 1 False
...fork_Osaka-state_test-create_opcode_CREATE-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE True 1 True
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_False CREATE2 False 0 False
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_0-external_sendall_recipient_True CREATE2 False 0 True
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_False CREATE2 False 1 False
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_False-balance_1-external_sendall_recipient_True CREATE2 False 1 True
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_False CREATE2 True 0 False
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_0-external_sendall_recipient_True CREATE2 True 0 True
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_False CREATE2 True 1 False
...fork_Osaka-state_test-create_opcode_CREATE2-call_set_code_first_True-balance_1-external_sendall_recipient_True CREATE2 True 1 True