Skip to content

test_many_delegations()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_many_delegations@21507778.

Generate fixtures for these test cases for Amsterdam with:

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

Perform as many delegations as possible in a transaction using the entire block gas limit.

Every delegation comes from a different signer.

The account of can be empty or not depending on the signer_balance parameter.

The transaction is expected to succeed and the state after the transaction is expected to have the code of the entry contract set to 1.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
@pytest.mark.parametrize(
    "signer_balance",
    [
        pytest.param(0, id="empty_balance"),
        pytest.param(
            1,
            id="non_empty_balance",
            marks=pytest.mark.execute(
                pytest.mark.skip(reason="excessive pre-fund txs")
            ),
        ),
    ],
)
@pytest.mark.slow()
def test_many_delegations(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
    signer_balance: int,
) -> None:
    """
    Perform as many delegations as possible in a transaction using the entire
    block gas limit.

    Every delegation comes from a different signer.

    The account of can be empty or not depending on the `signer_balance`
    parameter.

    The transaction is expected to succeed and the state after the transaction
    is expected to have the code of the entry contract set to 1.
    """
    env = Environment()
    tx_gas_limit_cap = fork.transaction_gas_limit_cap()
    if tx_gas_limit_cap is not None:
        max_gas = tx_gas_limit_cap
    else:
        max_gas = env.gas_limit
    gas_for_delegations = max_gas - 21_000 - 20_000 - (3 * 2)

    delegation_count = gas_for_delegations // Spec.AUTH_PER_EMPTY_ACCOUNT

    success_slot = 1
    entry_code = Op.SSTORE(success_slot, 1) + Op.STOP
    entry_address = pre.deploy_contract(entry_code)

    signers = [pre.fund_eoa(signer_balance) for _ in range(delegation_count)]

    tx = Transaction(
        gas_limit=max_gas,
        to=entry_address,
        value=0,
        authorization_list=[
            AuthorizationTuple(
                address=Address(i + 1),
                nonce=0,
                signer=signer,
            )
            for (i, signer) in enumerate(signers)
        ],
        sender=pre.fund_eoa(),
    )

    post = {
        entry_address: Account(
            storage={success_slot: 1},
        ),
    } | {
        signer: Account(
            code=Spec.delegation_designation(Address(i + 1)),
        )
        for (i, signer) in enumerate(signers)
    }

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 3 forks.