Skip to content

test_many_delegations()

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

Generate fixtures for these test cases for Prague with:

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

Perform as many delegations as possible in a single 120 million gas transaction.

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
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
@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.parametrize(
    "max_gas",
    [
        pytest.param(
            120_000_000,
            id="120m",
            marks=pytest.mark.execute(pytest.mark.skip(reason="excessive gas")),
        ),
        pytest.param(
            20_000_000,
            id="20m",
            marks=pytest.mark.fill(pytest.mark.skip(reason="execute-only test")),
        ),
    ],
)
def test_many_delegations(
    state_test: StateTestFiller,
    pre: Alloc,
    max_gas: int,
    signer_balance: int,
):
    """
    Perform as many delegations as possible in a single 120 million gas transaction.

    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.
    """
    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) max_gas signer_balance
...fork_Prague-state_test-120m-empty_balance 120000000 0
...fork_Prague-state_test-120m-non_empty_balance 120000000 1
...fork_Prague-state_test-20m-empty_balance 20000000 0
...fork_Prague-state_test-20m-non_empty_balance 20000000 1
...fork_Prague-blockchain_test_from_state_test-120m-empty_balance 120000000 0
...fork_Prague-blockchain_test_from_state_test-120m-non_empty_balance 120000000 1
...fork_Prague-blockchain_test_from_state_test-20m-empty_balance 20000000 0
...fork_Prague-blockchain_test_from_state_test-20m-non_empty_balance 20000000 1
...fork_Osaka-state_test-120m-empty_balance 120000000 0
...fork_Osaka-state_test-120m-non_empty_balance 120000000 1
...fork_Osaka-state_test-20m-empty_balance 20000000 0
...fork_Osaka-state_test-20m-non_empty_balance 20000000 1
...fork_Osaka-blockchain_test_from_state_test-120m-empty_balance 120000000 0
...fork_Osaka-blockchain_test_from_state_test-120m-non_empty_balance 120000000 1
...fork_Osaka-blockchain_test_from_state_test-20m-empty_balance 20000000 0
...fork_Osaka-blockchain_test_from_state_test-20m-non_empty_balance 20000000 1