Skip to content

test_contract_creation()

Documentation for tests/benchmark/compute/scenario/test_transaction_types.py::test_contract_creation@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/scenario/test_transaction_types.py::test_contract_creation --gas-benchmark-values 1

Benchmark contract creations via transactions.

Source code in tests/benchmark/compute/scenario/test_transaction_types.py
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
@pytest.mark.parametrize("transfer_amount", [0, 1])
@pytest.mark.parametrize(
    "contract_size", [0, 1, pytest.param(None, id="contract_size_max")]
)
def test_contract_creation(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    fork: Fork,
    transfer_amount: int,
    gas_benchmark_value: int,
    contract_size: int | None,
) -> None:
    """Benchmark contract creations via transactions."""
    if contract_size is None:
        contract_size = fork.max_code_size()

    initcode = Op.RETURN(
        Op.PUSH0,
        contract_size,
        # gas accounting
        old_memory_size=0,
        new_memory_size=contract_size,
        code_deposit_size=contract_size,
    )
    intrinsic_gas_calc = fork.transaction_intrinsic_cost_calculator()

    # EIP-7623: actual gas used = max(standard + execution, floor)
    standard_intrinsic = intrinsic_gas_calc(
        calldata=bytes(initcode),
        contract_creation=True,
        return_cost_deducted_prior_execution=True,
    )
    floor_intrinsic = intrinsic_gas_calc(
        calldata=bytes(initcode),
        contract_creation=True,
    )
    execution_gas = initcode.gas_cost(fork)
    tx_cost = max(standard_intrinsic + execution_gas, floor_intrinsic)

    iteration_count = gas_benchmark_value // tx_cost

    sender = pre.fund_eoa()
    txs = []
    post = {}
    for nonce in range(iteration_count):
        txs.append(
            Transaction(
                to=None,
                data=initcode,
                value=transfer_amount,
                gas_limit=tx_cost,
                sender=sender,
            )
        )
        created_address = compute_create_address(address=sender, nonce=nonce)
        post[created_address] = Account(nonce=1)

    benchmark_test(
        pre=pre,
        post=post,
        blocks=[Block(txs=txs)],
        expected_benchmark_gas_used=iteration_count * tx_cost,
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 3 forks.