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@e9958ed2.

Generate fixtures for these test cases for Osaka with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_to_self_caller --fork Osaka

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
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@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,
) -> None:
    """Test the executing a self-call in a set-code transaction."""
    if "value" not in call_opcode.kwargs and value != 0:
        pytest.skip(f"Call opcode {call_opcode} does not support value")

    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)
    )
    if "value" in call_opcode.kwargs:
        call_bytecode = call_opcode(address=auth_signer, value=value)
    else:
        call_bytecode = call_opcode(address=auth_signer)
    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_bytecode)
        + 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-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_STATICCALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 STATICCALL LEGACY 0
...fork_Prague-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 STATICCALL 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_DELEGATECALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 DELEGATECALL LEGACY 0
...fork_Prague-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 DELEGATECALL 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_CALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 CALL LEGACY 0
...fork_Prague-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 CALL 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_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 CALLCODE LEGACY 0
...fork_Prague-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 CALLCODE 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_STATICCALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 STATICCALL LEGACY 0
...fork_Osaka-call_opcode_STATICCALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 STATICCALL 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_DELEGATECALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 DELEGATECALL LEGACY 0
...fork_Osaka-call_opcode_DELEGATECALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 DELEGATECALL 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_CALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 CALL LEGACY 0
...fork_Osaka-call_opcode_CALL-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 CALL 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
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test_from_state_test-value_0 CALLCODE LEGACY 0
...fork_Osaka-call_opcode_CALLCODE-evm_code_type_LEGACY-blockchain_test_from_state_test-value_1 CALLCODE LEGACY 1