Skip to content

test_eoa_tx_after_set_code()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_eoa_tx_after_set_code@14a7429a.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_eoa_tx_after_set_code --fork Prague

Test sending a transaction from an EOA after code has been set to the account.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
@pytest.mark.with_all_evm_code_types
@pytest.mark.with_all_tx_types(
    selector=lambda tx_type: tx_type != 4,
    marks=lambda tx_type: pytest.mark.execute(pytest.mark.skip("incompatible tx"))
    if tx_type in [0, 3]
    else None,
)
@pytest.mark.parametrize(
    "same_block",
    [
        pytest.param(
            True,
            marks=[pytest.mark.execute(pytest.mark.skip("duplicate scenario for execute"))],
            id="same_block",
        ),
        pytest.param(False, id="different_block"),
    ],
)
def test_eoa_tx_after_set_code(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    tx_type: int,
    fork: Fork,
    evm_code_type: EVMCodeType,
    same_block: bool,
):
    """Test sending a transaction from an EOA after code has been set to the account."""
    auth_signer = pre.fund_eoa()

    set_code = Op.SSTORE(1, Op.ADD(Op.SLOAD(1), 1)) + Op.STOP
    set_code_to_address = pre.deploy_contract(set_code)

    first_eoa_tx = Transaction(
        sender=pre.fund_eoa(),
        gas_limit=500_000,
        to=auth_signer,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
    )
    auth_signer.nonce += 1  # type: ignore

    follow_up_eoa_txs: List[Transaction] = []
    match tx_type:
        case 0:
            follow_up_eoa_txs.extend(
                [
                    Transaction(
                        type=tx_type,
                        sender=auth_signer,
                        gas_limit=500_000,
                        to=auth_signer,
                        value=0,
                        protected=True,
                    ),
                    Transaction(
                        type=tx_type,
                        sender=auth_signer,
                        gas_limit=500_000,
                        to=auth_signer,
                        value=0,
                        protected=False,
                    ),
                ]
            )
        case 1:
            follow_up_eoa_txs.append(
                Transaction(
                    type=tx_type,
                    sender=auth_signer,
                    gas_limit=500_000,
                    to=auth_signer,
                    value=0,
                    access_list=[
                        AccessList(
                            address=auth_signer,
                            storage_keys=[1],
                        )
                    ],
                )
            )
        case 2:
            follow_up_eoa_txs.append(
                Transaction(
                    type=tx_type,
                    sender=auth_signer,
                    gas_limit=500_000,
                    to=auth_signer,
                    value=0,
                    max_fee_per_gas=1_000,
                    max_priority_fee_per_gas=1_000,
                )
            )
        case 3:
            follow_up_eoa_txs.append(
                Transaction(
                    type=tx_type,
                    sender=auth_signer,
                    gas_limit=500_000,
                    to=auth_signer,
                    value=0,
                    max_fee_per_gas=1_000,
                    max_priority_fee_per_gas=1_000,
                    max_fee_per_blob_gas=fork.min_base_fee_per_blob_gas() * 10,
                    blob_versioned_hashes=add_kzg_version(
                        [Hash(1)],
                        Spec4844.BLOB_COMMITMENT_VERSION_KZG,
                    ),
                )
            )
        case _:
            raise ValueError(f"Unsupported tx type: {tx_type}, test needs update")

    if same_block:
        blocks = [Block(txs=[first_eoa_tx] + follow_up_eoa_txs)]
    else:
        blocks = [
            Block(txs=[first_eoa_tx]),
            Block(txs=follow_up_eoa_txs),
        ]
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            auth_signer: Account(
                nonce=3 if tx_type == 0 else 2,
                code=Spec.delegation_designation(set_code_to_address),
                storage={1: 3 if tx_type == 0 else 2},
            ),
        },
    )

Parametrized Test Cases

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

Test ID (Abbreviated) tx_type evm_code_type same_block
...fork_Prague-tx_type_3-evm_code_type_LEGACY-blockchain_test-same_block 3 LEGACY True
...fork_Prague-tx_type_3-evm_code_type_LEGACY-blockchain_test-different_block 3 LEGACY False
...fork_Prague-tx_type_2-evm_code_type_LEGACY-blockchain_test-same_block 2 LEGACY True
...fork_Prague-tx_type_2-evm_code_type_LEGACY-blockchain_test-different_block 2 LEGACY False
...fork_Prague-tx_type_1-evm_code_type_LEGACY-blockchain_test-same_block 1 LEGACY True
...fork_Prague-tx_type_1-evm_code_type_LEGACY-blockchain_test-different_block 1 LEGACY False
...fork_Prague-tx_type_0-evm_code_type_LEGACY-blockchain_test-same_block 0 LEGACY True
...fork_Prague-tx_type_0-evm_code_type_LEGACY-blockchain_test-different_block 0 LEGACY False
...fork_Osaka-tx_type_3-evm_code_type_LEGACY-blockchain_test-same_block 3 LEGACY True
...fork_Osaka-tx_type_3-evm_code_type_LEGACY-blockchain_test-different_block 3 LEGACY False
...fork_Osaka-tx_type_3-evm_code_type_EOF_V1-blockchain_test-same_block 3 EOF_V1 True
...fork_Osaka-tx_type_3-evm_code_type_EOF_V1-blockchain_test-different_block 3 EOF_V1 False
...fork_Osaka-tx_type_2-evm_code_type_LEGACY-blockchain_test-same_block 2 LEGACY True
...fork_Osaka-tx_type_2-evm_code_type_LEGACY-blockchain_test-different_block 2 LEGACY False
...fork_Osaka-tx_type_2-evm_code_type_EOF_V1-blockchain_test-same_block 2 EOF_V1 True
...fork_Osaka-tx_type_2-evm_code_type_EOF_V1-blockchain_test-different_block 2 EOF_V1 False
...fork_Osaka-tx_type_1-evm_code_type_LEGACY-blockchain_test-same_block 1 LEGACY True
...fork_Osaka-tx_type_1-evm_code_type_LEGACY-blockchain_test-different_block 1 LEGACY False
...fork_Osaka-tx_type_1-evm_code_type_EOF_V1-blockchain_test-same_block 1 EOF_V1 True
...fork_Osaka-tx_type_1-evm_code_type_EOF_V1-blockchain_test-different_block 1 EOF_V1 False
...fork_Osaka-tx_type_0-evm_code_type_LEGACY-blockchain_test-same_block 0 LEGACY True
...fork_Osaka-tx_type_0-evm_code_type_LEGACY-blockchain_test-different_block 0 LEGACY False
...fork_Osaka-tx_type_0-evm_code_type_EOF_V1-blockchain_test-same_block 0 EOF_V1 True
...fork_Osaka-tx_type_0-evm_code_type_EOF_V1-blockchain_test-different_block 0 EOF_V1 False