Skip to content

test_many_delegations()

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

Generate fixtures for these test cases for Osaka with:

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

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
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
@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.PER_EMPTY_ACCOUNT_COST

    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

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

Test ID (Abbreviated) signer_balance
...fork_Prague-state_test-empty_balance 0
...fork_Prague-state_test-non_empty_balance 1
...fork_Prague-blockchain_test_from_state_test-empty_balance 0
...fork_Prague-blockchain_test_from_state_test-non_empty_balance 1
...fork_Osaka-state_test-empty_balance 0
...fork_Osaka-state_test-non_empty_balance 1
...fork_Osaka-blockchain_test_from_state_test-empty_balance 0
...fork_Osaka-blockchain_test_from_state_test-non_empty_balance 1