Skip to content

test_set_code_to_self_caller()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_self_caller@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_caller --fork Prague

Test the executing a self-call in a set-code transaction.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
@pytest.mark.parametrize(
    "value",
    [0, 1],
)
@pytest.mark.with_all_call_opcodes
def test_set_code_to_self_caller(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    value: int,
    evm_code_type: EVMCodeType,
):
    """Test the executing a self-call in a set-code transaction."""
    storage = Storage()
    auth_signer = pre.fund_eoa(auth_account_start_balance)

    static_call = call_opcode in [Op.STATICCALL, Op.EXTSTATICCALL]

    first_entry_slot = storage.store_next(True)
    re_entry_success_slot = storage.store_next(not static_call)
    re_entry_call_return_code_slot = storage.store_next(
        call_return_code(opcode=call_opcode, success=not static_call)
    )
    set_code = Conditional(
        condition=Op.ISZERO(Op.SLOAD(first_entry_slot)),
        if_true=Op.SSTORE(first_entry_slot, 1)
        + Op.SSTORE(re_entry_call_return_code_slot, call_opcode(address=auth_signer, value=value))
        + Op.STOP,
        if_false=Op.SSTORE(re_entry_success_slot, 1) + Op.STOP,
        evm_code_type=evm_code_type,
    )
    set_code_to_address = pre.deploy_contract(set_code)

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

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address: Account(storage={}),
            auth_signer: Account(
                nonce=1,
                code=Spec.delegation_designation(set_code_to_address),
                storage=storage,
                balance=auth_account_start_balance + value,
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) call_opcode evm_code_type value
...fork_Prague-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test-value_0 STATICCALL LEGACY 0
...fork_Prague-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test-value_1 STATICCALL LEGACY 1
...fork_Prague-call_opcode_STATICCALL-evm_code_type_LEGACY-state_test-value_0 STATICCALL LEGACY 0
...fork_Prague-call_opcode_STATICCALL-evm_code_type_LEGACY-state_test-value_1 STATICCALL LEGACY 1
...fork_Prague-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test-value_0 DELEGATECALL LEGACY 0
...fork_Prague-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test-value_1 DELEGATECALL LEGACY 1
...fork_Prague-call_opcode_DELEGATECALL-evm_code_type_LEGACY-state_test-value_0 DELEGATECALL LEGACY 0
...fork_Prague-call_opcode_DELEGATECALL-evm_code_type_LEGACY-state_test-value_1 DELEGATECALL LEGACY 1
...fork_Prague-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test-value_0 CALL LEGACY 0
...fork_Prague-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test-value_1 CALL LEGACY 1
...fork_Prague-call_opcode_CALL-evm_code_type_LEGACY-state_test-value_0 CALL LEGACY 0
...fork_Prague-call_opcode_CALL-evm_code_type_LEGACY-state_test-value_1 CALL LEGACY 1
...fork_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test-value_0 CALLCODE LEGACY 0
...fork_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test-value_1 CALLCODE LEGACY 1
...fork_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-state_test-value_0 CALLCODE LEGACY 0
...fork_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-state_test-value_1 CALLCODE LEGACY 1
...fork_Osaka-call_opcode_EXTCALL-evm_code_type_EOF_V1-blockchain_test-value_0 EXTCALL EOF_V1 0
...fork_Osaka-call_opcode_EXTCALL-evm_code_type_EOF_V1-blockchain_test-value_1 EXTCALL EOF_V1 1
...fork_Osaka-call_opcode_EXTCALL-evm_code_type_EOF_V1-state_test-value_0 EXTCALL EOF_V1 0
...fork_Osaka-call_opcode_EXTCALL-evm_code_type_EOF_V1-state_test-value_1 EXTCALL EOF_V1 1
...fork_Osaka-call_opcode_EXTSTATICCALL-evm_code_type_EOF_V1-blockchain_test-value_0 EXTSTATICCALL EOF_V1 0
...fork_Osaka-call_opcode_EXTSTATICCALL-evm_code_type_EOF_V1-blockchain_test-value_1 EXTSTATICCALL EOF_V1 1
...fork_Osaka-call_opcode_EXTSTATICCALL-evm_code_type_EOF_V1-state_test-value_0 EXTSTATICCALL EOF_V1 0
...fork_Osaka-call_opcode_EXTSTATICCALL-evm_code_type_EOF_V1-state_test-value_1 EXTSTATICCALL EOF_V1 1
...fork_Osaka-call_opcode_EXTDELEGATECALL-evm_code_type_EOF_V1-blockchain_test-value_0 EXTDELEGATECALL EOF_V1 0
...fork_Osaka-call_opcode_EXTDELEGATECALL-evm_code_type_EOF_V1-blockchain_test-value_1 EXTDELEGATECALL EOF_V1 1
...fork_Osaka-call_opcode_EXTDELEGATECALL-evm_code_type_EOF_V1-state_test-value_0 EXTDELEGATECALL EOF_V1 0
...fork_Osaka-call_opcode_EXTDELEGATECALL-evm_code_type_EOF_V1-state_test-value_1 EXTDELEGATECALL EOF_V1 1
...fork_Osaka-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test-value_0 STATICCALL LEGACY 0
...fork_Osaka-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test-value_1 STATICCALL LEGACY 1
...fork_Osaka-call_opcode_STATICCALL-evm_code_type_LEGACY-state_test-value_0 STATICCALL LEGACY 0
...fork_Osaka-call_opcode_STATICCALL-evm_code_type_LEGACY-state_test-value_1 STATICCALL LEGACY 1
...fork_Osaka-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test-value_0 DELEGATECALL LEGACY 0
...fork_Osaka-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test-value_1 DELEGATECALL LEGACY 1
...fork_Osaka-call_opcode_DELEGATECALL-evm_code_type_LEGACY-state_test-value_0 DELEGATECALL LEGACY 0
...fork_Osaka-call_opcode_DELEGATECALL-evm_code_type_LEGACY-state_test-value_1 DELEGATECALL LEGACY 1
...fork_Osaka-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test-value_0 CALL LEGACY 0
...fork_Osaka-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test-value_1 CALL LEGACY 1
...fork_Osaka-call_opcode_CALL-evm_code_type_LEGACY-state_test-value_0 CALL LEGACY 0
...fork_Osaka-call_opcode_CALL-evm_code_type_LEGACY-state_test-value_1 CALL LEGACY 1
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test-value_0 CALLCODE LEGACY 0
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test-value_1 CALLCODE LEGACY 1
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-state_test-value_0 CALLCODE LEGACY 0
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-state_test-value_1 CALLCODE LEGACY 1