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

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

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
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
@pytest.mark.with_all_call_opcodes
@pytest.mark.parametrize(
    "value",
    [0, 1],
)
@pytest.mark.filter_combinations(
    lambda call_opcode, value, **_: (
        "value" in call_opcode.kwargs or value == 0
    ),
    reason="opcode does not support value argument",
)
@pytest.mark.eels_base_coverage
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."""
    auth_signer_1 = pre.fund_eoa(auth_account_start_balance)
    storage_1 = Storage()

    static_call = call_opcode == Op.STATICCALL

    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]
                    else storage_1 + storage_2
                ),
                balance=(0 if call_opcode == Op.CALL 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 == Op.CALL else {},
                balance=(value if call_opcode == Op.CALL else 0)
                + auth_account_start_balance,
            ),
        },
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 3 forks.