Skip to content

test_many_delegations()

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

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
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
@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