Skip to content

test_worst_case_auth_block()

Documentation for tests/benchmark/test_worst_blocks.py::test_worst_case_auth_block@e9958ed2.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_blocks.py::test_worst_case_auth_block -m benchmark

Test an auth block.

Source code in tests/benchmark/test_worst_blocks.py
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
@pytest.mark.parametrize("empty_authority", [True, False])
@pytest.mark.parametrize("zero_delegation", [True, False])
def test_worst_case_auth_block(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    intrinsic_cost: int,
    gas_benchmark_value: int,
    fork: Fork,
    empty_authority: bool,
    zero_delegation: bool,
) -> None:
    """Test an auth block."""
    gas_costs = fork.gas_costs()

    iteration_count = (gas_benchmark_value - intrinsic_cost) // gas_costs.G_AUTHORIZATION

    code = Op.STOP * fork.max_code_size()
    auth_target = Address(0) if zero_delegation else pre.deploy_contract(code=code)

    auth_tuples = []
    for _ in range(iteration_count):
        signer = (
            pre.fund_eoa(amount=0, delegation=None)
            if empty_authority
            else pre.fund_eoa(amount=0, delegation=auth_target)
        )
        auth_tuple = AuthorizationTuple(address=auth_target, nonce=signer.nonce, signer=signer)
        auth_tuples.append(auth_tuple)

    tx = Transaction(
        to=pre.empty_account(),
        gas_limit=gas_benchmark_value,
        sender=pre.fund_eoa(),
        authorization_list=auth_tuples,
    )

    gas_used = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=auth_tuples
    )

    refund = 0
    if not empty_authority:
        refund = min(
            gas_used // 5,
            (gas_costs.G_AUTHORIZATION - gas_costs.R_AUTHORIZATION_EXISTING_AUTHORITY)
            * iteration_count,
        )

    blockchain_test(
        pre=pre,
        post={},
        blocks=[Block(txs=[tx])],
        expected_benchmark_gas_used=gas_used - refund,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) zero_delegation empty_authority
...fork_Prague-blockchain_test-zero_delegation_True-empty_authority_True True True
...fork_Prague-blockchain_test-zero_delegation_True-empty_authority_False True False
...fork_Prague-blockchain_test-zero_delegation_False-empty_authority_True False True
...fork_Prague-blockchain_test-zero_delegation_False-empty_authority_False False False
...fork_Osaka-blockchain_test-zero_delegation_True-empty_authority_True True True
...fork_Osaka-blockchain_test-zero_delegation_True-empty_authority_False True False
...fork_Osaka-blockchain_test-zero_delegation_False-empty_authority_True False True
...fork_Osaka-blockchain_test-zero_delegation_False-empty_authority_False False False