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@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

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
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
@pytest.mark.parametrize(
    "value",
    [0, 1],
)
@pytest.mark.with_all_call_opcodes
@pytest.mark.filter_combinations(
    lambda call_opcode, value, **_: (
        "value" in call_opcode.kwargs or value == 0
    ),
    reason="opcode does not support value argument",
)
def test_set_code_to_self_caller(
    state_test: StateTestFiller,
    pre: Alloc,
    call_opcode: Op,
    value: int,
) -> None:
    """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 == Op.STATICCALL

    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,
    )
    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

This test generates 6 parametrized test cases across 3 forks.