Skip to content

test_many_delegations()

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

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
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
@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")),
        ),
    ],
)
def test_many_delegations(
    state_test: StateTestFiller,
    fork: Fork,
    pre: Alloc,
    signer_balance: int,
):
    """
    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