Skip to content

test_set_code_call_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_call_set_code@88e9fb8f.

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_call_set_code --fork Osaka

Test the calling a set-code account from another set-code account.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
@pytest.mark.with_all_call_opcodes
@pytest.mark.parametrize(
    "value",
    [0, 1],
)
def test_set_code_call_set_code(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    value: int,
) -> None:
    """Test the calling a set-code account from another set-code account."""
    if "value" not in call_opcode.kwargs and value != 0:
        pytest.skip(f"Call opcode {call_opcode} does not support value")

    auth_signer_1 = pre.fund_eoa(auth_account_start_balance)
    storage_1 = Storage()

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

    set_code_1_call_result_slot = storage_1.store_next(
        call_return_code(opcode=call_opcode, success=not static_call)
    )
    set_code_1_success = storage_1.store_next(True)

    auth_signer_2 = pre.fund_eoa(auth_account_start_balance)
    storage_2 = Storage().set_next_slot(storage_1.peek_slot())
    set_code_2_success = storage_2.store_next(not static_call)

    if "value" in call_opcode.kwargs:
        call_bytecode = call_opcode(address=auth_signer_2, value=value)
    else:
        call_bytecode = call_opcode(address=auth_signer_2)

    set_code_1 = (
        Op.SSTORE(set_code_1_call_result_slot, call_bytecode)
        + Op.SSTORE(set_code_1_success, 1)
        + Op.STOP
    )
    set_code_to_address_1 = pre.deploy_contract(set_code_1)

    set_code_2 = Op.SSTORE(set_code_2_success, 1) + Op.STOP
    set_code_to_address_2 = pre.deploy_contract(set_code_2)

    tx = Transaction(
        gas_limit=10_000_000,
        to=auth_signer_1,
        value=value,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address_1,
                nonce=0,
                signer=auth_signer_1,
            ),
            AuthorizationTuple(
                address=set_code_to_address_2,
                nonce=0,
                signer=auth_signer_2,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address_1: Account(storage=dict.fromkeys(storage_1, 0)),
            set_code_to_address_2: Account(storage=dict.fromkeys(storage_2, 0)),
            auth_signer_1: Account(
                nonce=1,
                code=Spec.delegation_designation(set_code_to_address_1),
                storage=(
                    storage_1
                    if call_opcode in [Op.CALL, Op.STATICCALL, Op.EXTCALL, Op.EXTSTATICCALL]
                    else storage_1 + storage_2
                ),
                balance=(0 if call_opcode in [Op.CALL, Op.EXTCALL] else value)
                + auth_account_start_balance,
            ),
            auth_signer_2: Account(
                nonce=1,
                code=Spec.delegation_designation(set_code_to_address_2),
                storage=storage_2 if call_opcode in [Op.CALL, Op.EXTCALL] else {},
                balance=(value if call_opcode in [Op.CALL, Op.EXTCALL] else 0)
                + auth_account_start_balance,
            ),
        },
    )

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